lstm.py
def create_model(self, n_ts_in:int, n_features:int):
        """ Create a new model from scratch.
        """

        # the input to LSTM layer should be (n_samples, n_ts_in, n_features)

        self.model = keras.models.Sequential()
        self.model.add(keras.layers.BatchNormalization(input_shape=(n_ts_in, n_features),
                                                    scale=False,
                                                    center=False)) # layer to normalize input samples
        self.model.add(keras.layers.LSTM(64, # dimensionality of the output space (number of neurons)
                                        activation="tanh",
                                        return_sequences=True)) # the output becomes the input of the next layer
        self.model.add(keras.layers.Dropout(0.5)) # apply dropout between layers to prevent overfitting
        self.model.add(keras.layers.LSTM(32, activation="tanh"))
        self.model.add(keras.layers.Dropout(0.5))
        #self.model.add(keras.layers.LSTM(16, activation="tanh"))
        #self.model.add(keras.layers.Dropout(0.5))
        self.model.add(keras.layers.Dense(10, activation="elu"))
        self.model.add(keras.layers.Dense(2, activation="softmax"))
        # softmax activation in the last layer and categorical crossentropy allow to get a result
        # telling something about the likelihood that a data point belongs to each of two classes.

        # configure the model for training
        self.model.compile(loss="categorical_crossentropy",
                        optimizer=keras.optimizers.Adam(lr=0.01),
                        metrics=["accuracy"])

        # self.model.summary()

        # save model
        self.save_model()

        # create folder for the metrics, if it does not exist
        path = self.metrics_dir + "/" + self.name
        Path(path).mkdir(parents=True, exist_ok=True)

        # create csv file to save metrics values
        with open(path + "/" + self.name + "_metrics.csv", "w") as output_file:
            output_file.write("epoch,loss,accuracy\n")

        return
 Create a new model from scratch.
        
Create a new model from scratch.
Create a new model from scratch .
def create_model(self, n_ts_in:int, n_features:int):
        self.model = keras.models.Sequential()
        self.model.add(keras.layers.BatchNormalization(input_shape=(n_ts_in, n_features),
                                                    scale=False,
                                                    center=False)) 
        self.model.add(keras.layers.LSTM(64, 
                                        activation="tanh",
                                        return_sequences=True)) 
        self.model.add(keras.layers.Dropout(0.5)) 
        self.model.add(keras.layers.LSTM(32, activation="tanh"))
        self.model.add(keras.layers.Dropout(0.5))
        self.model.add(keras.layers.Dense(10, activation="elu"))
        self.model.add(keras.layers.Dense(2, activation="softmax"))
        self.model.compile(loss="categorical_crossentropy",
                        optimizer=keras.optimizers.Adam(lr=0.01),
                        metrics=["accuracy"])
        self.save_model()
        path = self.metrics_dir + "/" + self.name
        Path(path).mkdir(parents=True, exist_ok=True)
        with open(path + "/" + self.name + "_metrics.csv", "w") as output_file:
            output_file.write("epoch,loss,accuracy\n")
        return
def create_model ( self , n_ts_in : int , n_features : int ) : self . model = keras . models . Sequential ( ) self . model . add ( keras . layers . BatchNormalization ( input_shape = ( n_ts_in , n_features ) , scale = False , center = False ) ) self . model . add ( keras . layers . LSTM ( 64 , activation = "tanh" , return_sequences = True ) ) self . model . add ( keras . layers . Dropout ( 0.5 ) ) self . model . add ( keras . layers . LSTM ( 32 , activation = "tanh" ) ) self . model . add ( keras . layers . Dropout ( 0.5 ) ) self . model . add ( keras . layers . Dense ( 10 , activation = "elu" ) ) self . model . add ( keras . layers . Dense ( 2 , activation = "softmax" ) ) self . model . compile ( loss = "categorical_crossentropy" , optimizer = keras . optimizers . Adam ( lr = 0.01 ) , metrics = [ "accuracy" ] ) self . save_model ( ) path = self . metrics_dir + "/" + self . name Path ( path ) . mkdir ( parents = True , exist_ok = True ) with open ( path + "/" + self . name + "_metrics.csv" , "w" ) as output_file : output_file . write ( "epoch,loss,accuracy\n" ) return
Create a new model from scratch.
Create a new model from scratch .
""" Create a new model from scratch.
        """ # the input to LSTM layer should be (n_samples, n_ts_in, n_features)
 # layer to normalize input samples
 # dimensionality of the output space (number of neurons)
 # the output becomes the input of the next layer
 # apply dropout between layers to prevent overfitting
 #self.model.add(keras.layers.LSTM(16, activation="tanh"))
 #self.model.add(keras.layers.Dropout(0.5))
 # softmax activation in the last layer and categorical crossentropy allow to get a result
 # telling something about the likelihood that a data point belongs to each of two classes.
 # configure the model for training
 # self.model.summary()
 # save model
 # create folder for the metrics, if it does not exist
 # create csv file to save metrics values

self
n_ts_in
int
n_features
int