Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sklearn pipeline + keras sequential model - how to get history?

Keras models, when .fit is called, return a history object. Is it possible to retrieve it if I use this model as one step of a sklearn pipeline? btw, i'm using python 3.6

Thanks in advance!

like image 504
wass Avatar asked Jan 25 '19 04:01

wass


People also ask

What is history in Keras?

In the Keras docs, we find: The History. history attribute is a dictionary recording training loss values and metrics values at successive epochs, as well as validation loss values and validation metrics values (if applicable).

What is from Keras models import sequential?

Sequential. The core idea of Sequential API is simply arranging the Keras layers in a sequential order and so, it is called Sequential API. Most of the ANN also has layers in sequential order and the data flows from one layer to another layer in the given order until the data finally reaches the output layer.

What function should you use to train a Keras sequential model?

Fit Keras Model You can train or fit your model on your loaded data by calling the fit() function on the model. Training occurs over epochs, and each epoch is split into batches.


1 Answers

The History callback records training metrics for each epoch. This includes the loss and the accuracy (for classification problems) as well as the loss and accuracy for the validation dataset, if one is set.

The history object is returned from calls to the fit() function used to train the model. Metrics are stored in a dictionary in the history member of the object returned.

This also means that the values have to be in the scope of the fit() function or the sequential model, so if it is in a sklearn pipeline, it doesn't have access to the final values, and it can't store, or return what it can't see.

As of right now I an not aware of a history callback in sklearn so the only I see for you is to manually record the metrics you want to track. One way to do so would be to have pipeline return the data and then simply fit your model onto it. If you are not able to figure that out comment.

like image 102
anand_v.singh Avatar answered Oct 23 '22 20:10

anand_v.singh