Python / Keras - create a single forecast callback for each era

I use Keras to predict the time series. I use 20 eras as a standard. I want to know what my neural network predicted for each of the 20 eras.

Using model.predict, I get only one prediction among all eras (not sure how Keras chooses it). I want all the forecasts, or at least the top 10.

According to the previous answer I received, I have to calculate the predictions after each school age by completing the corresponding callback by subclassing Callback()and calling the model prediction inside the function on_epoch_end.

Well, the theory seems to be in shape, but I have problems with that. Can someone give some sample code?

Not sure how to implement a subclass Callback(), or how to mix it with a model.predictfunction inside on_epoch_end .

Your help would be much appreciated :)


EDIT

Well, I have changed a bit. We figured out how to create a subclass and how to associate it with model.predict. However, I burn my brain on how to create a list with all the predictions. Below is my current code:

#Creating a Callback subclass that stores each epoch prediction
class prediction_history(Callback):
    def on_epoch_end(self, epoch, logs={}):
        self.predhis=(model.predict(predictor_train))

#Calling the subclass
predictions=prediction_history()

#Executing the model.fit of the neural network
model.fit(X=predictor_train, y=target_train, nb_epoch=2, batch_size=batch,validation_split=0.1,callbacks=[predictions]) 

#Printing the prediction history
print predictions.predhis

However, all I get with this is a list of forecasts of the latest era (the same effect as print model.predict (predictor_train)).

Now the question arises: how do I adapt my code so that it adds to the predhispredictions of each era?

+4
source share
1 answer

, . :

class prediction_history(Callback):
    def __init__(self):
        self.predhis = []
    def on_epoch_end(self, epoch, logs={}):
        self.predhis.append(model.predict(predictor_train))

, self.predhis , .

+6

All Articles