Python Forum
Predicting/Forecasting Future Values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Predicting/Forecasting Future Values
#1
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[ ]:
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Demand Forecasting using Arima LukasBen123 6 1,167 Jul-21-2023, 11:58 PM
Last Post: Pedroski55
  Forecasting with ARIMAX Scott 0 1,903 Jan-14-2022, 08:41 PM
Last Post: Scott
  Substation Load Forecasting BadWhite 1 1,976 May-22-2020, 01:02 AM
Last Post: jefsummers
  Predicting an output variable with sklearn Ccross1 1 2,484 Jun-04-2019, 03:11 PM
Last Post: michalmonday
  predicting values at point in time mk1216 1 1,839 May-07-2019, 03:25 PM
Last Post: mk1216
  future warning when using numpy fancy indexing bluefrog 0 4,245 Nov-20-2018, 09:44 AM
Last Post: bluefrog

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020