From 79ab1697a7a41ba88a8c0b39ba70fd33a11bbfd3 Mon Sep 17 00:00:00 2001 From: Matteo Interlandi Date: Sun, 30 Aug 2020 11:39:00 -0700 Subject: [PATCH] add support for afe with boolean indices (#272) --- .../hummingbird/ml/operator_converters/index.html | 4 ++-- .../ml/operator_converters/sklearn/index.html | 5 +++++ .../sklearn/missing_indicator.html | 12 ++---------- .../ml/operator_converters/sklearn/pipeline.html | 12 ++++++++---- doc/html/hummingbird/ml/supported.html | 12 +++--------- .../ml/operator_converters/sklearn/pipeline.py | 2 ++ 6 files changed, 22 insertions(+), 25 deletions(-) diff --git a/doc/html/hummingbird/ml/operator_converters/index.html b/doc/html/hummingbird/ml/operator_converters/index.html index 81845873..2896a578 100644 --- a/doc/html/hummingbird/ml/operator_converters/index.html +++ b/doc/html/hummingbird/ml/operator_converters/index.html @@ -1,4 +1,4 @@ -vi + @@ -26,7 +26,7 @@ vi
Expand source code -Browse git +Browse git
# -------------------------------------------------------------------------
 # Copyright (c) Microsoft Corporation. All rights reserved.
diff --git a/doc/html/hummingbird/ml/operator_converters/sklearn/index.html b/doc/html/hummingbird/ml/operator_converters/sklearn/index.html
index 8161d6d5..010b688d 100644
--- a/doc/html/hummingbird/ml/operator_converters/sklearn/index.html
+++ b/doc/html/hummingbird/ml/operator_converters/sklearn/index.html
@@ -66,6 +66,10 @@ All scikit-learn operators converters are stored under this package.
 

Converters for scikit-learn linear models: LinearRegression, LogisticRegression, LinearSVC, SGDClassifier, LogisticRegressionCV.

+
hummingbird.ml.operator_converters.sklearn.missing_indicator
+
+

Converter for scikit-learn MissingIndicator.

+
hummingbird.ml.operator_converters.sklearn.mlp

Converters for scikit-learn MLP models: MLPClassifier

@@ -127,6 +131,7 @@ All scikit-learn operators converters are stored under this package.
  • hummingbird.ml.operator_converters.sklearn.gbdt
  • hummingbird.ml.operator_converters.sklearn.iforest
  • hummingbird.ml.operator_converters.sklearn.linear
  • +
  • hummingbird.ml.operator_converters.sklearn.missing_indicator
  • hummingbird.ml.operator_converters.sklearn.mlp
  • hummingbird.ml.operator_converters.sklearn.nb
  • hummingbird.ml.operator_converters.sklearn.normalizer
  • diff --git a/doc/html/hummingbird/ml/operator_converters/sklearn/missing_indicator.html b/doc/html/hummingbird/ml/operator_converters/sklearn/missing_indicator.html index 160ff926..38c07783 100644 --- a/doc/html/hummingbird/ml/operator_converters/sklearn/missing_indicator.html +++ b/doc/html/hummingbird/ml/operator_converters/sklearn/missing_indicator.html @@ -183,18 +183,10 @@ register_converter("SklearnMissingIndicator", convert_sklearn_missing_in

    Methods

    -def forward(self, x) +def forward(self, x) -> Callable[..., Any]
    -

    Defines the computation performed at every call.

    -

    Should be overridden by all subclasses.

    -
    -

    Note

    -

    Although the recipe for forward pass needs to be defined within -this function, one should call the :class:Module instance afterwards -instead of this since the former takes care of running the -registered hooks while the latter silently ignores them.

    -
    +
    Expand source code diff --git a/doc/html/hummingbird/ml/operator_converters/sklearn/pipeline.html b/doc/html/hummingbird/ml/operator_converters/sklearn/pipeline.html index c200b1e4..e8d4b84d 100644 --- a/doc/html/hummingbird/ml/operator_converters/sklearn/pipeline.html +++ b/doc/html/hummingbird/ml/operator_converters/sklearn/pipeline.html @@ -26,7 +26,7 @@
    Expand source code -Browse git +Browse git
    # -------------------------------------------------------------------------
     # Copyright (c) Microsoft Corporation. All rights reserved.
    @@ -88,6 +88,8 @@ def convert_sklearn_array_feature_extractor(operator, device, extra_config):
         assert operator is not None
     
         indices = operator.column_indices
    +    if any([type(i) is bool for i in indices]):
    +        indices = [i for i in range(len(indices)) if indices[i]]
         return ArrayFeatureExtractor(np.ascontiguousarray(indices), device)
     
     
    @@ -161,7 +163,7 @@ register_converter("SklearnMultiply", convert_sklearn_multiply)
     
     Expand source code
    -Browse git
    +Browse git
     
     
    def convert_sklearn_array_feature_extractor(operator, device, extra_config):
         """
    @@ -178,6 +180,8 @@ register_converter("SklearnMultiply", convert_sklearn_multiply)
    @@ -203,7 +207,7 @@ register_converter("SklearnMultiply", convert_sklearn_multiply)
    Expand source code -Browse git +Browse git
    def convert_sklearn_concat(operator, device=None, extra_config={}):
         """
    @@ -242,7 +246,7 @@ register_converter("SklearnMultiply", convert_sklearn_multiply)
     
     Expand source code
    -Browse git
    +Browse git
     
     
    def convert_sklearn_multiply(operator, device=None, extra_config={}):
         """
    diff --git a/doc/html/hummingbird/ml/supported.html b/doc/html/hummingbird/ml/supported.html
    index 67654b5f..663bd544 100644
    --- a/doc/html/hummingbird/ml/supported.html
    +++ b/doc/html/hummingbird/ml/supported.html
    @@ -70,7 +70,7 @@ XGBRegressor

    Expand source code -Browse git +Browse git
    # -------------------------------------------------------------------------
     # Copyright (c) Microsoft Corporation. All rights reserved.
    @@ -170,7 +170,6 @@ def _build_sklearn_operator_list():
             # SVM-based models
             from sklearn.svm import LinearSVC, SVC, NuSVC
     
    -
             # Imputers
             from sklearn.impute import MissingIndicator
     
    @@ -180,7 +179,6 @@ def _build_sklearn_operator_list():
             # Naive Bayes Models
             from sklearn.naive_bayes import BernoulliNB, GaussianNB, MultinomialNB
     
    -
             # Preprocessing
             from sklearn.preprocessing import (
                 Binarizer,
    @@ -458,9 +456,7 @@ CONTAINER = "container"
     
    Expand source code - -Browse git - +Browse git
    def get_onnxml_api_operator_name(model_type):
         """
    @@ -497,9 +493,7 @@ or an object with scikit-learn API (e.g., LightGBM)
    Expand source code - -Browse git - +Browse git
    def get_sklearn_api_operator_name(model_type):
         """
    diff --git a/hummingbird/ml/operator_converters/sklearn/pipeline.py b/hummingbird/ml/operator_converters/sklearn/pipeline.py
    index 00c33642..06950f49 100644
    --- a/hummingbird/ml/operator_converters/sklearn/pipeline.py
    +++ b/hummingbird/ml/operator_converters/sklearn/pipeline.py
    @@ -58,6 +58,8 @@ def convert_sklearn_array_feature_extractor(operator, device, extra_config):
         assert operator is not None
     
         indices = operator.column_indices
    +    if any([type(i) is bool for i in indices]):
    +        indices = [i for i in range(len(indices)) if indices[i]]
         return ArrayFeatureExtractor(np.ascontiguousarray(indices), device)