# f = plt.figure(facecolor='white') # timeSeries.plot(color='blue') # plt.show() # def draw_acf_pacf(ts,lags=40): # f = plt.figure(facecolor= 'white') # ax1 = f.add_subplot(211) # plot_acf(ts,lags=40,ax=ax1) # ax2 = f.add_subplot(212) # plot_pacf(ts,lags=40,ax=ax2) # plt.show() test_stationarity.testStationarity(dta) test_stationarity.draw_acf_pacf(dta,l=40) dta_log = np.log(dta) test_stationarity.draw_ts(dta_log) test_stationarity.draw_trend(dta_log,12) # #--------------------------handcraft diff------------------------------------# # diff_12 = dta_log.diff(12) # diff_12.dropna(inplace=True) # diff_12_1 = diff_12.diff(1) # diff_12_1.dropna(inplace=True) # test_stationarity.testStationarity(diff_12_1) # test_stationarity.draw_acf_pacf(diff_12_1) # from statsmodels.tsa.seasonal import seasonal_decompose # decomposition = seasonal_decompose(dta_log,model='multiplicative')
##################################################################################### """ for i in range(749): df = pd.read_csv("../merge_10/"+str(i+1)+".csv",index_col="timeStamp") # df = pd.read_csv("../merge_10_check/checkin.csv",index_col="timeStamp") df.index = pd.to_datetime(df.index) ts = df['passengerCount'] series_list[i]=ts # print ts.head() # print ts.head().index # print df.describe() # print df.dtypes # print "check date :",ts['2016-09-10 08:58:02'],ts['2016-09-10'],"http://www.cnblogs.com/foley/p/5582358.html" """ #log_tran """ # ts_log = np.log(ts) test_stationarity.draw_ts(series_list) """ ########################################################################## # import os # direction = "../merge_10_add_predict/" # file_list = os.listdir(direction) # for file_name in file_list: # print wifi_name_dict[int(file_name.split(".")[0])] # file_path = direction+file_name # df1 = pd.read_csv(file_path,index_col="timeStamp") # # df = pd.read_csv("../merge_10_check/checkin.csv",index_col="timeStamp") # df1.index = pd.to_datetime(df1.index) # df1.sort_index(inplace=True) # # cols = list(df1)
for row in rows: # if num == 0: # last_data = float(row[0]) # if float(row[0]) >400 or float(row[0])<40 : # data.append(last_data) # else: data.append(float(row[0])) last_data = float(row[0]) time.append(row[1]) num += 1 # x = np.linspace(0, 42, len(data)) # plt.plot(x,data) # plt.show() # present = pd.read_csv(file_path,sep = ',') # print present.shape # print present.columns # present_day = present.set_index("data") # present_day['date'].plot() # plt.legend(loc = 'best') # present_day.plot() # present_day.date.plot(color='g') # plt.legend(loc = 'best') # present_day[:10].plot(kind = 'bar') series_data = pd.Series(data) draw_trend(series_data, 10) from test_stationarity import draw_ts draw_ts(series_data) from test_stationarity import testStationarity testStationarity(series_data) from test_stationarity import draw_acf_pacf # draw_acf_pacf(series_data)
import numpy as np import pandas as pd from datetime import datetime import matplotlib.pylab as plt import test_stationarity from statsmodels.tsa.seasonal import seasonal_decompose # 读取数据,pd.read_csv默认生成DataFrame对象,需将其转换成Series对象 df = pd.read_csv('AirPassengers.csv', encoding='utf-8', index_col='date') df.index = pd.to_datetime(df.index) # 将字符串索引转换成时间索引 ts = df['Passengers'] # 生成pd.Series对象 # 查看数据格式 # print ts.head() # print ts['1949'] ts_log = np.log(ts) test_stationarity.draw_ts(ts_log) test_stationarity.draw_trend(ts_log, 12) diff_12 = ts_log.diff(12) diff_12.dropna(inplace=True) diff_12_1 = diff_12.diff(1) diff_12_1.dropna(inplace=True) test_stationarity.testStationarity(diff_12_1) print(test_stationarity.testStationarity(diff_12_1)) decomposition = seasonal_decompose(ts_log, model="additive") trend = decomposition.trend seasonal = decomposition.seasonal residual = decomposition.resid