0
$\begingroup$

I am trying to build a RNN for classification and below is the layout of the network

import tensorflow as tf
model  = tf.keras.Sequential()
model.add(tf.keras.layers.Masking(mask_value=-100.0, input_shape=X.shape[1:]))
model.add(tf.keras.layers.LSTM(units = X.shape[1]))
model.add(tf.keras.layers.Dense(units=10,activation='relu'))
model.add(tf.keras.layers.Dense(units=1,activation=tf.nn.sigmoid))
model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy',tf.keras.metrics.AUC(name='auc')])

and adding class weights

from sklearn.utils.class_weight import compute_class_weight
class_weight = compute_class_weight(class_weight='balanced',classes =np.unique(y),y=y)
class_weight = {i : class_weight[i] for i in range(len(class_weight))}

and fitting using

model.fit(X,y,epochs=10,validation_split=0.4,class_weight=class_weight)

My X has structure :

array([[[  0.29615385,   0.9375    ,   0.52268041, ...,   0.        ,
           0.13050997,   0.15842043],
        [  0.29615385,   0.9375    ,   0.52268041, ...,   0.        ,
           0.13050997,   0.15842043],
        [  0.26538462,   0.9875    ,   0.52268041, ...,   0.        ,
           0.09115686,   0.12374666],
        ...,
        [-100.        , -100.        , -100.        , ..., -100.        ,
         -100.        , -100.        ],
        [-100.        , -100.        , -100.        , ..., -100.        ,
         -100.        , -100.        ],
        [-100.        , -100.        , -100.        , ..., -100.        ,
         -100.        , -100.        ]],

           :
           :
           :

The -100 is the padding done to make those inner 2d arrays of same shape

However the model is not learning as I expect it to be i.e increasing accuracy

The model's accuracy does not increase more than this, it decreases on more epochs. Is there anything wrong with my Neural Network structure or I need to experiment with more number of hidden layers (which I already tried)

757/757 [=============>] - ETA: 10:08 - loss: 0.6800 - accuracy: 0.5290 - auc: 0.6303
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.