超参数调优数据输出到excel表格

问题描述 投票:0回答:1

我在jupyter笔记本中对LSTM模型进行了超参数调整,我想将输出导出到Excel中,这样它将以表格形式存在,但是,使用这种编码,我只能得到超参数调整的最后一个输出。我想要在 Excel 中列出所有输出。我怎样才能得到它?

df=DataFrame({'神经元':[神经元],'优化器':[优化器],'学习率':[learning_rate],'批量大小':[batch_size],'MSE':[mse]}) df.to_excel(r"C:\Users\Daniee\Desktop\output.xlsx",index=False)

我尝试使用这个,但在 Excel 中,它仅导出 jupyter 笔记本的最后输出。

python excel deep-learning lstm hyperparameters
1个回答
0
投票

将代码直接从笔记本导出到 Excel 文件并不好,因为 Jupyter Notebook 通常都是

interactive
。打开 CSV 进行写入,然后通过
file.to_csv
读取它,然后使用
pd.read_csv
读取该 CSV。 现在使用如下路径将数据传输到 Excel 文件:

csv_file.to_excel(str(os.path.join(os.getcwd() , 'output.xlsx')) , index= False)
或者

您可以在开始超参数调整之前初始化一个空的 DataFrame,然后将每次迭代的结果附加到此 DataFrame,最后在所有迭代完成后将 DataFrame 导出到 Excel。

import pandas import os from pandas import Data frame Dframe = DataFrame(columns=['Neurons', 'Optimizer', 'Learning Rate', 'Batch Size', 'MSE']) for (neurons, optimizer, learning_rate, batch_size, mse) in hyperparameter_tuning:# Assuming it is an iterable consisting tuples results_df = Dframe.append({ 'Neurons': neurons, 'Optimizer': optimizer, 'Learning Rate': learning_rate, 'Batch Size': batch_size, 'MSE': mse }, ignore_index=True) ##You rest of code about hyperparameter tuning Dframe.to_excel(str(os.path.join(os.getcwd() ,'output.xlsx')) , index = False)
    
© www.soinside.com 2019 - 2024. All rights reserved.