Answers for "custom scoring function gridsearchcv"

1

custom scoring function gridsearchcv

# create custom loss function
from sklearn.metrics import make_scorer

# custom loss function
def rmse_loss(y_true, y_pred):
    return np.sqrt(np.mean(np.square(y_pred - y_true))) 
  
rmse = make_scorer(rmse_loss, greater_is_better=False)

# training randomized search cv
model_rndm = RandomizedSearchCV(RandomForestRegressor(), 
                                param_distributions=random_grid,
                                n_iter=200, scoring=rmse, cv=3, n_jobs=-1)
                                                 ↑
#                                      our custom loss function
Posted by: Guest on September-16-2021

Python Answers by Framework

Browse Popular Code Answers by Language