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)
14 ↑
15# our custom loss function