python - 运行代码时出现错误:未定义“y_test”
问题描述
我正在运行此代码来训练和预测数据:
#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
请帮忙。
解决方案
您已经初始化Y_test
,但您正在使用y_test
计算rmse
,请确保您注意字母大小写。
推荐阅读
- php - 将 php webapplication 与 tally prime 连接以交换数据
- api - 汽车颜色代码 API
- c++ - std::stoi 可以验证 digit 的值是否超出基数范围吗?
- c# - C# DateTime 和 String 值条件检查
- ruby - 如何根据中间人 s3_sync 的环境更新配置?
- c# - 拆分字符串并以相反的顺序将其重新连接在一起
- css - 如何使 Bootstrap SVG 图标居中?
- gitlab-ci - 在 gitlab.ci.yml 的 slack POST CURL 命令中传递变量时的 invalid_payload
- sql - 访问日期之间的 VBA SQL 查询搜索
- python - 将用户分配给单个组 LDAP Django Netbox