open = X_test['Open'].values for i in range(len(open)): if open[i] == 0: predict[i] = 0 print(predict) predict = pd.DataFrame({ 'Date': pd.date_range(start='2015-06-02', end='2015-07-31'), 'Sales': predict }) predict = predict.set_index('Date') rmspe = RMSPE(test.values, predict.values) print(rmspe) rmse = RMSE(test.values, predict.values) print(rmse) end = time.clock() print(end - start) plot(test, predict, 'holt winters') plt.show() ''' [4078.688909737665, 3914.9182155556387, 0, 3878.2511613264446, 4278.099628828576, 0, 4273.686082464293, 4078.9217627910157, 3915.151068608989, 3628.0536168821154, 3878.484014379795, 4278.332481881926, 0, 4273.918935517643, 4079.154615844366, 3915.3839216623396, 3628.286469935466, 3878.7168674331456, 4278.565334935276, 0, 4274.151788570994, 4079.3874688977157, 3915.61677471569, 3628.5193229888164, 3878.949720486496, 4278.7981879886265, 0, 4274.384641624344, 4079.620321951066, 3915.8496277690406, 3628.752176042167, 3879.1825735398456, 4279.031041041977, 0, 4274.617494677695, 4079.8531750044167, 3916.082480822391, 3628.9850290955173, 3879.415426593196, 4279.2638940953275, 0, 4274.850347731044, 4080.086028057767, 3916.3153338757415, 3629.217882148868, 3879.6482796465466, 4279.496747148678, 0, 4275.083200784395, 4080.3188811111177, 3916.548186929092, 3629.4507352022174, 3879.881132699897, 4279.729600202028, 0, 4275.316053837745, 4080.551734164468, 3916.7810399824425, 3629.683588255568, 3880.1139857532476] 0.16513565625542484 776.7568224130538 1.2834301828308678 '''
open = X_test['Open'].values for i in range(len(open)): if open[i] == 0: predict[i] = 0 print(predict.tolist()) predict = pd.DataFrame({ 'Date': pd.date_range(start='2015-06-02', end='2015-07-31'), 'Sales': predict }) predict = predict.set_index('Date') rmspe = RMSPE(Y_test.values, predict.values) print(rmspe) rmse = RMSE(Y_test.values, predict.values) print(rmse) end = time.clock() print(end - start) plot(Y_test, predict, 'XGBoost') plt.show() #0.09163980031597718 #410.174619826727 #2.8563968433922797
X_train1,Y_train1,X_test1,Y_test1 = getData() open = X_test1['Open'].values for i in range(len(open)): if open[i] == 0: predict[i] = 0 print(predict) predict = pd.DataFrame({'Date':pd.date_range(start='2015-06-02',end='2015-07-31'),'Sales':predict}) predict = predict.set_index('Date') rmspe = RMSPE(Y_test1.values,predict.values) print(rmspe) rmse = RMSE(Y_test1.values,predict.values) print(rmse) end = time.clock() print(end-start) plot(Y_test1,predict,'LSTM') plt.show() ''' [5084.501732826233, 5019.245115280151, 0, 5781.067540168762, 4901.263449668884, 0, 3662.2705371379852, 3477.3887135982513, 3604.1994395256042, 3828.9382531642914, 4032.512934923172, 4200.44766497612, 0, 5500.914894104004, 5050.877872467041, 5098.942625999451, 5025.512603759766, 4833.0650424957275, 4640.630259275436, 0, 3671.070349931717, 3477.643422603607, 3604.097783088684, 3828.9450681209564, 4032.516626358032, 4200.447097063065, 0, 5500.914894104004, 5050.877872467041, 4920.514566421509, 5046.2789125442505, 4971.274635314941, 4627.1812262535095, 0, 3669.725247859955, 3477.582087993622, 3604.101758480072, 3828.9450681209564, 4032.5163424015045, 4200.447097063065, 0, 5500.914894104004, 5050.877872467041, 4920.514566421509, 4885.047260284424, 4937.634873390198, 4722.873724222183, 0, 3666.717580318451, 3477.3611698150635, 3604.0779061317444, 3828.9459199905396, 4032.51691031456, 4200.447381019592, 0, 5852.633671760559, 4982.125182151794, 4571.126219987869, 4490.589333772659, 4383.06578707695] 0.09977151293431874 398.3729562984607 '''
pd.date_range(start='2015-06-02', end='2015-07-31'), 'Sales': predict }) predict = predict.set_index('Date') rmspe = RMSPE(test.values, predict.values) print(rmspe) rmse = RMSE(test.values, predict.values) print(rmse) end = time.clock() print(end - start) plot(test, predict, 'ARIMA') plt.show() #0.15629390036574742 #683.436169886969 #153.88056277698684 #模型检验 ''' model = sm.tsa.ARIMA(train, order=(13, 1, 0)) results = model.fit() resid = results.resid #赋值 fig = plt.figure(figsize=(12,8)) fig = sm.graphics.tsa.plot_acf(resid.values.squeeze(), lags=80) plt.show() '''
if __name__ == '__main__': # create the data set X, Y, w = ds.mk_data(120) Y_nature = copy.deepcopy(Y) Y[Y<0] = 0 number = X.shape[1] # training part train = X[:,0:100].reshape(2,100) label = Y[:,0:100].reshape(1,100) a_new, z = model(train, label, 0.02) # testing part test = X[:,100:120].reshape(2,20) result = np.dot(a_new.T, np.append(test, np.ones((1,20)), axis = 0)) result[result > 0] = 1 result[result < 0] = 0 print('Accuracy: %d' % accuracy(result, Y[:, 100:120]) + "%") x = np.arange(-1.1, 1.1, .01) y = np.arange(-1.1, 1.1, .01) x, y = np.meshgrid(x, y) f = a_new[0] * x + a_new[1] * y + a_new[2] pl = ds.plot(X, Y_nature) pl.contour(x, y, f, 0, colors = 'black', linewidth = 0.001) pl.show()
#0.05 0.19104665873372706 #0.07 0.18185077499029648 alpha = 0.06 #data = [i for i in range(100)] data = train.values a,b,c = three_smooth(alpha,data) predict = [] for i in range(1,len(test)+1): data_ = a[-1] + b[-1]*i + c[-1]*(i**2) print(data_) predict.append(data_) open = X_test['Open'].values for i in range(len(open)): if open[i] == 0: predict[i] = 0 predict = pd.DataFrame({'Date': pd.date_range(start='2015-06-02', end='2015-07-31'), 'Sales': predict}) predict = predict.set_index('Date') rmspe = RMSPE(test.values, predict.values) print(rmspe) plot(test,predict,'Exponential Smoothing') plt.show() #0.17078593793136068