keras: how to save the training history attribute of the history object

前端 未结 8 2030
小鲜肉
小鲜肉 2020-12-12 23:43

In Keras, we can return the output of model.fit to a history as follows:

 history = model.fit(X_train, y_train, 
                     batch_size         


        
8条回答
  •  無奈伤痛
    2020-12-12 23:57

    An other way to do this:

    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)
    

提交回复
热议问题