Skip to content

Commit 1ce5484

Browse files
committed
fixes alpha value in sklearn example and runs notebook till the end
1 parent c6c675a commit 1ce5484

File tree

2 files changed

+100
-44
lines changed

2 files changed

+100
-44
lines changed

examples/sklearn_example.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,51 @@
99
from bayes_opt import BayesianOptimization
1010

1111
# Load data set and target values
12-
data, target = make_classification(n_samples=1000,
13-
n_features=45,
14-
n_informative=12,
15-
n_redundant=7)
12+
data, target = make_classification(
13+
n_samples=1000,
14+
n_features=45,
15+
n_informative=12,
16+
n_redundant=7
17+
)
1618

1719
def svccv(C, gamma):
18-
return cross_val_score(SVC(C=C, gamma=gamma, random_state=2),
19-
data, target, 'f1', cv=2).mean()
20+
val = cross_val_score(
21+
SVC(C=C, gamma=gamma, random_state=2),
22+
data, target, 'f1', cv=2
23+
).mean()
24+
25+
return val
2026

2127
def rfccv(n_estimators, min_samples_split, max_features):
22-
return cross_val_score(RFC(n_estimators=int(n_estimators),
23-
min_samples_split=int(min_samples_split),
24-
max_features=min(max_features, 0.999),
25-
random_state=2),
26-
data, target, 'f1', cv=2).mean()
28+
val = cross_val_score(
29+
RFC(n_estimators=int(n_estimators),
30+
min_samples_split=int(min_samples_split),
31+
max_features=min(max_features, 0.999),
32+
random_state=2
33+
),
34+
data, target, 'f1', cv=2
35+
).mean()
36+
return val
2737

2838
if __name__ == "__main__":
29-
gp_params = {"alpha": 1e5}
39+
gp_params = {"alpha": 1e-5}
3040

31-
svcBO = BayesianOptimization(svccv, {'C': (0.001, 100), 'gamma': (0.0001, 0.1)})
41+
svcBO = BayesianOptimization(svccv,
42+
{'C': (0.001, 100), 'gamma': (0.0001, 0.1)})
3243
svcBO.explore({'C': [0.001, 0.01, 0.1], 'gamma': [0.001, 0.01, 0.1]})
3344

34-
rfcBO = BayesianOptimization(rfccv, {'n_estimators': (10, 250),
35-
'min_samples_split': (2, 25),
36-
'max_features': (0.1, 0.999)})
45+
rfcBO = BayesianOptimization(
46+
rfccv,
47+
{'n_estimators': (10, 250),
48+
'min_samples_split': (2, 25),
49+
'max_features': (0.1, 0.999)}
50+
)
3751

3852
svcBO.maximize(n_iter=10, **gp_params)
39-
print('-'*53)
53+
print('-' * 53)
4054
rfcBO.maximize(n_iter=10, **gp_params)
4155

42-
print('-'*53)
56+
print('-' * 53)
4357
print('Final Results')
4458
print('SVC: %f' % svcBO.res['max']['max_val'])
4559
print('RFC: %f' % rfcBO.res['max']['max_val'])

examples/visualization.ipynb

Lines changed: 68 additions & 26 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)