简体   繁体   English

适合:使用 sklearn.model_selection.GridSearchCV 传递多个输入

[英]fit: passing multiple inputs with sklearn.model_selection.GridSearchCV

as explained in https://keras.io/models/model , Keras' fit function x can behttps://keras.io/models/model 中所述,Keras 的fit函数x可以是

Numpy array of training data (if the model has a single input), or list of Numpy arrays (if the model has multiple inputs).训练数据的 Numpy 数组(如果模型有单个输入),或 Numpy 数组列表(如果模型有多个输入)。 If input layers in the model are named, you can also pass a dictionary mapping input names to Numpy arrays.如果模型中的输入层已命名,您还可以将字典映射输入名称传递给 Numpy 数组。

but it doesn't seem to be possible with sklearn.model_selection.GridSearchCV fit .但 sklearn.model_selection.GridSearchCV fit似乎不可能。 Is that true?真的吗? Is there any workaround?有什么解决方法吗?

Thanks!谢谢!

If you want to just use grid search as in sci-kit learn, you can use the KerasClassifier wrapper.如果您只想像在 sci-kit learn 中那样使用网格搜索,则可以使用 KerasClassifier 包装器。 You just create your model in your function.您只需在函数中创建模型。

def create_model(dropout_rate):
    #...
model = KerasClassifier(build_fn=create_model)

param_grid = dict(dropout_rate=[0.2,0.3,0.5])
grid = GridSearchCV(estimator=model, param_grid=param_grid, n_jobs=-1)
grid_result = grid.fit(X, Y)

https://machinelearningmastery.com/grid-search-hyperparameters-deep-learning-models-python-keras/ https://machinelearningmastery.com/grid-search-hyperparameters-deep-learning-models-python-keras/

Unfortunately, this approach is kind of limited, as you don´t have a validation after each epoch.不幸的是,这种方法有一定的局限性,因为您没有在每个 epoch 之后进行验证。 To solve this, you need to implement your own KerasClassifier.要解决这个问题,您需要实现自己的 KerasClassifier。

https://github.com/keras-team/keras/issues/4278 https://github.com/keras-team/keras/issues/4278

The short answers are yes and yes.简短的回答是肯定的。

GridSearchCV checks that X and y have the same length, I assume this is required for splitting the data to do cross-validation. GridSearchCV 检查 X 和 y 的长度是否相同,我认为这是拆分数据以进行交叉验证所必需的。 If you have multiple inputs and the first dimension of X represents this number of inputs this check wil fail.如果您有多个输入并且 X 的第一个维度表示输入的数量,则此检查将失败。

There is an issue to support multiple input layers: https://github.com/keras-team/keras/issues/9001 .支持多个输入层存在一个问题: https : //github.com/keras-team/keras/issues/9001 Also check this issue for a possible workaround.另请检查此问题以获取可能的解决方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在不拆分数据的情况下运行 sklearn.model_selection.GridSearchCV? - How to run sklearn.model_selection.GridSearchCV without splitting data? sklearn.model_selection.GridSearchCV 的 LatentDirichletAllocation 评分策略 - Scoring strategy of sklearn.model_selection.GridSearchCV for LatentDirichletAllocation 从 sklearn.model_selection.GridSearchCV 获取 keyerror - Getting keyerror from sklearn.model_selection.GridSearchCV sklearn.model_selection.GridSearchCV 可以自定义阈值吗? - Is sklearn.model_selection.GridSearchCV can do custom threshold? sklearn.model_selection.GridSearchCV 如何检索所有 .best_params_ - sklearn.model_selection.GridSearchCV how to retrieve all .best_params_ 回归问题中sklearn.model_selection.GridSearchCV中的cv参数:best_score_随着cv值的增大而减小 - cv parameter in sklearn.model_selection.GridSearchCV in regression problems: best_score_ decreases with larger cv values 如何定义自己的评分策略sklearn.model_selection.GridSearchCV? - How can I define my own scoring strategy sklearn.model_selection.GridSearchCV? 什么是“遗留数据”? sklearn.model_selection.GridSearchCV如何遗漏数据? - What is “the left out data”? How the data is being left out by `sklearn.model_selection.GridSearchCV`? Sklearn.model_selection GridsearchCV ValueError:C &lt;= 0 - Sklearn.model_selection GridsearchCV ValueError: C <= 0 使用适合sklearn gridsearchcv - use fit for sklearn gridsearchcv
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM