MachineLearningNotebooks icon indicating copy to clipboard operation
MachineLearningNotebooks copied to clipboard

predict_proba() method not working for LinearSVMWrapper

Open ruankie opened this issue 3 years ago • 0 comments

It seems like there is a problem when calling the predict_proba() method on LinearSVMWrapper when using azureml-core==1.41.0.

This model was contained in a scikit-learn Pipeline within soft voting classifier model. This is the full error message:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/opt/miniconda/lib/python3.7/site-packages/azureml/automl/runtime/shared/model_wrappers.py in predict_proba(self, X)
   2191         try:
-> 2192             return self.model.predict_proba(X)
   2193         except Exception as e:

/opt/miniconda/lib/python3.7/site-packages/sklearn/calibration.py in predict_proba(self, X)
    418         for calibrated_classifier in self.calibrated_classifiers_:
--> 419             proba = calibrated_classifier.predict_proba(X)
    420             mean_proba += proba

/opt/miniconda/lib/python3.7/site-packages/sklearn/calibration.py in predict_proba(self, X)
    707         """
--> 708         n_classes = len(self.classes)
    709         pred_method, method_name = _get_prediction_method(self.base_estimator)

TypeError: object of type 'NoneType' has no len()

During handling of the above exception, another exception occurred:

PredictionException                       Traceback (most recent call last)
/tmp/ipykernel_201/372255677.py in <module>
----> 1 fitted_model.predict(X_test)

/opt/miniconda/lib/python3.7/site-packages/sklearn/utils/metaestimators.py in <lambda>(*args, **kwargs)
    111 
    112             # lambda, but not partial, allows help() to work with update_wrapper
--> 113             out = lambda *args, **kwargs: self.fn(obj, *args, **kwargs)  # noqa
    114         else:
    115 

/opt/miniconda/lib/python3.7/site-packages/sklearn/pipeline.py in predict(self, X, **predict_params)
    468         for _, name, transform in self._iter(with_final=False):
    469             Xt = transform.transform(Xt)
--> 470         return self.steps[-1][1].predict(Xt, **predict_params)
    471 
    472     @available_if(_final_estimator_has("fit_predict"))

/opt/miniconda/lib/python3.7/site-packages/sklearn/ensemble/_voting.py in predict(self, X)
    339         check_is_fitted(self)
    340         if self.voting == "soft":
--> 341             maj = np.argmax(self.predict_proba(X), axis=1)
    342 
    343         else:  # 'hard' voting

/opt/miniconda/lib/python3.7/site-packages/sklearn/utils/metaestimators.py in <lambda>(*args, **kwargs)
    111 
    112             # lambda, but not partial, allows help() to work with update_wrapper
--> 113             out = lambda *args, **kwargs: self.fn(obj, *args, **kwargs)  # noqa
    114         else:
    115 

/opt/miniconda/lib/python3.7/site-packages/sklearn/ensemble/_voting.py in predict_proba(self, X)
    380         check_is_fitted(self)
    381         avg = np.average(
--> 382             self._collect_probas(X), axis=0, weights=self._weights_not_none
    383         )
    384         return avg

/opt/miniconda/lib/python3.7/site-packages/azureml/automl/runtime/shared/model_wrappers.py in _collect_probas(self, X)
   5244         probas = [
   5245             _scoring_utilities.pad_predictions(clf.predict_proba(X), clf.classes_, self.classes_)
-> 5246             for clf in self.estimators_
   5247         ]
   5248         return np.asarray(probas)

/opt/miniconda/lib/python3.7/site-packages/azureml/automl/runtime/shared/model_wrappers.py in <listcomp>(.0)
   5244         probas = [
   5245             _scoring_utilities.pad_predictions(clf.predict_proba(X), clf.classes_, self.classes_)
-> 5246             for clf in self.estimators_
   5247         ]
   5248         return np.asarray(probas)

/opt/miniconda/lib/python3.7/site-packages/sklearn/utils/metaestimators.py in <lambda>(*args, **kwargs)
    111 
    112             # lambda, but not partial, allows help() to work with update_wrapper
--> 113             out = lambda *args, **kwargs: self.fn(obj, *args, **kwargs)  # noqa
    114         else:
    115 

/opt/miniconda/lib/python3.7/site-packages/sklearn/pipeline.py in predict_proba(self, X, **predict_proba_params)
    534         for _, name, transform in self._iter(with_final=False):
    535             Xt = transform.transform(Xt)
--> 536         return self.steps[-1][1].predict_proba(Xt, **predict_proba_params)
    537 
    538     @available_if(_final_estimator_has("decision_function"))

/opt/miniconda/lib/python3.7/site-packages/azureml/automl/runtime/shared/model_wrappers.py in predict_proba(self, X)
   2005         except Exception as e:
   2006             raise PredictionException.from_exception(e, has_pii=True, target='LinearSVMWrapper'). \
-> 2007                 with_generic_msg(_generic_prediction_error_message.format(self.__class__.__name__))
   2008 
   2009     def predict(self, X):

/opt/miniconda/lib/python3.7/site-packages/azureml/automl/runtime/shared/model_wrappers.py in predict_proba(self, X)
   2002         """
   2003         try:
-> 2004             return self.model.predict_proba(X)
   2005         except Exception as e:
   2006             raise PredictionException.from_exception(e, has_pii=True, target='LinearSVMWrapper'). \

/opt/miniconda/lib/python3.7/site-packages/azureml/automl/runtime/shared/model_wrappers.py in predict_proba(self, X)
   2193         except Exception as e:
   2194             raise PredictionException.from_exception(e, has_pii=True, target='CalibratedModel'). \
-> 2195                 with_generic_msg(_generic_prediction_error_message.format(self.__class__.__name__))
   2196 
   2197 

/opt/miniconda/lib/python3.7/site-packages/azureml/automl/runtime/shared/model_wrappers.py in predict_proba(self, X)
   2190         """
   2191         try:
-> 2192             return self.model.predict_proba(X)
   2193         except Exception as e:
   2194             raise PredictionException.from_exception(e, has_pii=True, target='CalibratedModel'). \

/opt/miniconda/lib/python3.7/site-packages/sklearn/calibration.py in predict_proba(self, X)
    417         mean_proba = np.zeros((_num_samples(X), len(self.classes_)))
    418         for calibrated_classifier in self.calibrated_classifiers_:
--> 419             proba = calibrated_classifier.predict_proba(X)
    420             mean_proba += proba
    421 

/opt/miniconda/lib/python3.7/site-packages/sklearn/calibration.py in predict_proba(self, X)
    706             The predicted probabilities. Can be exact zeros.
    707         """
--> 708         n_classes = len(self.classes)
    709         pred_method, method_name = _get_prediction_method(self.base_estimator)
    710         predictions = _compute_predictions(pred_method, method_name, X, n_classes)

PredictionException: PredictionException:
	Message: object of type 'NoneType' has no len()
	InnerException: TypeError: object of type 'NoneType' has no len()
	ErrorResponse 
{
    "error": {
        "code": "SystemError",
        "message": "Encountered an internal AutoML error. Error Message/Code: PredictionException. Additional Info: PredictionException:\n\tMessage: object of type 'NoneType' has no len()\n\tInnerException: None\n\tErrorResponse \n{\n    \"error\": {\n        \"message\": \"object of type 'NoneType' has no len()\",\n        \"target\": \"CalibratedModel\",\n        \"reference_code\": \"CalibratedModel\"\n    }\n}",
        "details_uri": "https://aka.ms/automltroubleshoot",
        "target": "CalibratedModel",
        "inner_error": {
            "code": "ClientError",
            "inner_error": {
                "code": "AutoMLInternal"
            }
        },
        "reference_code": "CalibratedModel"
    }
}

Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

ruankie avatar Jun 10 '22 15:06 ruankie