-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNeural.py
More file actions
116 lines (76 loc) · 2.38 KB
/
Copy pathNeural.py
File metadata and controls
116 lines (76 loc) · 2.38 KB
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
'''
Created on 04/09/2017
@author: michaelnew
'''
# 3rd parties
import csv
import numpy as np
import sklearn
import matplotlib
import matplotlib.pyplot as plt
# Our Library
from Skyze_Indicators_Library.IndicatorAbstract import IndicatorAbstract
from Skyze_Standard_Library.ExceptionSkyzeAbstract import ExceptionSkyzeAbstract
prices = []
dates = []
def get_data(filename):
with open(filename,'r') as csvfile:
csvFileReader = csv.reader(csvfile)
next(csvFileReader)
for row in csvFileReader:
dates.append(int(row[0].split('-')[0]))
prices.append(float(row[1]))
return
class Neural(IndicatorAbstract,ExceptionSkyzeAbstract):
'''
classdocs
'''
# Static Variables
name = "Neural"
version = 1.0
def __init__(self
):
''' Constructor '''
# raise exceptionality
pass
def initial(self, p_data):
''' Calculate the first value if the calc is different to the subsequent calculations '''
return p_data
def calculate (self,
p_data # pd dataframe series
):
''' Calculations '''
p_data = self.initial(p_data)
#p_data["MA_"+str(self.ma_period)] = p_data[self.ma_column].rolling(window=self.ma_period).mean().shift(1)
#def predict_prices(dates,prices,x):
dates = ""
prices = ""
x = 29
dates = np.reshope(dates,(len(dates),1))
svr_lin = SVR(kernal='linear',C=1e3)
svr_poly = SVR(kernel='poly',C=1e3, degree=2)
svr_rbf = SVR(kernel='rbf', C=1e3, gamma=0.1)
svr_lin.fit(dates,prices)
svr_poly.fit(dates,prices)
svr_rbf.fit(dates,prices)
plt.scatter(dates,prices, color='black', label = 'Date')
plt.xlabel('Date')
plt.ylabel('Price')
plt.title('Support Vector Regression')
plt.show()
p_data["SVR_LIN"] = svr_lin.predict(x)[0]
p_data["SVR_POLY"] = svr_poly.predict(x)[0]
p_data["SVR_RBF"] = svr_rbf.predict(x)[0]
return p_data
def getResult (self):
''' Getter '''
return self.result
def getName(self):
''' Getter '''
return self.name
print("Hello")
plt.scatter(dates,prices, color='blac,', label = 'Date')
plt.xlabel('Date')
plt.ylabel('Price')
plt.title('Support Vector Regression')
plt.show()