非常抱歉给您带来了困扰。根据您的反馈,上面的代码中确实缺少了定义'future_scaled'的部分。以下是修正后的代码:

# 构建未来10年的特征矩阵
future_features = np.zeros((10, len(data[0])-1))
current_data = data[-1, :-1]  # 使用最后一行数据作为当前数据

# 根据模型预测未来十年的特征
for i in range(10):
    feature = model.predict(current_data.reshape(1, -1))  # 使用模型预测特征
    future_features[i] = feature  # 更新特征矩阵
    current_data = np.concatenate((current_data[1:], feature))  # 更新当前数据

# 归一化未来的特征数据
future_scaled = scaler.transform(future_features)

# 使用TSK_FLS模型预测未来十年的目标变量
future_pred = model.predict(future_scaled)

# 计算置信区间
residuals = y_test - y_pred
mean_residuals = np.mean(residuals)
std_residuals = np.std(residuals)
n_samples = len(future_pred)
z_score = 1.96  # 对应于95%的置信区间
margin_of_error = z_score * std_residuals / np.sqrt(n_samples)

lower_bound = future_pred - margin_of_error
upper_bound = future_pred + margin_of_error

# 输出未来十年的预测置信区间
print('未来十年的预测置信区间:')
for i in range(len(future_pred)):
    print(f'年份: {i+1}, 下界: {lower_bound[i]}, 上界: {upper_bound[i]}')

这次修正后的代码中包含了未定义的'future_scaled'的定义和使用。

非常抱歉之前的错误带来的困扰,希望以上修正的代码能帮助您计算预测未来10年成分数据的置信区间。如果您还有任何其他问题,请随时提问。

Python 错误:NameError: name 'future_scaled' is not defined - TSK-FS 模型预测置信区间

原文地址: https://www.cveoy.top/t/topic/5Ww 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录