Skip to content
Advertisement

RandomizedSearchCV: All estimators failed to fit

I am currently working on the “French Motor Claims Datasets freMTPL2freq” Kaggle competition (https://www.kaggle.com/floser/french-motor-claims-datasets-fremtpl2freq). Unfortunately I get a “NotFittedError: All estimators failed to fit” error whenever I am using RandomizedSearchCV and I cannot figure out why that is. Any help is much appreciated.

JavaScript

The first five rows of the original dataframe data_freq look like this:

JavaScript

The error I get is as follows:

JavaScript

I also tried running fit without the sample_weight parameter. In this case the error changes to:

JavaScript

When setting verbose = 10 and n_jobs = 1 the following error message shows up:

JavaScript

Advertisement

Answer

Wow, that was a mess of a traceback, but I think I’ve finally found it. You set scoring=mean_squared_error, and should instead use scoring="neg_mean_squared_error".

The metric function mean_squared_error has signature (y_true, y_pred, *, <kwargs>), whereas the scorer obtained by using the string "neg_mean_squared_error" has signature (estimator, X_test, y_test). So in the traceback, where you see

JavaScript

it is calling mean_squared_error with y_true=estimator, y_test=X_test, and sample_weight=y_test (the first kwarg, and hence the FutureWarning about specifying keyword arguments as positional). Going deeper into the traceback, we see a check that the shapes of y_true and y_pred are compatible, but it thinks the former is your pipeline object (and hence the final error message)!

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement