Dazu verwende ich die Bibliothek optuna.
Code: Alles auswählen
def objective(trial):
eta = trial.suggest_float("eta",0,0.5)
max_depth = trial.suggest_int("max_depth",2,32)
min_child_weight = trial.suggest_float("min_child_weight",0,3)
reg_alpha = trial.suggest_float("reg_alpha",0,3)
colsample_bytree = trial.suggest_float("colsample_bytree",0.5,1)
n_estimators = trial.suggest_int("n_estimators",10, 6000)
model = xgb.XGBClassifier(eta=eta,n_estimators =n_estimators, max_depth = max_depth,
reg_alpha = reg_alpha,min_child_weight=min_child_weight,
colsample_bytree=colsample_bytree, use_label_encoder=False,
val_metric='mlogloss',seed = 0)
model.fit(X_train,y_train)
predictions = model.predict(X_val)
return accuracy_score(y_true=y_val, y_pred=predictions)
study = optuna.create_study(direction = "maximize", pruner=optuna.pruners.HyperbandPruner())
study.optimize(objective, n_trials=100)
Ich finde aber keinen Fehler im Code.
Könnte mir bitte jemand helfen? Ich sitze schon den ganzen Tag dran.
Vielen Dank im Voraus!