如何评估keras调谐器的模型性能。
我目前正在尝试通过在每个时期显示Val_mse来可视化我的预测模型的性能。用于model.fit()
用于tuner.search()
的代码不起作用。谁能为我提供一些指南。谢谢。
上一个代码:
import matplotlib.pyplot as plt
def plot_model(history):
hist = pd.DataFrame (history.history)
hist['epoch'] = history.epoch
plt.figure()
plt.xlabel('Epoch')
plt.ylabel('Mean Absolute Error')
plt.plot(hist['epoch'], hist['mae'],
label='Train Error')
plt.plot(hist['epoch'], hist['val_mae'],
label = 'Val Error')
plt.legend()
plt.ylim([0,20])
plt.figure()
plt.xlabel('Epoch')
plt.ylabel('Mean Square Error')
plt.plot (hist['epoch'], hist['mse'],
label='Train Error')
plt.plot (hist['epoch'], hist['val_mse'],
label = 'Val Error')
plt.legend()
plt.ylim([0,400])
plot_model(history)
keras.tuner代码:
history = tuner.search(x = normed_train_data,
y = y_train,
epochs = 200,
batch_size=64,
validation_data=(normed_test_data, y_test),
callbacks = [early_stopping])
I'm currently trying to visualise the performance of my prediction model by showing the val_mse in every epoch. The code that used to work for model.fit()
doesn't work for tuner.search()
. Can anyone provide me with some guide on this. Thank you.
Previous code:
import matplotlib.pyplot as plt
def plot_model(history):
hist = pd.DataFrame (history.history)
hist['epoch'] = history.epoch
plt.figure()
plt.xlabel('Epoch')
plt.ylabel('Mean Absolute Error')
plt.plot(hist['epoch'], hist['mae'],
label='Train Error')
plt.plot(hist['epoch'], hist['val_mae'],
label = 'Val Error')
plt.legend()
plt.ylim([0,20])
plt.figure()
plt.xlabel('Epoch')
plt.ylabel('Mean Square Error')
plt.plot (hist['epoch'], hist['mse'],
label='Train Error')
plt.plot (hist['epoch'], hist['val_mse'],
label = 'Val Error')
plt.legend()
plt.ylim([0,400])
plot_model(history)
keras.tuner code:
history = tuner.search(x = normed_train_data,
y = y_train,
epochs = 200,
batch_size=64,
validation_data=(normed_test_data, y_test),
callbacks = [early_stopping])
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Keras Tuner无法正常工作!
使用张量板回调,还有更多的“ kerastuner” - 友好的方式来可视化训练曲线。
这样定义张板回调。
修改您的tuner.search()方法。
用于在Python笔记本(.IPYNB)中运行此操作。
有关更多信息,请访问: https://keras.io/guides/guides/guides/keras_tuner/visal/visalize_tuning/
Keras Tuner does not work that way!
There is more "KerasTuner"-friendly way of visualizing the training curves by using Tensorboard callback.
Define the tensorboard callback like this.
Modify you tuner.search() method like this.
For running this in Python Notebook (.ipynb).
For more information visit: https://keras.io/guides/keras_tuner/visualize_tuning/
在使用
tuner.search
要搜索最佳模型之前,您需要安装和导入keras_tuner
:然后,在模型定义中定义超参数(HP),例如:
初始化调谐器:
现在,启动搜索并使用
tuner.search
获得最佳模型:因此,现在您可以使用此
best_model
来训练和评估模型您的数据集并将大大减少损失。请检查此链接作为参考,以获取更多详细信息。
Before using
tuner.search
to search the best model, you need to install and importkeras_tuner
:Then, define the hyperparameter (hp) in the model definition, for instance as below:
Initialize the tuner:
Now, Start the search and get the best model by using
tuner.search
:Hence, Now you can use this
best_model
to train and evaluate the model with your dataset and will get a significant decrease in loss.Please check this link as a reference for more detail.