GridSearchCV最佳模型简历历史 [英] GridSearchCV best model CV history

查看:79
本文介绍了GridSearchCV最佳模型简历历史的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将GridSearchCV和KerasRegressor一起用于超参数搜索. Keras model.fit函数本身允许使用历史对象查看'loss'和'val_loss'变量.

I am trying to use GridSearchCV along with KerasRegressor for hyperparameter search. Keras model.fit function on its own allows to look at the 'loss' and 'val_loss' variables using the history object.

使用GridSearchCV时是否可以查看'loss'和'val_loss'变量.

Is it possible to look at the 'loss' and 'val_loss' variables when using GridSearchCV.

这是我用来进行网格搜索的代码:

Here is the code i am using to do a gridsearch:

model = KerasRegressor(build_fn=create_model_gridsearch, verbose=0)
layers = [[16], [16,8]]
activations  =  ['relu' ]
optimizers = ['Adam']
param_grid = dict(layers=layers, activation=activations, input_dim=[X_train.shape[1]], output_dim=[Y_train.shape[1]], batch_size=specified_batch_size, epochs=num_of_epochs, optimizer=optimizers)
grid = GridSearchCV(estimator=model, param_grid=param_grid, scoring='neg_mean_squared_error', n_jobs=-1, verbose=1, cv=7)

grid_result = grid.fit(X_train, Y_train)

# summarize results
print("Best: %f using %s" % (grid_result.best_score_, grid_result.best_params_))
means = grid_result.cv_results_['mean_test_score']
stds = grid_result.cv_results_['std_test_score']
params = grid_result.cv_results_['params']
for mean, stdev, param in sorted(zip(means, stds, params), key=lambda x: x[0]):
    print("%f (%f) with: %r" % (mean, stdev, param))

def create_model_gridsearch(input_dim, output_dim, layers, activation, optimizer):
    model = Sequential()

    for i, nodes in enumerate(layers):
        if i == 0:
            model.add(Dense(nodes, input_dim=input_dim))
            model.add(Activation(activation))
        else:
            model.add(Dense(nodes))
            model.add(Activation(activation))
    model.add(Dense(output_dim, activation='linear'))

    model.compile(optimizer=optimizer, loss='mean_squared_error')

    return model

如何获得最佳模型grid_result.best_estimator_.model的训练和CV损失?

How can i get the training and CV loss per epoch for the best model, grid_result.best_estimator_.model?

没有像grid_result.best_estimator_.model.history.keys()这样的变量

There is no variable like grid_result.best_estimator_.model.history.keys()

推荐答案

历史记录被很好地隐藏了.我能够在

The history is well hidden. I was able to find it in

grid_result.best_estimator_.model.model.history.history

这篇关于GridSearchCV最佳模型简历历史的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆