5
5
6
6
class LinearRegression :
7
7
def __init__ (self , base_functions : list ):
8
- # TODO: init weights using np.random.randn (normal distribution with mean=0 and variance=1)
9
- self .weights = np .random .randn (len (base_functions ))
8
+ """init weights using np.random.randn (normal distribution with mean=0 and variance=1)"""
9
+ """we take one more weight, because we need column f0 = 1"""
10
+ self .weights = np .random .randn (len (base_functions ) + 1 )
10
11
self .base_functions = base_functions
11
12
12
13
@staticmethod
@@ -15,8 +16,12 @@ def __pseudoinverse_matrix(matrix: np.ndarray) -> np.ndarray:
15
16
pass
16
17
17
18
def __plan_matrix (self , inputs : np .ndarray ) -> np .ndarray :
18
- # TODO build Plan matrix using list of lambda functions defined in config. Use only one loop (for base_functions)
19
- return np .array ([function (inputs ) for function in lin_reg_cfg .base_functions ]).T
19
+ """build Plan matrix using list of lambda functions defined in config.
20
+ Use only one loop (for base_functions)""" """about f0 - we need column with only ones"""
21
+ matrix = [np .ones_like (inputs )]
22
+ for function in self .base_functions :
23
+ matrix = np .append (matrix , np .array ([function (inputs )]), 0 )
24
+ return matrix .T
20
25
21
26
def __calculate_weights (
22
27
self , pseudoinverse_plan_matrix : np .ndarray , targets : np .ndarray
@@ -25,7 +30,7 @@ def __calculate_weights(
25
30
pass
26
31
27
32
def calculate_model_prediction (self , plan_matrix ) -> np .ndarray :
28
- # TODO calculate prediction of the model (y) using formula from the lecture
33
+ """ calculate prediction of the model (y) using formula from the lecture"""
29
34
return np .dot (plan_matrix , self .weights .T )
30
35
31
36
def train_model (self , inputs : np .ndarray , targets : np .ndarray ) -> None :
0 commit comments