我正在尝试使用GridSearchCV找到NN回归模型的最佳参数,代码如下:
param_grid = dict(optimizer=optimizer, epochs=epochs, batch_size=batches, init=init
grid = GridSearchCV(estimator=model, param_grid=param_grid, scoring='neg_mean_squared_error')
grid_result = grid.fit(input_train, target_train)
pred = grid.predict(input_test)
据我了解, grid.predict(input_test)
使用最佳参数来预测给定的输入集 . 有没有办法使用测试集为每组参数评估GridSearchCV?
实际上,我的测试集包含一些特殊记录,我想测试模型的一般性和准确性 . 谢谢 .
1 回答
您可以使用自定义迭代器替换
GridSearchCV
的标准3倍cv参数,从而生成连锁列车和测试数据帧的列车和测试索引 . 结果,虽然1倍交叉验证,您将在input_train
对象上训练您的模型,并在input_test
对象上测试您的拟合模型:通过访问
grid_result.cv_results_
字典,您可以在测试集上查看指定模型参数的所有网格的度量值 .