【发布时间】:2021-04-11 21:52:27
【问题描述】:
我有一个关于超参数调整和寻找最佳拟合模型(寻找特定数据集的最佳拟合模型)的问题。有人建议我将数据分成三组,而不是两组(仅限训练和测试):
_培训
_验证
_测试
并在我的训练集上使用网格搜索(交叉验证),在网格搜索(交叉验证)之后,我可能会使用另一组“验证集”来测试我的模型的泛化能力(在看不见的数据上的性能),我可以之后更改一些参数。但是,我不知道如何使用验证集来测试我的模型的泛化能力。
我的代码:
dt = DecisionTreeClassifier(random_state=12)
max_depth = [int(d) for d in np.linspace(1,20,20)]
max_features = ['log2', 'sqrt','auto']
criterion = ['gini', 'entropy']
min_samples_split = [2, 3, 50, 100]
min_samples_leaf = [1, 5, 8, 10]
grid_param_dt = dict(max_depth=max_depth, max_features=max_features, min_samples_split=min_samples_split, min_samples_leaf=min_samples_leaf, criterion=criterion)
gd_sr_dt = GridSearchCV(estimator=dt, param_grid=grid_param_dt, scoring='accuracy', cv=10)
gd_sr_dt.fit(x_train, y_train)
best_parameters_dt = gd_sr_dt.best_params_
print(best_parameters_dt)
我得到的超参数调整如下:
{'criterion': 'gini', 'max_depth': 9, 'max_features': 'log2', 'min_samples_leaf': 10, 'min_samples_split': 50}
如何使用验证集来测试具有这些超参数的模型的泛化能力?
【问题讨论】:
标签: python machine-learning hyperparameters