Reputation: 1889
I use CalibratedClassifierCV with RandomForest and use GridSearch to determine the best parameters. However, when I use GridSearchCV to read back the best parameters it says GridSearchCV object has no attribute 'best_params_'
from sklearn.calibration import CalibratedClassifierCV
from classifiers import SVMClassification
from sklearn.model_selection import GridSearchCV
from imblearn.pipeline import Pipeline as imbpipeline
pipeline=imbpipeline([ ('oversample', Sampling(random_state=444)),('rf', rf())])
paramgrid=[ {'rf__max_depth': [8,10], 'rf__n_estimators':[3,5]}]
grid_search_rf = GridSearchCV(pipeline, param_grid=paramgrid,cv=3)
rf_calibrated=CalibratedClassifierCV(grid_search_rf,cv=5, method="sigmoid")
rf_calibrated.fit(x_labelled,y_labelled)
print(rf_calibrated.base_estimator.best_params_)
AttributeError: 'GridSearchCV' object has no attribute 'best_params_'
Upvotes: 1
Views: 2088
Reputation: 36599
I am assuming you are thinking that the CalibratedClassifierCV will fit the supplied estimator and then somehow enhance (calibrate) the output probabilities for that.
Thats partially correct.
What happens is:
CalibratedClassifierCV will make a clone of the supplied estimator and then fit the data onto the clone. So you doing this
rf_calibrated.base_estimator`
will only return an unfitted estimator which don't have the best_params_
attribute. best_params_
is only available after fitting.
Checking best_params_
from CalibratedClassifierCV will not make any sense, because it will divide the data into 5 parts (as you have done cv=5
) in it and each fold is trained on a separate clone, so you may have multiple best_params
in that depending on the data.
Upvotes: 2