简单移动平均,利用Numpy、Pandas
import random
data = [random.uniform(0, 10) for i in range(100)] # 生成100个 10以内的浮点数
import pandas as pd
import numpy as np
df = pd.DataFrame(data, columns=['value'])
df['SMA_10'] = df['value'].rolling(window=10).mean() #大小为10的窗口
print(df.head(30))
mae = np.mean(np.abs(df['value'] - df['SMA_10'])) # 平均绝对误差评估
print("MAE: ", mae)
加权移动平均
标签:10,预测,df,代码,random,value,np,序列,import
From: https://www.cnblogs.com/ivan09/p/17142795.html