title: How to make a prediction on a RNN without training it every time
body: <p>I am new to Neural networks and I have successfully trained an RNN but it takes a while to train the data. It would not be feasible for me to train the data every time I want to make a prediction. So the question is, how do I make the training data persistent in that the RNN does not have to train every time every time I make a prediction?</p>
  <p>This is the code I am using...</p>
  <pre><code> from sklearn import preprocessing
   from sklearn.model_selection import train_test_split
   from keras.models import Sequential
   from keras.layers import Dense
   from keras.utils.data_utils import pad_sequences
  
  
   class Predict:
  
  TrainingData    = None
  XScale          = None
  
  
  def __init__(self,PredData,TrainingData):
  
  
      PreparedData = self.PrepareData(PredData,TrainingData)
  
      #set the training data
  
      self.Train(PreparedData)
  
      #split all of the training data into their respective variables
  
  
      X_train, X_val_and_test, Y_train, Y_val_and_test    = train_test_split(self.XScale, self.Y, test_size = 0.6)
      X_val, X_test, Y_val, Y_test                        = train_test_split(X_val_and_test, Y_val_and_test, test_size = 0.6)
  
      #define the model
      self.DefineModel(X_train, Y_train, X_val, Y_val)
  
      #do the prediction
      return self.predict(PredData)
  
  
  def PrepareData(self, PredData,TrainingData):
  
      LNumber = 0
  
      for I in TrainingData:
  
          if(len(I) &gt; LNumber):
              LNumber = len(I)
  
  
      PadData = pad_sequences(TrainingData, maxlen = LNumber, padding = 'post', truncating = 'post')
  
  
  
      return PadData
  
  def Train(self,TrainData):
  
      min_max_scaler = preprocessing.MinMaxScaler()
  
      self.X = TrainData[0:10]
      self.Y = TrainData[-10:]
  
  
  
  
  
      self.XScale = min_max_scaler.fit_transform(self.X)
  
  def DefineModel(self,X_train, T_train, X_val, Y_val):
  
      self.model = Sequential([
                                  Dense(32, activation = 'relu', input_shape = (10,)),
                                  Dense(32, activation = 'relu'),
                                  Dense(1, activation  = 'sigmoid'),
                              ])
  
      self.model.compile(     optimizer   = 'sgd',
                              loss        = 'binary_crossentropy',
                              metrics     = ['accuracy']
                              )
  
      self.model.fit(         X_train, Y_train,
                              batch_size = 32, epochs = 100,
                              validation_data = (X_val, Y_val))
  
  
  def predict(self,PredData):
  
      Self.Prediction = model.predict(PredData)
  </code></pre>