tpot icon indicating copy to clipboard operation
tpot copied to clipboard

Idea to make predict_proba consistent with other sklearn models/pipelines.

Open perib opened this issue 2 years ago • 0 comments

Currently there is not an intuitive way to check if the tpot estimator has the predict_proba function and is inconsistent with other sklearn pipelines/methods.

Context of the issue

The only method of figuring out if the pipeline has predict_proba is to look into the internal variable with hasattr(tpot_instance.fitted_pipeline_, "predict_proba) other sklearn methods all allow you to call hasattr directly on the estimator. such as hasattr(svc_instance, "predict_proba")

Process to reproduce the issue

[ordered list the process to finding and recreating the issue, example below]

  1. User creates TPOT instance
  2. User calls TPOT fit() function with training data
  3. if the pipeline does not have the predict_proba method, hasattr(tpot_instance, "predict_proba") still returns true.

Expected result

hasattr(tpot_instance "predict_proba") should return false when the pipeline does not have predict_proba, to be consistent with other sklearn methods removing the need to treat tpot as a special case.

Current result

if the pipeline does not have the predict_proba method, hasattr(tpot_instance "predict_proba") still returns true.

Possible fix

We can use this : sklearn sklearn.utils.metaestimators.available_if

I think this would be helpful for TPOTs predict_proba method. we could simplify it to

@available_if(hasattr(self.fitted_pipeline_,"predict_proba")
def predict_proba(self, features):
    features = self._check_dataset(features, target=None, sample_weight=None)
    return self.fitted_pipeline_.predict_proba(features)

Example with sklearn implementation of SVC

perib avatar Apr 28 '22 19:04 perib