# error while fitting auto encoder for anomaly detection on sensor data [closed]

I have sensor data like this and it's unsupervised and it has almost 800 features. my use-case is for anomaly detection. I applied Principal component analysis (PCA) for dimensionality reduction. now i got 20 Principal component which i am going to use as features to fit autoencoder.

I am trying to fit autoencoder for anomaly detection use case following this tutorial https://engineering.taboola.com/anomaly-detection-using-lstm-autoencoder/ here is my code. But getting error Nameerror: name 'self' is not defined and please instead of downgrading try to help someone. As I am new to deep learning. I want to know as according to my use case i am i right direction and i need help to fit autoencoder to this is what i tried .

import matplotlib.pyplot as plt
import numpy as np
import tensorflow as tf
from tensorflow.keras.models import Model, Sequential
from tensorflow.keras.layers import Dense
import pandas as pd
import random
from sklearn.preprocessing import StandardScaler
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

df = df.astype('float32')
# normalize features
scaler = MinMaxScaler(feature_range=(0, 1))
scaled = scaler.fit_transform(df)
#Python
#fit
self.history = self.model.fit(self.train_X, self.train_y, epochs=50, batch_size=72, validation_split=0.1, shuffle=False)
#predict
# Python
X_test_pred = self.model.predict(self.test_X)
test_mae_loss = np.mean(np.abs(X_test_pred - self.test_X), axis=1)
test_mae_loss_avg_vector = np.mean(test_mae_loss, axis=1)


self is used in python class methods, to denote an instance of the class in python. For example in this snippet self.name will assign the given name to the instance.

class Dog:
def __init__(self, name):
self.name = name


Here, as you're not subclassing, you should remove the self and just use model.

self.model. -> model.


You'll also need to add a model declaration before using .add

from tensorflow.keras.models import Model

model = Model()
$$$$

• model = tf.keras.Model() and removing all references of self` should solve this issue – Saurav Maheshkar May 28 at 6:28