运行我的代码时出现错误:'y_test' 未定义

时间:2020-12-20 13:06:38

标签: python numpy prediction

我正在运行此代码来训练和预测数据:

#Create the testing data set
#Create a new array containing scaled values from index 1543 to 2003
test_data = scaled_data[training_data_len - 60: , :]
#Create the data sets x_test and y_test
x_test= []
Y_test = dataset[training_data_len:, :]
for i in range(60, len(test_data)):
  x_test.append(test_data[i-60:i, 0])

#Convert the data to a numpy array
x_test = np.asarray(x_test)

#reshape the data
x_test = np.reshape(x_test, (x_test.shape[0], x_test.shape[1], 1))

#Get the models predicted price values
predictions = model.predict(x_test)
predictions = scaler.inverse_transform(predictions)

当我为 RMSE 运行以下代码时

#Get the root mean squared error (RMSE)
rmse=np.sqrt(np.mean(((predictions- y_test)**2)))
rmse

我收到以下错误:

NameError                                 Traceback (most recent call last)
<ipython-input-129-555ecc401e59> in <module>()
      1 #Get the root mean squared error (RMSE)
----> 2 rmse=np.sqrt(np.mean(((predictions- y_test)**2)))
      3 rmse

NameError: name 'y_test' is not defined

请帮忙。

1 个答案:

答案 0 :(得分:2)

您已初始化 Y_test,但您正在使用 y_test 计算 rmse,请确保注意字母大小写。