Jun-09-2020, 07:08 PM
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?
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?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
#!/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[ ]: |