Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- best_model = None
- best_acc = 0
- best_f1 = 0
- best_depth = 0
- best_est = 0
- for est in range(1, 50):
- for depth in range (1, 16):
- model_forest = RandomForestClassifier(random_state=42, n_estimators=est, max_depth=depth, class_weight='balanced')
- model_forest.fit(X_train_counts, y_train)
- predictions_rf = model_forest.predict(X_test_counts)
- acc_score = accuracy_score(predictions_rf, y_test)
- f1score = f1_score(predictions_rf, y_test, pos_label=None, average='weighted')
- if f1score > best_f1:
- best_model = model_forest
- best_f1 = f1score
- best_est = est
- best_depth = depth
- print("F1:", best_f1, "Количество деревьев:", best_est, "Максимальная глубина:", best_depth)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement