Skip to content

Commit e454328

Browse files
Merge pull request #35 from Techtonique/lsboost-lilbro
Lsboost lilbro
2 parents 9817a17 + ce70678 commit e454328

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+18786
-9627
lines changed

Makefile

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ clean-build: ## remove build artifacts
3232
rm -fr build/
3333
rm -fr .eggs/
3434
find . -name '*.egg-info' -exec rm -fr {} +
35-
find . -name '*.egg' -exec rm -f {} +
35+
find . -name '*.egg' -exec rm -f {} +
36+
find . -name '*.so' -exec rm -f {} +
37+
find . -name '*.c' -exec rm -f {} +
3638

3739
clean-pyc: ## remove Python file artifacts
3840
find . -name '*.pyc' -exec rm -f {} +
@@ -89,7 +91,10 @@ dist: clean ## builds source and wheel package
8991
ls -l dist
9092

9193
install: clean ## install the package to the active Python's site-packages
92-
python3 -m pip install .
94+
python3 -m pip install . --verbose
9395

9496
run-examples: ## run all examples with one command
95-
find examples -maxdepth 2 -name "*.py" -exec python3 {} \;
97+
find examples -maxdepth 2 -name "*.py" -exec python3 {} \;
98+
99+
run-lazy: ## run all lazy estimators examples with one command
100+
find examples -maxdepth 2 -name "*lazy*.py" -exec python3 {} \;

examples/genboost_classifier.py

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
import numpy as np
2+
from sklearn.datasets import load_digits, load_breast_cancer, load_wine, load_iris
3+
from sklearn.model_selection import train_test_split, GridSearchCV, cross_val_score
4+
from sklearn.tree import DecisionTreeRegressor
5+
from sklearn.kernel_ridge import KernelRidge
6+
from time import time
7+
from os import chdir
8+
from sklearn import metrics
9+
import os
10+
11+
print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")
12+
13+
print(os.path.relpath(os.path.dirname(__file__)))
14+
15+
#wd="/workspace/mlsauce/mlsauce/examples"
16+
#
17+
#chdir(wd)
18+
19+
import mlsauce as ms
20+
21+
#ridge
22+
23+
print("\n")
24+
print("GenericBoosting Decision tree -----")
25+
print("\n")
26+
27+
print("\n")
28+
print("breast_cancer data -----")
29+
30+
# data 1
31+
breast_cancer = load_breast_cancer()
32+
X = breast_cancer.data
33+
y = breast_cancer.target
34+
# split data into training test and test set
35+
np.random.seed(15029)
36+
X_train, X_test, y_train, y_test = train_test_split(X, y,
37+
test_size=0.2)
38+
39+
clf = DecisionTreeRegressor()
40+
clf2 = KernelRidge()
41+
42+
obj = ms.GenericBoostingClassifier(clf, tolerance=1e-2)
43+
print(obj.get_params())
44+
start = time()
45+
obj.fit(X_train, y_train)
46+
print(time()-start)
47+
start = time()
48+
print(obj.score(X_test, y_test))
49+
print(time()-start)
50+
51+
print(obj.obj['loss'])
52+
53+
obj = ms.GenericBoostingClassifier(clf, tolerance=1e-2, n_clusters=2)
54+
print(obj.get_params())
55+
start = time()
56+
obj.fit(X_train, y_train)
57+
print(time()-start)
58+
start = time()
59+
print(obj.score(X_test, y_test))
60+
print(time()-start)
61+
62+
print(obj.obj['loss'])
63+
64+
65+
# data 2
66+
print("\n")
67+
print("wine data -----")
68+
69+
wine = load_wine()
70+
Z = wine.data
71+
t = wine.target
72+
np.random.seed(879423)
73+
X_train, X_test, y_train, y_test = train_test_split(Z, t,
74+
test_size=0.2)
75+
76+
obj = ms.GenericBoostingClassifier(clf)
77+
print(obj.get_params())
78+
start = time()
79+
obj.fit(X_train, y_train)
80+
print(time()-start)
81+
start = time()
82+
print(obj.score(X_test, y_test))
83+
print(time()-start)
84+
85+
print(obj.obj['loss'])
86+
87+
obj = ms.GenericBoostingClassifier(clf, n_clusters=3)
88+
print(obj.get_params())
89+
start = time()
90+
obj.fit(X_train, y_train)
91+
print(time()-start)
92+
start = time()
93+
print(obj.score(X_test, y_test))
94+
print(time()-start)
95+
96+
print(obj.obj['loss'])
97+
98+
# data 3
99+
print("\n")
100+
print("iris data -----")
101+
102+
iris = load_iris()
103+
Z = iris.data
104+
t = iris.target
105+
np.random.seed(734563)
106+
X_train, X_test, y_train, y_test = train_test_split(Z, t,
107+
test_size=0.2)
108+
109+
110+
obj = ms.GenericBoostingClassifier(clf)
111+
print(obj.get_params())
112+
start = time()
113+
obj.fit(X_train, y_train)
114+
print(time()-start)
115+
start = time()
116+
print(obj.score(X_test, y_test))
117+
print(time()-start)
118+
119+
print(obj.obj['loss'])
120+
121+
122+
print("\n")
123+
print("GenericBoosting KRR -----")
124+
print("\n")
125+
126+
obj = ms.GenericBoostingClassifier(clf2, tolerance=1e-2)
127+
print(obj.get_params())
128+
start = time()
129+
obj.fit(X_train, y_train)
130+
print(time()-start)
131+
start = time()
132+
print(obj.score(X_test, y_test))
133+
print(time()-start)
134+
135+
print(obj.obj['loss'])
136+
137+
obj = ms.GenericBoostingClassifier(clf2, tolerance=1e-2, n_clusters=2)
138+
print(obj.get_params())
139+
start = time()
140+
obj.fit(X_train, y_train)
141+
print(time()-start)
142+
start = time()
143+
print(obj.score(X_test, y_test))
144+
print(time()-start)
145+
146+
print(obj.obj['loss'])
147+
148+
149+
# data 2
150+
print("\n")
151+
print("wine data -----")
152+
153+
wine = load_wine()
154+
Z = wine.data
155+
t = wine.target
156+
np.random.seed(879423)
157+
X_train, X_test, y_train, y_test = train_test_split(Z, t,
158+
test_size=0.2)
159+
160+
obj = ms.GenericBoostingClassifier(clf2)
161+
print(obj.get_params())
162+
start = time()
163+
obj.fit(X_train, y_train)
164+
print(time()-start)
165+
start = time()
166+
print(obj.score(X_test, y_test))
167+
print(time()-start)
168+
169+
print(obj.obj['loss'])
170+
171+
obj = ms.GenericBoostingClassifier(clf2, n_clusters=3)
172+
print(obj.get_params())
173+
start = time()
174+
obj.fit(X_train, y_train)
175+
print(time()-start)
176+
start = time()
177+
print(obj.score(X_test, y_test))
178+
print(time()-start)
179+
180+
print(obj.obj['loss'])
181+
182+
# data 3
183+
print("\n")
184+
print("iris data -----")
185+
186+
iris = load_iris()
187+
Z = iris.data
188+
t = iris.target
189+
np.random.seed(734563)
190+
X_train, X_test, y_train, y_test = train_test_split(Z, t,
191+
test_size=0.2)
192+
193+
194+
obj = ms.GenericBoostingClassifier(clf2)
195+
print(obj.get_params())
196+
start = time()
197+
obj.fit(X_train, y_train)
198+
print(time()-start)
199+
start = time()
200+
print(obj.score(X_test, y_test))
201+
print(time()-start)
202+
203+
print(obj.obj['loss'])
204+

examples/genboost_regressor.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import subprocess
2+
import sys
3+
import os
4+
5+
print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")
6+
7+
8+
subprocess.check_call([sys.executable, "-m", "pip", "install", "matplotlib"])
9+
10+
import mlsauce as ms
11+
import numpy as np
12+
import matplotlib.pyplot as plt
13+
from sklearn.datasets import load_diabetes
14+
from sklearn.model_selection import train_test_split, GridSearchCV, cross_val_score
15+
from sklearn.tree import DecisionTreeRegressor
16+
from time import time
17+
from os import chdir
18+
from sklearn import metrics
19+
20+
21+
print("\n")
22+
print("diabetes data -----")
23+
24+
regr = DecisionTreeRegressor()
25+
26+
diabetes = load_diabetes()
27+
X = diabetes.data
28+
y = diabetes.target
29+
# split data into training test and test set
30+
np.random.seed(15029)
31+
X_train, X_test, y_train, y_test = train_test_split(X, y,
32+
test_size=0.2)
33+
34+
obj = ms.GenericBoostingRegressor(regr, col_sample=0.9, row_sample=0.9)
35+
print(obj.get_params())
36+
start = time()
37+
obj.fit(X_train, y_train)
38+
print(time()-start)
39+
start = time()
40+
print(np.sqrt(np.mean(np.square(obj.predict(X_test) - y_test))))
41+
print(time()-start)
42+
43+
print(obj.obj['loss'])
44+
45+
obj = ms.GenericBoostingRegressor(regr, col_sample=0.9, row_sample=0.9, n_clusters=2)
46+
print(obj.get_params())
47+
start = time()
48+
obj.fit(X_train, y_train)
49+
print(time()-start)
50+
start = time()
51+
print(np.sqrt(np.mean(np.square(obj.predict(X_test) - y_test))))
52+
print(time()-start)
53+
54+
print(obj.obj['loss'])
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import mlsauce as ms
3+
from sklearn.datasets import load_breast_cancer, load_iris, load_wine, load_digits
4+
from sklearn.model_selection import train_test_split
5+
from time import time
6+
7+
print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")
8+
9+
#load_models = [load_breast_cancer, load_iris, load_wine, load_digits]
10+
load_models = [load_breast_cancer, load_iris, load_wine]
11+
#load_models = [load_breast_cancer]
12+
13+
for model in load_models:
14+
15+
data = model()
16+
X = data.data
17+
y= data.target
18+
19+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = .2, random_state = 13)
20+
21+
clf = ms.LazyBoostingClassifier(verbose=1, ignore_warnings=False,
22+
custom_metric=None, preprocess=False)
23+
24+
start = time()
25+
models, predictioms = clf.fit(X_train, X_test, y_train, y_test)
26+
print(f"\nElapsed: {time() - start} seconds\n")
27+
28+
print(models)
29+

examples/lazy_booster_regression.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import os
2+
import mlsauce as ms
3+
from sklearn.datasets import load_diabetes
4+
from sklearn.model_selection import train_test_split
5+
6+
print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")
7+
8+
data = load_diabetes()
9+
X = data.data
10+
y= data.target
11+
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = .2, random_state = 123)
12+
13+
regr = ms.LazyBoostingRegressor(verbose=0, ignore_warnings=True,
14+
custom_metric=None, preprocess=True)
15+
models, predictioms = regr.fit(X_train, X_test, y_train, y_test)
16+
model_dictionary = regr.provide_models(X_train, X_test, y_train, y_test)
17+
print(models)

0 commit comments

Comments
 (0)