I am new to neural networks and I want to use LSTM to classify the on/off state of devices based on power values. In my training dataset, I have power values, device one (0,1), and device 2 (0,1). 0 for no change in the state and 1 for when they are switched on and off. The testing dataset has only power values. The dataset has a temporal dependency, so I decided to use LSTM. Now, I am not able to prepare my data for this neural network. Could anyone please give me some tips/ guidelines or link to any resource? I would be thankful!

This is what my training data looks like;

enter image description here

def df_to_X_y_2(df, window_size = 12):
    df_np = df.to_numpy() 
    X = []
    y = []
    for i in range(window_size, len(df)):
        row = [[a] for a in df_np[i-window_size:i,0]]
        label = df_np[i-1,1:]
    return np.array(X), np.array(y)

I am using Keras and this is the model I came up with;

model1 = Sequential()
model1.add(InputLayer((12, 1)))
model1.add(Dense(32, 'relu'))
model1.add(Dense(2, 'sigmoid'))

cp1 = ModelCheckpoint('models/model1/', save_best_only=True)
model1.compile(loss='binary_crossentropy', optimizer=Adam(learning_rate=0.0001), metrics=['accuracy'])

model1.fit(X2, y2, epochs=10, callbacks=[cp1])

This is not giving me good results. There are a total of 12 ones (True) values for device 1 and 4 Trues for device 2 in my test data but it is not predicting one even once.

I tried this model as well but no luck.

model2 = Sequential()
model2.add(InputLayer((12, 1)))
# model2.add(LSTM(64, activation = 'tanh', recurrent_activation='hard_sigmoid'))

If someone's interested this is the detailed explanation of the task.

The task at hand involves developing a Non-Intrusive Load Monitoring (NILM) program that classifies continuous aggregate power loads into switching events. The dataset contains aggregate power loads and switching events for specific appliances. The goal is to analyze the data and develop an algorithm that accurately classifies the continuous aggregate power into switching events. The classification algorithm needs to identify the patterns in the continuous aggregate power, and accurately predicts switching events.

  • $\begingroup$ give us more information. Are you using Keras or PyTorch? Can you provide the network so we inspect it? $\endgroup$
    – Memristor
    Commented Jun 10, 2023 at 15:08
  • 1
    $\begingroup$ @Memristor, let me know if you need more information. $\endgroup$
    – Zain
    Commented Jun 10, 2023 at 17:04
  • $\begingroup$ If you want to know when the switching is ON/OFF I would take the values from power directly before jumping to the LSTM. $\endgroup$
    – Memristor
    Commented Jun 10, 2023 at 22:02
  • $\begingroup$ could you please elaborate? Did you mean that LSTM is not the right choice of the algorithm here? If this is the case, what other neural networks should I look into? $\endgroup$
    – Zain
    Commented Jun 10, 2023 at 22:55
  • $\begingroup$ If you are not getting results you should indeed try another approach. From a physics perspective (maybe your problem is more complicated, then I'm wrong) switches have a threshold so that when the voltage is greater they become ON, the rest of the time it is OFF by default, so maybe starting with a fully connected or a Decision Tree (or even a linear regression) can be a better approach. $\endgroup$
    – Memristor
    Commented Jun 11, 2023 at 0:12


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.