-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathadaboost_classification.py
More file actions
133 lines (107 loc) · 4.53 KB
/
adaboost_classification.py
File metadata and controls
133 lines (107 loc) · 4.53 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import os
import nnetsauce as ns
import numpy as np
from sklearn.datasets import load_breast_cancer, load_wine, load_iris
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn import metrics
from time import time
print(f"\n ----- Running: {os.path.basename(__file__)}... ----- \n")
# dataset no. 1 ----------
print(" \n breast cancer dataset ----- \n")
# logistic reg
breast_cancer = load_breast_cancer()
Z = breast_cancer.data
t = breast_cancer.target
np.random.seed(123)
X_train, X_test, y_train, y_test = train_test_split(Z, t, test_size=0.2)
# SAMME.R
clf = LogisticRegression(solver='liblinear',
random_state=123)
fit_obj = ns.AdaBoostClassifier(clf,
n_hidden_features=int(11.22338867),
direct_link=True,
n_estimators=250, learning_rate=0.01126343,
col_sample=0.72684326, row_sample=0.86429443,
dropout=0.63078613, n_clusters=2,
type_clust="gmm",
verbose=1, seed = 123,
method="SAMME.R")
start = time()
fit_obj.fit(X_train, y_train)
print(f"Elapsed {time() - start}")
start = time()
print(fit_obj.score(X_test, y_test))
print(f"Elapsed {time() - start}")
preds = fit_obj.predict(X_test)
print(fit_obj.score(X_test, y_test, ))
print(metrics.classification_report(preds, y_test))
# SAMME.R (conformal)
clf = LogisticRegression(solver='liblinear', multi_class = 'ovr',
random_state=123)
fit_obj = ns.AdaBoostClassifier(clf,
n_hidden_features=int(11.22338867),
direct_link=True,
n_estimators=250, learning_rate=0.01126343,
col_sample=0.72684326, row_sample=0.86429443,
dropout=0.63078613, n_clusters=2,
type_clust="gmm",
verbose=1, seed = 123,
method="SAMME.R")
start = time()
fit_obj.fit(X_train, y_train)
print(f"Elapsed {time() - start}")
preds = fit_obj.predict(X_test)
# dataset no. 2 ----------
print(" \n wine dataset ----- \n")
wine = load_wine()
Z = wine.data
t = wine.target
np.random.seed(123)
Z_train, Z_test, y_train, y_test = train_test_split(Z, t, test_size=0.2)
# SAMME
clf = LogisticRegression(solver='liblinear', multi_class = 'ovr',
random_state=123)
fit_obj = ns.AdaBoostClassifier(clf,
n_hidden_features=int(8.21154785e+01),
direct_link=True,
n_estimators=1000, learning_rate=2.96252441e-02,
col_sample=4.22766113e-01, row_sample=7.87268066e-01,
dropout=1.56909180e-01, n_clusters=3,
type_clust="gmm",
verbose=1, seed = 123,
method="SAMME")
start = time()
fit_obj.fit(Z_train, y_train)
print(f"Elapsed {time() - start}")
start = time()
print(fit_obj.score(Z_test, y_test))
print(f"Elapsed {time() - start}")
preds = fit_obj.predict(Z_test)
print(metrics.classification_report(preds, y_test))
# dataset no. 3 ----------
print(" \n iris dataset ----- \n")
iris = load_iris()
Z = iris.data
t = iris.target
np.random.seed(123)
Z_train, Z_test, y_train, y_test = train_test_split(Z, t, test_size=0.2)
# SAMME.R
clf = LogisticRegression(solver='liblinear', multi_class = 'ovr',
random_state=123)
fit_obj = ns.AdaBoostClassifier(clf,
n_hidden_features=int(19.66918945),
direct_link=True,
n_estimators=250, learning_rate=0.28534302,
col_sample=0.45474854, row_sample=0.87833252,
dropout=0.15603027, n_clusters=0,
verbose=1, seed = 123,
method="SAMME.R")
start = time()
fit_obj.fit(Z_train, y_train)
print(f"Elapsed {time() - start}")
start = time()
print(fit_obj.score(Z_test, y_test))
print(f"Elapsed {time() - start}")
preds = fit_obj.predict(Z_test)
print(metrics.classification_report(preds, y_test))