In Keras, we can return the output of model.fit
to a history as follows:
history = model.fit(X_train, y_train,
batch_size
As history.history
is a dict
, you can convert it as well to a pandas
DataFrame
object, which can then be saved to suit your needs.
Step by step:
import pandas as pd
# assuming you stored your model.fit results in a 'history' variable:
history = model.fit(x_train, y_train, epochs=10)
# convert the history.history dict to a pandas DataFrame:
hist_df = pd.DataFrame(history.history)
# save to json:
hist_json_file = 'history.json'
with open(hist_json_file, mode='w') as f:
hist_df.to_json(f)
# or save to csv:
hist_csv_file = 'history.csv'
with open(hist_csv_file, mode='w') as f:
hist_df.to_csv(f)