custom scoring function gridsearchcv

Solutions on MaxInterview for custom scoring function gridsearchcv by the best coders in the world

showing results for - "custom scoring function gridsearchcv"
Thiago
02 Oct 2017
1# create custom loss function
2from sklearn.metrics import make_scorer
3
4# custom loss function
5def rmse_loss(y_true, y_pred):
6    return np.sqrt(np.mean(np.square(y_pred - y_true))) 
7  
8rmse = make_scorer(rmse_loss, greater_is_better=False)
9
10# training randomized search cv
11model_rndm = RandomizedSearchCV(RandomForestRegressor(), 
12                                param_distributions=random_grid,
13                                n_iter=200, scoring=rmse, cv=3, n_jobs=-1)
1415#                                      our custom loss function