I am trying to optimize a classification model for a certain performance metric using hyperparameter tuning. I did not receive the above error until I tried to tune my model specifically for the precision_score
metric; when I just used my model as a normal predictor everything ran very smoothly, even when I added hyperparameter tuning it was fine. Only when I tried to optimize it to a certain metric did it throw this error. This is the relevant code:
scorers = {
'precision_score': make_scorer(precision_score),
'recall_score': make_scorer(recall_score),
'accuracy_score': make_scorer(accuracy_score)
}
rf = RandomForestRegressor()
cv=KFold(n_splits=5,random_state=1,shuffle=False)
rf_rsearch = RandomizedSearchCV(estimator = rf, param_distributions = random_hypparams, scoring=scorers,refit='precision_score', return_train_score=True, n_iter = 50, cv = cv , verbose=2, n_jobs = -1)
rf_rsearch.fit(OS_x, OS_y)
In this code:
- random_hyperparams: is just a grid of randomized hyperparameters to be tested to find the best set.
- OS_x, OS_y are the x and y training set oversampled using SMC with the respective shapes: (1290, 33) (1290,)
The error seems to be occurring in the final line of the chunk of code displayed.