Skip to content

Instantly share code, notes, and snippets.

View Vishnunkumar's full-sized avatar
😉
Exploring Dev

Vishnu Nandakumar Vishnunkumar

😉
Exploring Dev
View GitHub Profile
@Vishnunkumar
Vishnunkumar / bubble_chart_ict.html
Created November 28, 2020 11:24
plotly_bubble_chart_ict values of premier league players
This file has been truncated, but you can view the full file.
<html>
<head><meta charset="utf-8" /></head>
<body>
<div> <script type="text/javascript">window.PlotlyConfig = {MathJaxConfig: 'local'};</script>
<script type="text/javascript">/**
* plotly.js v1.56.0
* Copyright 2012-2020, Plotly, Inc.
* All rights reserved.
* Licensed under the MIT license
*/
df_es = df_test.copy()
df_es['preds'] = 0
p = len(df_test)
model = ExponentialSmoothing(np.asarray(df_train['Page.Loads']),seasonal_periods=365, seasonal='add', trend='add')
model_fit = model.fit()
preds = model_fit.forecast(p)
df_es['preds'] = preds
@Vishnunkumar
Vishnunkumar / rolling_forecast.py
Created November 27, 2020 07:37
Rolling training and forecast function
def rolling_forecast_es(df, df_test, p):
"""
Does rolling training and forecast for one week at a time
"""
df_test['preds'] = 0
for k in range(0, int(len(df_test)/p)):
model = ExponentialSmoothing(np.asarray(df['Page.Loads'].iloc[:ix2 + (k)*p]),seasonal_periods=365, seasonal='add', trend='add')
model_fit = model.fit()
preds = model_fit.forecast(p)
@Vishnunkumar
Vishnunkumar / main_es.py
Created November 27, 2020 07:26
Time series forecasting using Exponential smoothing
from statsmodels.tsa.api import ExponentialSmoothing seasonal_decompose
import statsmodels
import pandas as pd
import numpy as np
import datetime
from sklearn import metrics
def preprocess(df):
"""
Preprocess the dataframe to required timeseries format