Vigneswaran S's Posts - Data Science Central2021-05-12T09:06:02ZVigneswaran Shttps://www.datasciencecentral.com/profile/VigneswaranShttps://storage.ning.com/topology/rest/1.0/file/get/2808682810?profile=original&width=48&height=48&crop=1%3A1https://www.datasciencecentral.com/profiles/blog/feed?user=0kfbavd6qisa0&xn_auth=noOverview on Forecasting Models in Power BItag:www.datasciencecentral.com,2020-07-19:6448529:BlogPost:9627742020-07-19T10:01:54.000ZVigneswaran Shttps://www.datasciencecentral.com/profile/VigneswaranS
<p>Time Series forecasting in PBI is based on the thumb technique of smoothening time series prediction called Exponential Smoothening (ES). ES of time series data assigns exponentially decreasing weights for newest to oldest observations. ES is also be used for time series with trend and seasonality. This model is usually used to make short term forecasts, as longer-term forecasts using this technique can be quite unreliable. Collectively, the methods are sometimes referred to as ETS models,…</p>
<p>Time Series forecasting in PBI is based on the thumb technique of smoothening time series prediction called Exponential Smoothening (ES). ES of time series data assigns exponentially decreasing weights for newest to oldest observations. ES is also be used for time series with trend and seasonality. This model is usually used to make short term forecasts, as longer-term forecasts using this technique can be quite unreliable. Collectively, the methods are sometimes referred to as ETS models, referring to explicit modeling for errors, Trend and Seasonality.</p>
<p><strong>Types of Exponential Smoothening models in PBI </strong></p>
<ul>
<li>Simple exponential smoothening : - uses a weighted moving average with exponentially decreasing weights</li>
<li>Holt’s trend-corrected double exponential smoothening :- usually more reliable for handling data that shows trends, compared to the single procedure</li>
<li>Triple exponential smoothening :- usually more reliable for parabolic trends or data that shows trends and seasonality</li>
</ul>
<p><strong> </strong></p>
<p><strong>Handling the missing values</strong></p>
<p>In some cases, your timeline might be missing some historical values. Does this pose a problem?</p>
<p>Not usually – the forecasting chart can automatically fill in some values to provide a forecast. If the total number of missing values is less than 40% of the total number of data points, the algorithm will perform linear interpolation prior to performing the forecast.</p>
<p>If more than 40% of your values are missing, try to fill in more data, or perhaps aggregate values into larger time units, to ensure that a more complete data series is available for analysis.<br/><br/>Reference Code ::-<br/><br/></p>
<p>import requests<br/>import pandas as pd<br/>import json<br/>import matplotlib.pyplot as plt<br/>import matplotlib.dates as mdates<br/>from statsmodels.tsa.holtwinters import SimpleExpSmoothing, Holt<br/>import numpy as np<br/>%matplotlib inline<br/>plt.style.use('Solarize_Light2')</p>
<p>r = requests.get('https://datamarket.com/api/v1/list.json?ds=22qx')<br/>jobj = json.loads(r.text[18:-1])<br/>data = jobj[0]['data']<br/>df = pd.DataFrame(data, columns=['time','data']).set_index('time')<br/>train = df.iloc[100:-10, :]<br/>test = df.iloc[-10:, :]<br/>train.index = pd.to_datetime(train.index)<br/>test.index = pd.to_datetime(test.index)<br/>pred = test.copy()</p>
<p>model = SimpleExpSmoothing(np.asarray(train['data']))<br/>model._index = pd.to_datetime(train.index)</p>
<p>fit1 = model.fit()<br/>pred1 = fit1.forecast(9)<br/>fit2 = model.fit(smoothing_level=.2)<br/>pred2 = fit2.forecast(9)<br/>fit3 = model.fit(smoothing_level=.5)<br/>pred3 = fit3.forecast(9)</p>
<p>fig, ax = plt.subplots(figsize=(12, 6))<br/>ax.plot(train.index[150:], train.values[150:])<br/>ax.plot(test.index, test.values, color="gray")<br/>for p, f, c in zip((pred1, pred2, pred3),(fit1, fit2, fit3),('#ff7823','#3c763d','c')):<br/> ax.plot(train.index[150:], f.fittedvalues[150:], color=c)<br/> ax.plot(test.index, p, label="alpha="+str(f.params['smoothing_level'])[:3], color=c)<br/>plt.title("Simple Exponential Smoothing") <br/>plt.legend();<br/> <br/>model = Holt(np.asarray(train['data']))<br/>model._index = pd.to_datetime(train.index)</p>
<p>fit1 = model.fit(smoothing_level=.3, smoothing_slope=.05)<br/>pred1 = fit1.forecast(9)<br/>fit2 = model.fit(optimized=True)<br/>pred2 = fit2.forecast(9)<br/>fit3 = model.fit(smoothing_level=.3, smoothing_slope=.2)<br/>pred3 = fit3.forecast(9)</p>
<p>fig, ax = plt.subplots(figsize=(12, 6))<br/>ax.plot(train.index[150:], train.values[150:])<br/>ax.plot(test.index, test.values, color="gray")<br/>for p, f, c in zip((pred1, pred2, pred3),(fit1, fit2, fit3),('#ff7823','#3c763d','c')):<br/> ax.plot(train.index[150:], f.fittedvalues[150:], color=c)<br/> ax.plot(test.index, p, label="alpha="+str(f.params['smoothing_level'])[:4]+", beta="+str(f.params['smoothing_slope'])[:4], color=c)<br/>plt.title("Holt's Exponential Smoothing")<br/>plt.legend();</p>
<p> </p>
<p><strong>Evaluating the Forecast</strong></p>
<p>Hindcasting and adjusting confidence intervals are two good ways to evaluate the quality of the forecast.</p>
<p>Hindcast is one way to verify whether the model is doing a good job If the observed value doesn’t exactly match the predicted value, it does not mean the forecast is all wrong – instead, consider both the amount of variation and the direction of the trend line. Predictions are a matter of probability and estimation, so if the predicted value is close to but not exactly the same as the real value, it could be a better indicator of prediction quality than if the value exactly matched the real result. In general, when a model too closely mirrors the values and trends within the input dataset, it might be overfitted, meaning it likely won’t provide good predictions on new data.</p>
<p>You are the best judge of how reliable the input data is, and what the real range of possible predictions might be.</p>