-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathglm_regression.py
More file actions
105 lines (89 loc) · 2.95 KB
/
glm_regression.py
File metadata and controls
105 lines (89 loc) · 2.95 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
import os
import numpy as np
import nnetsauce as ns
from sklearn.datasets import load_diabetes
from sklearn.model_selection import train_test_split
from time import time
import matplotlib.pyplot as plt
print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")
diabetes = load_diabetes()
X = diabetes.data
y = diabetes.target
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=2020)
print(f"\n Example 1 -----")
opt = ns.Optimizer(type_optim="sgd",
learning_rate=0.1,
batch_prop=0.25,
verbose=0)
obj = ns.GLMRegressor(n_hidden_features=3,
lambda1=1e-2, alpha1=0.5,
lambda2=1e-2, alpha2=0.5,
optimizer=opt)
start = time()
obj.fit(X_train, y_train)
print(f"\n Elapsed: {time() - start}")
plt.plot(obj.optimizer.results[2])
print(obj.beta_)
print("RMSE: ")
print(obj.score(X_test, y_test)) # RMSE
print(f"\n Example 2 -----")
opt2 = ns.Optimizer(type_optim="scd",
learning_rate=0.01,
batch_prop=0.8,
verbose=1)
obj2 = ns.GLMRegressor(n_hidden_features=5,
lambda1=1e-2, alpha1=0.5,
lambda2=1e-2, alpha2=0.5,
optimizer=opt2)
start = time()
obj2.fit(X_train, y_train)
print(f"\n Elapsed: {time() - start}")
plt.plot(obj2.optimizer.results[2])
print(obj2.beta_)
print("RMSE: ")
print(obj2.score(X_test, y_test)) # RMSE
print(f"\n Example 3 -----")
opt3 = ns.Optimizer(type_optim="scd",
batch_prop=0.25,
verbose=1)
obj3 = ns.GLMRegressor(n_hidden_features=5,
lambda1=1e-2, alpha1=0.1,
lambda2=1e-1, alpha2=0.9,
optimizer=opt3)
start = time()
obj3.fit(X_train, y_train)
print(f"\n Elapsed: {time() - start}")
plt.plot(obj3.optimizer.results[2])
print(obj3.beta_)
print("RMSE: ")
print(obj2.score(X_test, y_test)) # RMSE
print(f"\n Example 4 -----")
opt4 = ns.Optimizer(type_optim="scd",
learning_rate=0.01,
batch_prop=0.8,
verbose=0)
obj4 = ns.GLMRegressor(optimizer=opt4)
start = time()
obj4.fit(X_train, y_train)
print(f"\n Elapsed: {time() - start}")
plt.plot(obj4.optimizer.results[2])
print(obj4.beta_)
print("RMSE: ")
print(obj4.score(X_test, y_test)) # RMSE
print(f"\n Example 5 -----")
opt5 = ns.Optimizer(type_optim="scd",
learning_rate=0.1,
batch_prop=0.5,
verbose=0)
obj5 = ns.GLMRegressor(optimizer=opt5,
lambda1=1,
alpha1=0.5,
lambda2=1e-2,
alpha2=0.1)
start = time()
obj5.fit(X_train, y_train)
print(f"\n Elapsed: {time() - start}")
plt.plot(obj5.optimizer.results[2])
print(obj5.beta_)
print("RMSE: ")
print(obj5.score(X_test, y_test)) # RMSE