我在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 笔记本的最后输出。
将代码直接从笔记本导出到 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)
或者
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)