This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
path <- "path/to/data/winemag-data-130k-v2.csv" | |
winedata <- read_csv(file = path, col_names = TRUE) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tomar de datos originales dias 29-oct, 30-oct, y 31-oct | |
df_29_31 = df_mon_to_fri.loc['2018-10-29':'2018-10-31'] | |
df_29_31.plot() | |
# agregar bandas de confianza | |
pred_1_2_conf = results.get_forecast(steps=24*2).conf_int() | |
pred_1_2_conf.index = pd.date_range(start='11/1/2018', end='11/3/2018', freq='H')[:-1] | |
x = pd.date_range(start='11/1/2018', end='11/3/2018', freq='H')[:-1] | |
y1 = pred_1_2_conf['lower Bici'] | |
y2 = pred_1_2_conf['upper Bici'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from statsmodels.tsa.statespace.sarimax import SARIMAX # modelo SARIMA | |
from itertools import product # facilita ejecicion del ciclo for | |
# definiendo niveles del modelo | |
niveles = ['p', 'd', 'q', 'sp', 'sd', 'sq', 'AIC', 'BIC','log-like'] | |
resultados_modelos = pd.DataFrame(columns=niveles) | |
grados = [0,1,2] | |
# recorriendo todos los modelos posibles | |
for p, d, q, sp, sd, sq in product(grados, repeat=6): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from statsmodels.tsa.statespace.sarimax import SARIMAX | |
# definir conjunto de datos | |
x = df_mon_to_fri | |
# instanciar modelo | |
sarima_model = SARIMAX(x, order=(2,0,1), seasonal_order=(2, 1, 0, 24)) | |
# ajustar modelo | |
results = sarima_model.fit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# resample y agregacion por dia de mes | |
viajes_resample_day = viajes.Bici.resample('H').count() | |
# asignar día de la semana | |
df_resample = pd.concat([viajes_resample_day], axis=1) | |
df_resample['dayofweek'] = df_resample.index.dayofweek # 0 es lunes | |
# lunes a viernes | |
df_mon_to_fri = df_resample[df_resample.dayofweek.isin([0,1,2,3,4])].Bici |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# concatenar Hora_Retiro y Fecha_Retiro | |
viajes['fecha_hora_retiro'] = viajes.Fecha_Retiro + ' ' + viajes.Hora_Retiro | |
# cambiar de str a datetime | |
viajes['fecha_hora'] = viajes.fecha_hora_retiro \ | |
.map(lambda x : datetime.strptime(x, '%d/%m/%Y %H:%M:%S')) | |
# reindexar el dataframe | |
viajes.index = viajes.fecha_hora |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
viajes = pd.read_csv('2018-10.csv') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dia | hora | viajes | |
---|---|---|---|
0 | 0 | 38 | |
0 | 1 | 0 | |
0 | 2 | 0 | |
0 | 3 | 0 | |
0 | 4 | 0 | |
0 | 5 | 145 | |
0 | 6 | 627.5 | |
0 | 7 | 1757.25 | |
0 | 8 | 3181 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
print('hello world') | |
if True: | |
print('True!') |
NewerOlder