Python Forum

Full Version: Predicting/Forecasting Future Values
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey Guys,

I'm dealing too much with forecasting in my work.So, I made some code that will predict for me the load in my area. The good news is that I have tested the code using the SVR and results were amazing. Now, the question is how to predict the values for next week after this successful test?


#!/usr/bin/env python
# coding: utf-8

# In[1]:


#Import the libraries
from sklearn.svm import SVR
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
plt.style.use('seaborn-darkgrid')


# In[2]:


df = pd.read_csv('EOA 06-06-2020 - Copy.csv')


# In[3]:


df.shape


# In[4]:


df


# In[5]:


actual_load = df.tail(1)
actual_load


# In[6]:


df = df.head(len(df)-1)
df


# In[7]:


#Create the lists / X and y data set
time = list()
Actual_a = list()


# In[8]:


df_days = df.loc[:, 'Time']
df_adj_close = df.loc[:, 'Actual']


# In[9]:


#Create the independent data set
for day in df_days:
   time.append( [int(day.split(':')[1])] )
#Create the dependent data set
for actual in df_adj_close:
   Actual_a.append(actual)


# In[10]:


print(Actual_a)


# In[11]:


#Create and train an SVR model using a linear kernel
lin_svr = SVR(kernel='linear', C=1000.0)
lin_svr.fit(time,Actual_a)#Create and train an SVR model using a polynomial kernel
poly_svr = SVR(kernel='poly', C=1000.0, degree=2)
poly_svr.fit(time, Actual_a)#Create and train an SVR model using a RBF kernel
rbf_svr = SVR(kernel='rbf', C=1000.0, gamma=0.15)
rbf_svr.fit(time, Actual_a)


# In[12]:


#Plot the models on a graph to see which has the best fit
plt.figure(figsize=(16,8))
plt.scatter(time, Actual_a, color = 'black', label='Original Data')
plt.plot(time, rbf_svr.predict(time), color = 'green', label='RBF Model')
plt.plot(time, poly_svr.predict(time), color = 'orange', label='Polynomial Model')
plt.plot(time, lin_svr.predict(time), color = 'purple', label='Linear Model')
plt.xlabel('Time')
plt.ylabel('Actual')
plt.title('Support Vector Regression')
plt.legend()
plt.show()


# In[13]:


day = [[30]]
print('The RBF SVR predicted:', rbf_svr.predict(day))
print('The Linear SVR predicted:', lin_svr.predict(day))
print('The Polynomial SVR predicted:', poly_svr.predict(day))


# In[ ]:
I assume that you are working on timeseries data since you want to predict for next week.There are two ways of doing this,one being training your model such that it predicts the next 7 days instead of just one day.The other being using models such as ARIMA,SARIMA which can easily help you predict for next week or month.