Azure / Azure/MachineLearningNotebooks

predict_proba() method not working for LinearSVMWrapper

Open
#1,768 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
4.4k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

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:

```python
---------------------------------------------------------------------------
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
----> 1 fitted_model.predict(X_test)

/opt/miniconda/lib/python3.7/site-packages/sklearn/utils/metaestimators.py in (*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 (*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 (.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 (*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.*

* ID: 55f99a41-4a28-733f-7e32-4cdda9117f93
* Version Independent ID: e02b08ba-1dc7-a09a-a824-512be0bc7200
* Content: [azureml.automl.runtime.shared.model_wrappers.LinearSVMWrapper class - Azure Machine Learning Python](https://docs.microsoft.com/en-us/python/api/azureml-automl-runtime/azureml.automl.runtime.shared.model_wrappers.linearsvmwrapper?view=azure-ml-py#constructor)
* Content Source: [AzureML-Docset/stable/docs-ref-autogen/azureml-automl-runtime/azureml.automl.runtime.shared.model_wrappers.LinearSVMWrapper.yml](https://github.com/MicrosoftDocs/MachineLearning-Python-pr/blob/live/AzureML-Docset/stable/docs-ref-autogen/azureml-automl-runtime/azureml.automl.runtime.shared.model_wrappers.LinearSVMWrapper.yml)
* Service: **machine-learning**
* Sub-service: **core**
* GitHub Login: @DebFro
* Microsoft Alias: **debfro**

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.