11from activities .stock_prediction .stock_prediction import FrankfurtStockPrediction
22import numpy as np
3+ from keras import Sequential
4+ from keras .layers import Dense , Activation
5+ from random import randint
36
47
58class RandomRangePredictor (FrankfurtStockPrediction .Model ):
@@ -18,4 +21,88 @@ def predict(self, x):
1821
1922 @staticmethod
2023 def description ():
21- return '''Predicts within a range range, which is updated base on y data.'''
24+ return '''Predicts within a random range. The max and min of the range are updated based on y data.'''
25+
26+
27+ class MeanPredictor (FrankfurtStockPrediction .Model ):
28+
29+ def __init__ (self , activity ):
30+ super ().__init__ (activity )
31+
32+ def train (self , x , y ):
33+ pass
34+
35+ def predict (self , x ):
36+ return np .full (shape = (self .y_shape [0 ], x .shape [1 ]), fill_value = np .mean (x ))
37+
38+ @staticmethod
39+ def description ():
40+ return '''Predicts that every stock will have the same mean price overall.'''
41+
42+
43+ class MeanRowPredictor (FrankfurtStockPrediction .Model ):
44+
45+ def __init__ (self , activity ):
46+ super ().__init__ (activity )
47+
48+ def train (self , x , y ):
49+ pass
50+
51+ def predict (self , x ):
52+ n_y_cols = self .y_shape [1 ]
53+ prediction = np .empty (shape = self .y_shape )
54+ for row_i in range (x .shape [0 ]):
55+ row_mean = np .mean (x [row_i , :])
56+ prediction [:, row_i ] = [row_mean ] * n_y_cols
57+ return prediction
58+
59+ @staticmethod
60+ def description ():
61+ return '''Predicts that every stock will have the same mean price at every time interval.'''
62+
63+
64+ class ShallowNeuralNetworkPredictor (FrankfurtStockPrediction .Model ):
65+
66+ def __init__ (self , activity ):
67+ super ().__init__ (activity )
68+ self .neural_network = Sequential ([
69+ Dense (32 , input_shape = (self .x_shape [1 ],)),
70+ Dense (self .y_shape [1 ])
71+ ])
72+ self .neural_network .compile (
73+ optimizer = 'nadam' ,
74+ loss = 'mse'
75+ )
76+
77+ def train (self , x , y ):
78+ self .neural_network .fit (x = x , y = y )
79+
80+ def predict (self , x ):
81+ return self .neural_network .predict (x )
82+
83+ @staticmethod
84+ def description ():
85+ return '''Uses a shallow, wide neural network.'''
86+
87+
88+ class RandomDepthNeuralNetworkPredictor (FrankfurtStockPrediction .Model ):
89+
90+ def __init__ (self , activity ):
91+ super ().__init__ (activity )
92+ self .neural_network = Sequential ([Dense (8 , input_shape = (self .x_shape [1 ],))] +
93+ [Dense (8 ) for _ in range (randint (0 , 8 ))] +
94+ [Dense (self .y_shape [1 ])])
95+ self .neural_network .compile (
96+ optimizer = 'nadam' ,
97+ loss = 'mse'
98+ )
99+
100+ def train (self , x , y ):
101+ self .neural_network .fit (x = x , y = y )
102+
103+ def predict (self , x ):
104+ return self .neural_network .predict (x )
105+
106+ @staticmethod
107+ def description ():
108+ return '''Creates a neural network of depth from 2-10.'''
0 commit comments