Pronóstico: Leer Datos
Pronóstico: Leer Datos
Pronóstico: Leer Datos
ipynb - Colaboratory
Pronóstico
import pandas as pd
import numpy as np
import seaborn as sns
from matplotlib import pyplot as plt
from fbprophet import Prophet
Leer Datos
df=pd.read_csv("./Datos4.csv")
df.head()
Fecha Datos
0 01-01-2021 6
1 02-01-2021 31
2 03-01-2021 4
3 04-01-2021 143
4 05-01-2021 137
p_train=0.8
train = df[:int((len(df))*p_train)]
test = df[int((len(df))*p_train):]
df_comp=train.copy()
df_comp.head()
https://colab.research.google.com/drive/1RH1BvQGwhJY1qzwwKWqhaVDfSpMsxkhb#scrollTo=ns2nesm5n9mS&printMode=true 1/5
1/8/2021 Untitled1.ipynb - Colaboratory
Fecha Datos
0 01-01-2021 6
1 02-01-2021 31
2 03-01-2021 4
3 04-01-2021 143
4 05-01-2021 137
df_comp.Fecha=pd.to_datetime(df_comp.Fecha, dayfirst= True)
df_comp.set_index("Fecha",inplace=True)
df_comp.head()
Datos
Fecha
2021-01-01 6
2021-01-02 31
2021-01-03 4
2021-01-04 143
2021-01-05 137
df.Datos.plot(figsize=(10,5))
plt.title("Datos", size=24)
plt.show()
!pip install pmdarima
https://colab.research.google.com/drive/1RH1BvQGwhJY1qzwwKWqhaVDfSpMsxkhb#scrollTo=ns2nesm5n9mS&printMode=true 2/5
1/8/2021 Untitled1.ipynb - Colaboratory
p p p
from pmdarima.arima import auto_arima
Collecting pmdarima
Uninstalling statsmodels-0.10.2:
[statsmodels]
You must restart the runtime in order to use newly installed versions.
RESTART RUNTIME
model_auto=auto_arima(df_comp.Datos, m=5,
max_order= None, max_p=7, max_q=7, max_d=2, max_P=4, max_Q=4, max_D=2,
maxiter=50, alpha=0.05, information_criterion='aic')
model_auto
with_intercept=True)
model_auto.summary()
https://colab.research.google.com/drive/1RH1BvQGwhJY1qzwwKWqhaVDfSpMsxkhb#scrollTo=ns2nesm5n9mS&printMode=true 3/5
1/8/2021 Untitled1.ipynb - Colaboratory
SARIMAX Results
Dep. Variable: y No. Observations: 167
Model: SARIMAX(0, 0, 1)x(0, 0, 1, 5) Log Likelihood -841.427
Date: Sun, 01 Aug 2021 AIC 1690.855
Time: 16:25:43 BIC 1703.327
Sample: 0 HQIC 1695.917
- 167
Covariance Type: opg
coef std err z P>|z| [0.025 0.975]
intercept 74.5716 1.797 41.499 0.000 71.050 78.094
ma.L1 0.2953 0.094 3.126 0.002 0.110 0.480
ma.S.L5 -0.5747 0.074 -7.756 0.000 -0.720 -0.429
sigma2 1375.4178 175.577 7.834 0.000 1031.293 1719.543
Ljung-Box (L1) (Q): 0.02 Jarque-Bera (JB): 5.70
Prob(Q): 0.89 Prob(JB): 0.06
Heteroskedasticity (H): 1.02
date=pd.to_datetime("06-17-2021") Skew: 0.44
date Prob(H) (two-sided): 0.93 Kurtosis: 3.21
Timestamp('2021-06-17 00:00:00')
Warnings:
[1] Covariance matrix calculated using the outer product of gradients (complex-step).
i_date=date+pd.to_timedelta(np.arange(10),'D')
i_date
'2021-06-25', '2021-06-26'],
dtype='datetime64[ns]', freq=None)
pronostico=model_auto.predict(len(i_date))
df_test=pd.Series(pronostico,index=i_date)
df_test.head()
2021-06-17 93.366008
2021-06-18 114.026628
2021-06-19 47.533056
2021-06-20 55.214624
2021-06-21 66.332862
dtype: float64
df_auto_pred=pd.DataFrame({'Pronosticos': pronostico},index=i_date)
df_auto_pred.plot(figsize=(10,5),color="red")
df_comp.Datos.plot(color="blue")
plt.title("Pronostico vs Real", size=24)
plt.show()
https://colab.research.google.com/drive/1RH1BvQGwhJY1qzwwKWqhaVDfSpMsxkhb#scrollTo=ns2nesm5n9mS&printMode=true 4/5
1/8/2021 Untitled1.ipynb - Colaboratory
https://colab.research.google.com/drive/1RH1BvQGwhJY1qzwwKWqhaVDfSpMsxkhb#scrollTo=ns2nesm5n9mS&printMode=true 5/5