0
$\begingroup$

I need help in increasing the accuracy of a classification model using Neural Networks on Tensorflow.

I am trying to train a model on sequential data [shape:((435802, 20), (435802,))] where every sequence is of length 20 and $$X,Y \in [0,6]$$

Concept: each value in the sequence represents a class of real data instance and the objective is to predict the next class instance.

X[n] = [3, 4, 3, 0, 2, 6, 6, 6, 6, 5, 4, 3, 2, 2, 2, 2, 4, 2, 0, 0] => Y[n] = 0

Class Distribution in Y:

0: 46458
1: 40909
2: 76398
3: 102515
4: 80830
5: 43569
6: 45123

I have tried various combinations of layers like Conv, LSTM, SimpleRNN, Bidirectional, GRU, Dense, etc

Latest Model Definition:

model: "sequential_69"
_________________________________________________________________
 Layer (type)                Output Shape              Param #   
=================================================================
 conv1d_11 (Conv1D)          (None, 20, 64)            256       
                                                                 
 bidirectional_32 (Bidirecti  (None, 20, 512)          494592    
 onal)                                                           
                                                                 
 bidirectional_33 (Bidirecti  (None, 20, 512)          1182720   
 onal)                                                           
                                                                 
 lstm_56 (LSTM)              (None, 20, 64)            147712    
                                                                 
 lstm_57 (LSTM)              (None, 20, 32)            12416     
                                                                 
 lstm_58 (LSTM)              (None, 16)                3136      
                                                                 
 dropout_95 (Dropout)        (None, 16)                0         
                                                                 
 flatten_42 (Flatten)        (None, 16)                0         
                                                                 
 dropout_96 (Dropout)        (None, 16)                0         
                                                                 
 dense_217 (Dense)           (None, 7)                 119       
                                                                 
=================================================================
Total params: 1,840,951
Trainable params: 1,840,951
Non-trainable params: 0
_________________________________________________________________
Epoch 1/20
698/698 - 24s - loss: 1.8671 - accuracy: 0.2324 - val_loss: 1.9549 - val_accuracy: 0.1769 - 24s/epoch - 35ms/step
Epoch 2/20
698/698 - 12s - loss: 1.8484 - accuracy: 0.2451 - val_loss: 1.9464 - val_accuracy: 0.1835 - 12s/epoch - 18ms/step
Epoch 3/20
698/698 - 12s - loss: 1.8189 - accuracy: 0.2539 - val_loss: 1.8762 - val_accuracy: 0.2491 - 12s/epoch - 17ms/step
Epoch 4/20
698/698 - 12s - loss: 1.7844 - accuracy: 0.2726 - val_loss: 1.8567 - val_accuracy: 0.2470 - 12s/epoch - 17ms/step
Epoch 5/20
698/698 - 12s - loss: 1.7129 - accuracy: 0.3054 - val_loss: 1.7388 - val_accuracy: 0.3015 - 12s/epoch - 18ms/step
Epoch 6/20
698/698 - 12s - loss: 1.5867 - accuracy: 0.3488 - val_loss: 1.5342 - val_accuracy: 0.3941 - 12s/epoch - 17ms/step
Epoch 7/20
698/698 - 12s - loss: 1.4544 - accuracy: 0.3974 - val_loss: 1.5511 - val_accuracy: 0.3502 - 12s/epoch - 17ms/step
Epoch 8/20
698/698 - 12s - loss: 1.3705 - accuracy: 0.4300 - val_loss: 1.4285 - val_accuracy: 0.4169 - 12s/epoch - 17ms/step
Epoch 9/20
698/698 - 12s - loss: 1.3284 - accuracy: 0.4489 - val_loss: 1.3488 - val_accuracy: 0.4606 - 12s/epoch - 17ms/step
Epoch 10/20
698/698 - 12s - loss: 1.3064 - accuracy: 0.4587 - val_loss: 1.3678 - val_accuracy: 0.4483 - 12s/epoch - 17ms/step
Epoch 11/20
698/698 - 12s - loss: 1.2945 - accuracy: 0.4640 - val_loss: 1.3417 - val_accuracy: 0.4631 - 12s/epoch - 17ms/step
Epoch 12/20
698/698 - 12s - loss: 1.2848 - accuracy: 0.4694 - val_loss: 1.3644 - val_accuracy: 0.4471 - 12s/epoch - 18ms/step
Epoch 13/20
698/698 - 12s - loss: 1.2780 - accuracy: 0.4729 - val_loss: 1.3474 - val_accuracy: 0.4616 - 12s/epoch - 17ms/step
Epoch 14/20
698/698 - 12s - loss: 1.2717 - accuracy: 0.4741 - val_loss: 1.3396 - val_accuracy: 0.4604 - 12s/epoch - 18ms/step
Epoch 15/20
698/698 - 12s - loss: 1.2666 - accuracy: 0.4764 - val_loss: 1.3862 - val_accuracy: 0.4390 - 12s/epoch - 18ms/step
Epoch 16/20
698/698 - 12s - loss: 1.2630 - accuracy: 0.4773 - val_loss: 1.3143 - val_accuracy: 0.4672 - 12s/epoch - 17ms/step
Epoch 17/20
698/698 - 12s - loss: 1.2582 - accuracy: 0.4788 - val_loss: 1.3189 - val_accuracy: 0.4640 - 12s/epoch - 17ms/step
Epoch 18/20
698/698 - 12s - loss: 1.2571 - accuracy: 0.4796 - val_loss: 1.3443 - val_accuracy: 0.4549 - 12s/epoch - 17ms/step
Epoch 19/20
698/698 - 12s - loss: 1.2529 - accuracy: 0.4816 - val_loss: 1.3186 - val_accuracy: 0.4692 - 12s/epoch - 17ms/step
Epoch 20/20
698/698 - 12s - loss: 1.2504 - accuracy: 0.4819 - val_loss: 1.3074 - val_accuracy: 0.4714 - 12s/epoch - 17ms/step
313/313 [==============================] - 4s 7ms/step
              precision    recall  f1-score   support

           0       0.62      0.80      0.70      1059
           1       0.46      0.14      0.22       986
           2       0.43      0.46      0.44      1760
           3       0.46      0.56      0.50      2310
           4       0.44      0.48      0.46      1890
           5       0.41      0.09      0.15       941
           6       0.59      0.76      0.66      1054

    accuracy                           0.49     10000
   macro avg       0.49      0.47      0.45     10000
weighted avg       0.48      0.49      0.46     10000

Accuracy Graph

Some more context: I am a noob in terms of Neural Networks training and have tried basic models like TF examples, Pytorch Examples and some AutoEncoder examples.

$\endgroup$

1 Answer 1

0
$\begingroup$

Can you elaborate on the relationship between X[n] and X[n-1] ?

is there a f so that X[n] = f(X[n-1]) ? is each X[n] the output of different sources or one single source ? is it the evolution of a state machine ?

Have you analyzed your database ? It is not balanced, but do you have things like a same sequence associated to different targets ?

$\endgroup$
2
  • $\begingroup$ before training, i do implement rebalancing by resampling. as far as the multiple next sequences to same sequence...there are a few samples like that. but only a few $\endgroup$ Sep 16 at 8:00
  • $\begingroup$ Also I have not done the F(x) analysis. will check on the state machine $\endgroup$ Sep 16 at 8:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .