我正在从事一个学校项目,该项目计算数字的平均值,并将其与实际数字进行比较,例如: 我的数据是:
heats_chem = [0,1,2,3,4,5,6,7,8,9]
我的职能是:
def test(number_of_heats, length):
all_mean_errors = []
all_means = []
for heat in range(number_of_heats, len(heats_chem)-length, length):
train_data = heats_chem[heat:heat+number_of_heats]
test_data = heats_chem[heat + number_of_heats : heat + number_of_heats + length]
prediction_mean = mean(train_data)
all_means.append(prediction_mean)
mean_error = get_error(prediction_mean, test_data)
all_mean_errors.append(mean_error)
其中,热量的数量是计算预测的元素数,长度是我试图预测的下一个元素数。现在我正在尝试制作一个函数来实现这一点,但我也能够使用更多的元素“窗口”来进行更精确的预测,所以我将使用另一个参数,称为窗口
def test(number_of_heats, length, windows)
现在举例来说,使用参数2,1,3
,它应该做0,1,2,3,4,5
计算平均值,检查2,3,4,5
计算平均值,检查4,5
和计算平均值,然后切换到下一个,做2,3,4,5,6,7
平均值,4,5,6,7
平均值等等。但对于我来说,我最难的时间是尝试将它放入另一个循环中,以便能够做到这一点。谁能帮我一下吗
目前没有回答
相关问题 更多 >
编程相关推荐