1

I want to tune my RF model using Optuna. The dataset is imbalanced. So, I used class_weight parameter to solve this. This is my RF Model code:

model = RandomForestClassifier(
            n_estimators = trial.suggest_int("clw_n_estimators", 10, 200),
            max_depth = trial.suggest_int("clw_max_depth", 1, 5),
            n_jobs = 4,
            class_weight = {0:1,1:trial.suggest_float('clw_class_weight', 1,1.95)},
            random_state = 2022,
        )

When I run the Optuna, it gave me the "returned nan" message like in this picture below:

study = optuna.create_study(
direction="maximize",)
study.optimize(objective, n_trials=5)

enter image description here

Are there any of you that ever met this problem too and knew how to solve this?

ferdianm10
  • 55
  • 4

2 Answers2

0

According to the error message, objective returns nan, which should be a float value. Could you double-check the definition of objective?

nzw0301
  • 359
  • 1
  • 9
0

I think one of the parameters passed to RandomForestClassifier, or in the fit() method (not shown in your question) is invalid. maybe double-check the random forest docs.

J R
  • 436
  • 3
  • 7