-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinear_regression_test.py
51 lines (43 loc) · 1.87 KB
/
linear_regression_test.py
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
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from linearRegression.linearRegression import LinearRegression
from metrics import *
np.random.seed(42)
N = 30
P = 5
X = pd.DataFrame(np.random.randn(N, P))
y = pd.Series(np.random.randn(N))
print("------------------------------ Non-Vectorised Gradient Descent ------------------------------------")
for fit_intercept in [True, False]:
print("Bias is ", fit_intercept)
for l_type in ["constant", "inverse"]:
print("Learning rate is ", l_type)
LR = LinearRegression(fit_intercept=fit_intercept)
LR.fit_non_vectorised(X, y, lr_type=l_type) # here you can use fit_non_vectorised / fit_autograd methods
y_hat = LR.predict(X)
print('RMSE: ', rmse(y_hat, y))
print('MAE: ', mae(y_hat, y))
print()
print("---------------------------------- Vectorised Gradient Descent -----------------------")
for fit_intercept in [True, False]:
print("Bias is ", fit_intercept)
for l_type in ["constant", "inverse"]:
print("Learning rate is ", l_type)
LR = LinearRegression(fit_intercept=fit_intercept)
LR.fit_vectorised(X, y, lr_type=l_type) # here you can use fit_non_vectorised / fit_autograd methods
y_hat = LR.predict(X)
print('RMSE: ', rmse(y_hat, y))
print('MAE: ', mae(y_hat, y))
print()
print("-------------------------------------- Autograd Regression -----------------------------")
for fit_intercept in [True, False]:
print("Bias is",fit_intercept)
for l_type in ["constant", "inverse"]:
print("Learning rate is ", l_type)
LR = LinearRegression(fit_intercept=fit_intercept)
LR.fit_autograd(X, y, lr_type=l_type) # here you can use fit_non_vectorised / fit_autograd methods
y_hat = LR.predict(X)
print('RMSE: ', rmse(y_hat, y))
print('MAE: ', mae(y_hat, y))
print()