Code: Alles auswählen
def objective(trial):
n_estimators = trial.suggest_int("n_estimators",20, 1000)
max_depth = trial.suggest_int("max_depth",5,500)
rf = RandomForestClassifier(n_estimators=n_estimators, max_depth=max_depth, min_impurity_decrease=min_impurity_decrease, min_samples_split =min_samples_split, min_samples_leaf=min_samples_leaf,
bootstrap=False, max_features="auto")
scores = cross_val_score(rf, X_train, y_train, scoring = "accuracy", cv = 10)
return scores.mean()
study = optuna.create_study(direction = "maximize")
study.optimize(objective, n_trials=10000)
Wenn ich nun folgenden Code zum Validieren verwenden möchte, dann wird mir eine sehr viel kleiner accuracy bei dem report angegeben. Woran liegt das?
Code: Alles auswählen
# Confusion Matirx
predictions= cross_val_predict(model,X_main, y_main, cv = 10)
# Report für recall/precision/accuracy/f1
report = classification_report(y_main,predictions)