NameError: x_train is not deinfed

Viewed 20

I keep getting this error. I am building a prediction model but can't seem to get passed this

X_train = []
y_train = []

for i in range(100, data_training_array.shape[0]):
    x_train.append(data_training_array[i-100: i])
    y_train.append(data_training_array[i, 0])
    
x_train, y_train = np.array(x_train), np.array(y_train)

NameError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_34316/1046987676.py in 3 4 for i in range(100, data_training_array.shape[0]): ----> 5 x_train.append(data_training_array[i-100: i]) 6 y_train.append(data_training_array[i, 0]) 7

NameError: name 'x_train' is not defined

1 Answers

X_train is capitalized when you initialize it, but you refer to it as x_train in the rest of your code. Lowercase x_train = [] or capitalize it in the rest of the code.

Related