import pandas as pd
import datetime
# 加载数据
def parser(x):
return datetime.datetime.strptime(x, '%Y/%m/%d')
ser = pd.read_csv('../LSTM系列/LSTM单变量1/data_set/shampoo-sales.csv',
header=0, parse_dates=[0], index_col=0, date_parser=parser).squeeze('columns')
# 做差分,去趋势,获得差分序列
def difference(dataset, interval=1):
diff = []
for i in range(interval, len(dataset)):
value = dataset[i] - dataset[i-interval]
diff.append(value)
return pd.Series(diff)
# 差分逆变换
def inverse_difference(history, yhat, interval=1):
return yhat + history[-interval]
differenced = difference(ser, 1)
print(differenced.head())
inverted = []
for i in range(len(differenced)):
value = inverse_difference(ser, differenced[i], len(ser)-i)
inverted.append(value)
inverted = pd.Series(inverted)
print(inverted.head())
标签:转换成,ser,稳定,interval,inverted,pd,序列,difference,differenced
From: https://www.cnblogs.com/lotuslaw/p/17103765.html