Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %%time
- from sklearn.model_selection import GridSearchCV
- model_gs = RandomForestClassifier(random_state=12345, criterion="gini")
- parametrs_gs = {
- 'n_estimators': range(1,126, 25),
- 'min_samples_leaf': range (1,8),
- 'max_depth': range (1,13, 2)
- }
- gs = GridSearchCV(estimator = model_gs,
- param_grid = parametrs_gs,
- cv=5,
- scoring=['f1', 'roc_auc'],
- refit='f1')
- gs.fit(pd.concat([features_train, features_valid]), pd.concat([target_train, target_valid]))
- print(gs.best_estimator_)
- print(gs.best_score_)
- #Output
- #RandomForestClassifier(max_depth=11, min_samples_leaf=2, n_estimators=76,
- #random_state=12345)
- #0.866125
- #CPU times: user 3min 23s, sys: 932 ms, total: 3min 24s
- #Wall time: 3min 25s
- # ПРИМЕНЯЮ ПАРАМЕТРЫ НА МОДЕЛИ
- %%time
- model = RandomForestClassifier(random_state=12345, criterion='gini', max_depth=11, min_samples_leaf=2, n_estimators=76)
- model.fit(features_train, target_train)
- predicted_train = model.predict(features_train)
- predicted_valid = model.predict(features_valid)
- # print(f1_score(target_train, predicted_train))
- print("F1: ", f1_score(target_valid, predicted_valid))
- print("ROC_AUC: ", roc_auc_score(target_valid, predicted_valid))
- print("RECALL: ", recall_score(target_valid, predicted_valid))
- print("PRECISION: ", precision_score(target_valid, predicted_valid))
- print("Accuracy_score ", accuracy_score(target_valid, predicted_valid))
- #Output
- #F1: 0.5466448445171849
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement