Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optuna を用いたハイパーパラメータチューニング #15

Open
Inazuma110 opened this issue Apr 24, 2021 · 0 comments
Open

Comments

@Inazuma110
Copy link
Owner

こんな感じでチューニングできます.

def objective(trial):
    params = {
        'objective': 'multi:softmax',
        'num_class': 11,
        'max_depth': trial.suggest_int('max_depth', 1, 20),
        'min_child_weight': trial.suggest_int('min_child_weight', 1, 20),
        'subsample': trial.suggest_discrete_uniform('subsample', 0.5, 0.9, 0.1),
        'colsample_bytree': trial.suggest_discrete_uniform('colsample_bytree', 0.5, 0.9, 0.1),
        'n_estimators': trial.suggest_int('n_estimators', 10, 1000),
        'learning_rate': trial.suggest_loguniform('learning_rate', 1e-8, 1.0),
        'reg_lambda': trial.suggest_discrete_uniform('lambda', 0, 1, 0.1)
    }
    model = xgb.XGBClassifier(**params)
    model.fit(train_train_x, train_train_y)

    pred = model.predict(train_test_x)

    accuracy = f1_score(train_test_y, pred, average='micro')
    return (1-accuracy)


study = optuna.create_study()
study.optimize(objective, n_trials=300)

書き方が古いのかwarningが出ます.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant