簡體   English   中英

ValueError:CategoricalDistribution 不支持動態值空間

[英]ValueError: CategoricalDistribution does not support dynamic value space

為 optuna 創建了一個目標 function 以找到 KNN 回歸器的最佳參數,但遇到此錯誤:

ValueError: CategoricalDistribution does not support dynamic value space

關於為什么會發生這種情況的任何建議?

def objective(trial):
    
    params = {
        'n_neighbors': trial.suggest_int('n_neighbors', 2, 10, step=2),
        'algorithm': trial.suggest_categorical('weights', ['auto', 'ball_tree', 'kd_tree', 'brute']),
        'weights': trial.suggest_categorical("weights", ['uniform', 'distance']),
        "leaf_size": trial.suggest_int("leaf_size", 10, 60, step=10),
        "p": trial.suggest_categorical("p", [1, 2]),
    }
    
    regression_model = KNeighborsRegressor(**params)
    regression_model.fit(x_train.values, y_train.values)
    
    y_pred = regression_model.predict(x_test)
    rmse = mean_squared_error(y_test, y_pred)
    
    return rmse

find_params = optuna.create_study(direction='minimize')
find_params.optimize(objective, n_trials=5)

看看這個 github 問題: Github 問題

您定義了兩次“權重”參數。 從改變

    'algorithm': trial.suggest_categorical('weights', ['auto', 'ball_tree', 'kd_tree', 'brute']),
    'weights': trial.suggest_categorical("weights", ['uniform', 'distance']),

    'algorithm': trial.suggest_categorical('algorithm', ['auto', 'ball_tree', 'kd_tree', 'brute']),
    'weights': trial.suggest_categorical("weights", ['uniform', 'distance']),

並且錯誤應該 go 消失。 Optuna 不支持具有多個同名但值空間不同的參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM