-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgenboost_regressor.py
More file actions
79 lines (64 loc) · 2.45 KB
/
genboost_regressor.py
File metadata and controls
79 lines (64 loc) · 2.45 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
import subprocess
import sys
import os
print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")
import mlsauce as ms
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import load_diabetes, fetch_california_housing
from sklearn.linear_model import Ridge, LinearRegression
from sklearn.model_selection import train_test_split, GridSearchCV, cross_val_score
from sklearn.tree import DecisionTreeRegressor
from time import time
from os import chdir
from sklearn import metrics
print("\n")
print("diabetes data -----")
regr = LinearRegression()
diabetes = load_diabetes()
X = diabetes.data
y = diabetes.target
# split data into training test and test set
np.random.seed(15029)
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.2)
print("\n Example 1 --------------------------- \n")
obj = ms.GenericBoostingRegressor(regr, col_sample=0.9, row_sample=0.9)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(time()-start)
start = time()
print(np.sqrt(np.mean(np.square(obj.predict(X_test) - y_test))))
print(time()-start)
print(obj.obj['loss'])
print("\n Example 2 --------------------------- \n")
obj = ms.GenericBoostingRegressor(regr, col_sample=0.9, row_sample=0.9, n_clusters=2)
print(obj.get_params())
start = time()
obj.fit(X_train, y_train)
print(time()-start)
start = time()
print(np.sqrt(np.mean(np.square(obj.predict(X_test) - y_test))))
print(time()-start)
print(obj.obj['loss'])
print(obj.obj['fit_obj_i'])
print("\n Example 3 --------------------------- \n")
housing = fetch_california_housing()
n_samples = 500
X = housing.data[:n_samples]
y = housing.target[:n_samples]
# split data into training test and test set
np.random.seed(15029)
X_train, X_test, y_train, y_test = train_test_split(X, y,
test_size=0.2)
obj = ms.GenericBoostingRegressor(regr, n_hidden_features=2, n_estimators=10)
obj.fit(X_train, y_train)
print(f"obj.obj['fit_obj_i'][0]: {obj.obj['fit_obj_i'][0].coef_}")
print(f"score: {np.sqrt(np.mean(np.square(obj.predict(X_test[3:10,:]) - y_test[3:10])))}")
obj = obj.update(X_test[0,:], y_test[0])
obj = obj.update(X_test[1,:], y_test[1])
obj = obj.update(X_test[2,:], y_test[2])
print(f"obj.obj['fit_obj_i'][0]: {obj.obj['fit_obj_i'][0].coef_}")
print(f"preds: {obj.predict(X_test[3:10,:])}")
print(f"score: {np.sqrt(np.mean(np.square(obj.predict(X_test[3:10,:]) - y_test[3:10])))}")