Commit f7b2142b authored by Douglas's avatar Douglas

initial commit

parents
date;quantity
2015/05/01 00:00:00 UTC;3.0
2015/05/02 00:00:00 UTC;60.0
2015/05/03 00:00:00 UTC;59.962507811848994
2015/05/04 00:00:00 UTC;59.85012495834077
2015/05/05 00:00:00 UTC;59.663132338081276
2015/05/06 00:00:00 UTC;59.40199733523725
2015/05/07 00:00:00 UTC;59.06737265131934
2015/05/08 00:00:00 UTC;58.66009467376818
2015/05/09 00:00:00 UTC;58.181181385421375
2015/05/10 00:00:00 UTC;57.63182982008656
2015/05/11 00:00:00 UTC;57.013413070580306
2015/05/12 00:00:00 UTC;56.327476856711186
2015/05/13 00:00:00 UTC;55.575735661785174
2015/05/14 00:00:00 UTC;54.760068447290344
2015/05/15 00:00:00 UTC;53.88251395647168
2015/05/16 00:00:00 UTC;52.945265618534656
2015/05/17 00:00:00 UTC;51.95066606621463
2015/05/18 00:00:00 UTC;50.90120128041495
2015/05/19 00:00:00 UTC;49.799494376549475
2015/05/20 00:00:00 UTC;48.64829904811994
2015/05/21 00:00:00 UTC;47.45049268391651
2015/05/22 00:00:00 UTC;46.209069176044196
2015/05/23 00:00:00 UTC;44.92713143675181
2015/05/24 00:00:00 UTC;43.60788364276732
2015/05/25 00:00:00 UTC;42.25462322652473
2015/05/26 00:00:00 UTC;40.87073263430021
2015/05/27 00:00:00 UTC;39.45967087185806
2015/05/28 00:00:00 UTC;38.02496485873762
2015/05/29 00:00:00 UTC;36.57020061279124
2015/05/30 00:00:00 UTC;35.09901428700723
2015/05/31 00:00:00 UTC;33.615083081021
2015/06/01 00:00:00 UTC;32.12211605003108
2015/06/02 00:00:00 UTC;30.623844834092772
2015/06/03 00:00:00 UTC;29.124014330961337
2015/06/04 00:00:00 UTC;27.626373335797986
2015/06/05 00:00:00 UTC;26.13466517113426
2015/06/06 00:00:00 UTC;24.65261833051524
2015/06/07 00:00:00 UTC;23.18393715920739
2015/06/08 00:00:00 UTC;21.73229259526461
2015/06/09 00:00:00 UTC;20.301312994094896
2015/06/10 00:00:00 UTC;18.894575059461395
2015/06/11 00:00:00 UTC;17.51559490358573
2015/06/12 00:00:00 UTC;16.167819258698618
2015/06/13 00:00:00 UTC;14.854616862004274
2015/06/14 00:00:00 UTC;13.579270035591872
2015/06/15 00:00:00 UTC;12.344966482339625
2015/06/16 00:00:00 UTC;11.154791318317827
2015/06/17 00:00:00 UTC;10.011719361605277
2015/06/18 00:00:00 UTC;8.91860769679338
2015/06/19 00:00:00 UTC;7.878188533762637
2015/06/20 00:00:00 UTC;6.893062378580777
2015/06/21 00:00:00 UTC;5.965691533591989
2015/06/22 00:00:00 UTC;5.098393942943337
2015/06/23 00:00:00 UTC;4.29333739893158
2015/06/24 00:00:00 UTC;3.552534123651423
2015/06/25 00:00:00 UTC;2.8778357394881637
2015/06/26 00:00:00 UTC;2.270928641026093
2015/06/27 00:00:00 UTC;1.733329779940258
2015/06/28 00:00:00 UTC;1.266382873407289
2015/06/29 00:00:00 UTC;0.8712550455122836
2015/06/30 00:00:00 UTC;0.5489339100463764
2015/07/01 00:00:00 UTC;0.30022510198663754
2015/07/02 00:00:00 UTC;0.1257502638281638
2015/07/03 00:00:00 UTC;0.02594549180161554
2015/07/04 00:00:00 UTC;0.0010602458597408493
2015/07/05 00:00:00 UTC;0.05115672615740641
2015/07/06 00:00:00 UTC;0.17610971758361238
2015/07/07 00:00:00 UTC;0.3756069027340536
2015/07/08 00:00:00 UTC;0.6491496425419763
2015/07/09 00:00:00 UTC;0.9960542226161673
2015/07/10 00:00:00 UTC;1.4154535621708586
2015/07/11 00:00:00 UTC;1.9062993812761098
2015/07/12 00:00:00 UTC;2.4673648210117216
2015/07/13 00:00:00 UTC;3.09724750997559
2015/07/14 00:00:00 UTC;3.7943730694818623
2015/07/15 00:00:00 UTC;4.556999048687759
2015/07/16 00:00:00 UTC;5.3832192798131775
2015/07/17 00:00:00 UTC;6.270968642567494
2015/07/18 00:00:00 UTC;7.218028225874765
2015/07/19 00:00:00 UTC;8.222030873995793
2015/07/20 00:00:00 UTC;9.280467103184773
2015/07/21 00:00:00 UTC;10.390691374091642
2015/07/22 00:00:00 UTC;11.549928704232768
2015/07/23 00:00:00 UTC;12.755281604001926
2015/07/24 00:00:00 UTC;14.00373731888537
2015/07/25 00:00:00 UTC;15.292175359779018
2015/07/26 00:00:00 UTC;16.61737530258622
2015/07/27 00:00:00 UTC;17.976024837600736
2015/07/28 00:00:00 UTC;19.364728048556042
2015/07/29 00:00:00 UTC;20.78001390064742
2015/07/30 00:00:00 UTC;22.218344916311217
2015/07/31 00:00:00 UTC;23.676126017076612
2015/08/01 00:00:00 UTC;25.149713509389404
2015/08/02 00:00:00 UTC;26.635424191948353
2015/08/03 00:00:00 UTC;28.129544561790254
2015/08/04 00:00:00 UTC;29.62834009611328
2015/08/05 00:00:00 UTC;31.128064586639297
2015/08/06 00:00:00 UTC;32.624969503183394
2015/08/07 00:00:00 UTC;34.11531336302722
2015/08/08 00:00:00 UTC;35.59537108267727
2015/08/09 00:00:00 UTC;37.061443288633534
\ No newline at end of file
# coding: utf-8
# In[130]:
get_ipython().magic(u'matplotlib inline')
import csv
import requests
import ggplot
import matplotlib
matplotlib.use('agg')
matplotlib.style.use('ggplot')
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import statsmodels as sm
from sklearn import linear_model
from sklearn.gaussian_process import regression_models
from StringIO import StringIO
# need ssh tunnel to use this url
url = 'http://localhost:2200/erp5/portal_skins/erp5_r_order_prediction_tutorial/SaleOrderModule_getArimaPredictionList'
response = requests.get(url, auth=('zope', 'password'))
csv_file = StringIO()
csv_file.write(response.text)
csv_file.seek(0)
ts = pd.read_csv(csv_file, sep=';',
parse_dates=[0],
infer_datetime_format=True,
squeeze=True,
index_col='date')
X = (ts.index - ts.index[0]).days.reshape(-1, 1)
y = ts.values
X_train = X[:]
X_test = X[20:]
y_train = y[:]
y_test = y[20:]
# Linear Regression
lr = linear_model.LinearRegression(normalize=True)
lr.fit(X_train, y_train)
print lr.score(X_test, y_test)
plt.scatter(X_test, y_test, color='black')
plt.plot(X_test, lr.predict(X_test), color='blue', linewidth=3)
# ElasticNet Regression
mtl = linear_model.ElasticNet(alpha=0.1, normalize=True)
mtl.fit(X_train, y_train)
plt.plot(X_test, mtl.predict(X_test), color='green', linewidth=2)
# SGD Regression
sgd = linear_model.SGDRegressor(shuffle=False, eta0=0.25)
sgd.fit(X_train, y_train)
plt.plot(X_test, sgd.predict(X_test), color='red', linewidth=1)
plt.xticks()
plt.yticks()
plt.show()
\ No newline at end of file
# coding: utf-8
# # Basic setup and data (with plot)
# In[1]:
get_ipython().magic(u'matplotlib inline')
import csv
import requests
import ggplot
import matplotlib
matplotlib.use('agg')
matplotlib.style.use('ggplot')
import pandas as pd
import matplotlib.pyplot as plt
import statsmodels.api as sm
import numpy as np
from statsmodels.tsa.arima_process import ArmaProcess
from StringIO import StringIO
# need ssh tunnel to use this url
url = 'http://zope:runescape@localhost:2200/erp5/portal_skins/erp5_r_order_prediction_tutorial/SaleOrderModule_getArimaPredictionList'
response = requests.get(url, auth=('zope', 'runescape'))
csv_file = StringIO()
csv_file.write(response.text)
csv_file.seek(0)
ts = pd.read_csv(csv_file, sep=';',
parse_dates=[0],
infer_datetime_format=True,
squeeze=True,
index_col='date')
ts.plot()
# # Graphics to analyze auto correlation and partial auto correlation
# In[2]:
fig = plt.figure(figsize=(12, 8))
ax1 = fig.add_subplot(211)
fig = sm.graphics.tsa.plot_acf(ts, lags=30, ax=ax1)
ax2 = fig.add_subplot(212)
fig = sm.graphics.tsa.plot_pacf(ts, lags=30, ax=ax2)
# Looks like partial correlation going to 0 after lag 3. So **ARMA(3,0)** might be an adequated model for out data.
# # Minimum order selection for ARMA
# In[28]:
answers = [sm.tsa.arma_order_select_ic(ts, ic=['aic'], trend=trend, fit_kw={'method': 'css'}) for trend in ['c', 'nc']]
for answer in answers:
print answer['aic_min_order']
# # Check if series is stationary
# Using the Augmented Dicker-Fuller test we can check if out data is stationary. For this, we need to get an **adf statistic** value __smaller__ (more negative) than the critical value at 5% for regression **c**, **ct** and **nc**.
# In[15]:
def check_stationarity(series, regression='c'):
regressions = {
'c': 'constant only',
'ct': 'constant and trend',
'ctt': 'constant, linear and quadratic trend',
'nc': 'no constant, no trend'
}
result = sm.tsa.adfuller(series, regression=regression, autolag='t-stat', store=True)
store = result[-1]
if store.adfstat > result[2]['5%']:
print 'Time series is not stationary with %s. See data below:' % regressions[regression]
print ' - adf statistics: ', store.adfstat
print ' - p-value: ', result[1]
print ' - critical values: ', store.critvalues
return False
else:
print 'Time series is stationary with regression %s! :D\n' % regressions[regression]
return True
stationarity_tests = [check_stationarity(ts, regression) for regression in ['c', 'ct', 'ctt', 'nc']]
diff_ts = ts.diff()
diff_ts.plot()
# # Fit the ARIMA model and plot the data + forecast
# In[32]:
arima = sm.tsa.ARIMA(ts, (3,0,0))
arima_fit = arima.fit()
arima_fit.resid.plot()
fig, ax = plt.subplots()
ax = ts.plot(ax=ax)
fig = arima_fit.plot_predict(100, 200, dynamic=True, ax=ax)
plt.show()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment