- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
由于某种原因,Optuna TPESampler 和 RandomSampler 对任何参数尝试相同的建议整数值(也可能是浮点数和对数)不止一次。我找不到一种方法来阻止它再次建议相同的值。在 100 次试验中,相当多的试验只是重复。在 100 次试验中,唯一建议值计数最终约为 80-90。如果我包含更多的调整参数,比如说 3,我什至会看到所有 3 个参数在 100 次试验中多次获得相同的值。
就像这样。 75 for min_data_in_leaf 使用了 3 次:
[I 2020-11-14 14:44:05,320] 试验 8 完成值:45910.54012028659 和参数:{'min_data_in_leaf': 75}。最好的是试用 4,其值为:45805.19030897498。
[I 2020-11-14 14:44:07,876] 试验 9 完成值:45910.54012028659 和参数:{'min_data_in_leaf': 75}。最好的是试用 4,其值为:45805.19030897498。
[I 2020-11-14 14:44:10,447] 试验 10 完成,值:45831.75933279074 和参数:{'min_data_in_leaf': 43}。最好的是试用 4,其值为:45805.19030897498。
[I 2020-11-14 14:44:13,502] Trial 11 完成,值:46125.39810101329 和参数:{'min_data_in_leaf': 4}。最好的是试用 4,其值为:45805.19030897498。
[I 2020-11-14 14:44:16,547] Trial 12 完成,值:45910.54012028659 和参数:{'min_data_in_leaf': 75}。最好的是试用 4,其值为:45805.19030897498。
示例代码如下:
def lgb_optuna(trial):
rmse = []
params = {
"seed": 42,
"objective": "regression",
"metric": "rmse",
"verbosity": -1,
"boosting": "gbdt",
"num_iterations": 1000,
'min_data_in_leaf': trial.suggest_int('min_data_in_leaf', 1, 100)
}
cv = StratifiedKFold(n_splits=5, random_state=42, shuffle=False)
for train_index, test_index in cv.split(tfd_train, tfd_train[:,-1]):
X_train, X_test = tfd_train[train_index], tfd_train[test_index]
y_train = X_train[:,-2].copy()
y_test = X_test[:,-2].copy()
dtrain = lgb.Dataset(X_train[:,:-2], label=y_train)
dtest = lgb.Dataset(X_test[:,:-2], label=y_test)
booster_gbm = lgb.train(params, dtrain, valid_sets=dtest, verbose_eval=False)
y_predictions = booster_gbm.predict(X_test[:,:-2])
final_mse = mean_squared_error(y_test, y_predictions)
final_rmse = np.sqrt(final_mse)
rmse.append(final_rmse)
return np.mean(rmse)
study = optuna.create_study(sampler=TPESampler(seed=42), direction='minimize')
study.optimize(lgb_optuna, n_trials=100)
最佳答案
问题是您在此行中指定的采样器:
study = optuna.create_study(sampler=TPESampler(seed=42), direction='minimize')
TPESampler
不是一个统一的采样器。这是一个不同的采样器,它试图从有希望的值范围中进行采样。查看详情
here和
here .这就是您看到大量重复的原因。对于优化器,它们是有希望的值,然后它们可能会以不同的组合进行进一步探索。
sampler=RandomSampler(seed)
这并不能保证不会有重复,但值会更均匀地分布
GridSampler
.正如文档中所述:
the trials suggest all combinations of parameters in the given searchspace during the study.
关于python - Optuna 在大量试验中建议相同的参数值(浪费时间和预算的重复试验),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64836142/
我正在尝试将 LightGBM 用于回归问题(平均绝对误差/L1 - 或类似 Huber 或 pseud-Huber - 损失),我主要想调整我的超参数。 LightGBMTunerCV在 optun
这个问题的背景是通过运行 study.optimize() 来优化神经网络训练的超参数,启用默认剪枝并将学习率作为优化参数(这个问题可以推广到其他超参数). 高学习率最初可以产生良好的结果,可以在开始
使用 Optuna 执行单目标优化时,研究的最佳参数可使用: import optuna def objective(trial): x = trial.suggest_uniform('x'
使用 Optuna 执行单目标优化时,研究的最佳参数可使用: import optuna def objective(trial): x = trial.suggest_uniform('x'
我在寻找最佳 auc 的 lightgbm 建模中遇到错误。任何帮助将不胜感激。 import optuna from sklearn.model_selection import Stratifi
如何在 Optuna 的 objective 函数中同时优化多个指标。例如,我正在训练一个 LGBM 分类器,并希望为所有常见分类指标(如 F1、精度、召回率、准确率、AUC 等)找到最佳超参数集。
我知道这个问题已经被问过多次,但是有了其他线程的答案,我无法解决我的问题。我正在使用 python3 CTGAN_noscale.py --database_name CTGAN_noshift 在命
由于某种原因,Optuna TPESampler 和 RandomSampler 对任何参数尝试相同的建议整数值(也可能是浮点数和对数)不止一次。我找不到一种方法来阻止它再次建议相同的值。在 100
我正在尝试使用 optuna 搜索超参数空间。 在一个特定场景中,我在一台带有几个 GPU 的机器上训练一个模型。模型和批量大小允许我每 1 个 GPU 运行 1 次训练。所以,理想情况下,我想让 o
我正在使用 optuna 来优化我的自定义模型的参数。 有没有办法对参数进行采样,直到之前未测试当前参数集?我的意思是,如果过去使用相同的参数集进行过一些尝试,请尝试对另一个参数进行采样。 在某些情况
我想在 Optuna 中建议比率。 比率为 X_1, X_2, ..., X_k , 以 ∑X_i = 1 为界和 0 <= X_i <= 1对于所有 i . Optuna 不提供 Dirichlet
我正在使用 Optuna 优化一些目标函数。我想创建“包装”标准 Optuna 代码的自定义类。 例如,这是我的类(class)(它仍在进行中!): class Optimizer(object):
我想获得稍后在笔记本中使用的最佳模型,以使用不同的测试批次进行预测。 可重现的示例(取自 Optuna Github): import lightgbm as lgb import numpy as
我将 sklearn 与 optuna 一起用于 HPO。我想创建一个自定义函数,它将 sklearn 管道作为输入并返回特定于 optuna 的网格。返回 sklearn 特定的参数网格(即字典)似
我在使用 Optuna 调整我的模型时遇到警告。请告诉我如何抑制这些警告? [LightGBM] [Warning] feature_fraction is set=0.2, colsample_by
我想对官方 Optuna 和基于 pytorch 的示例代码 ( https://github.com/optuna/optuna/blob/master/examples/pytorch_simpl
我尝试使用 optuna 来调整超参数。但我的目标函数是有条件的,这会在获得最佳参数方面产生问题。 只有满足条件时我才想获得 cwc,否则继续尝试下一个超参数。但我猜由于条件不满足并且目标函数返回 c
我正在尝试在 Python 中使用 optuna 库来优化推荐系统模型的参数。这些模型是自定义的,看起来像标准的拟合预测 sklearn 模型(使用方法获取/设置参数)。 我所做的:从均匀 int 分
我想将 [OPTUNA][1] 与 sklearn [MLPRegressor][1] 模型一起使用。 对于几乎所有超参数,如何为它们设置 OPTUNA 都非常简单。例如,要设置学习率:learnin
def autotune(trial): cfg= { 'device' : "cuda" if torch.cuda.is_available() else "cpu",
我是一名优秀的程序员,十分优秀!