Reusing Model Fitted By Cross_val_score In Sklearn Using Joblib
Solution 1:
It's not quite correct that cross-validation has to fit your model; rather a k-fold cross validation fits your model k times on partial data sets. If you want the model itself, you actually need to fit the model again on the whole dataset; this actually isn't part of the cross-validation process. So it actually wouldn't be redundant to call
alg.fit(data, labels)
to fit your model after your cross validation.
Another approcach would be rather than using the specialized function cross_val_score
, you could think of this as a special case of a cross-validated grid search (with a single point in the parameter space). In this case GridSearchCV
will by default refit the model over the entire dataset (it has a parameter refit=True
), and also has predict
and predict_proba
methods in its API.
Solution 2:
The real reason your model is not fitted is that the function cross_val_score
first copies your model before fitting the copy : Source link
So your original model has not been fitted.
Solution 3:
Cross_val_score does not keep the fitted model Cross_val_predict does There is no cross_val_predict_proba but you can do this
Post a Comment for "Reusing Model Fitted By Cross_val_score In Sklearn Using Joblib"