-
Notifications
You must be signed in to change notification settings - Fork 42
/
random_annealing.py
37 lines (26 loc) · 802 Bytes
/
random_annealing.py
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
from sklearn.datasets import load_iris
from sklearn.neighbors import KNeighborsClassifier
from sklearn.model_selection import cross_val_score
from hyperactive import Hyperactive
from hyperactive.optimizers import RandomAnnealingOptimizer
data = load_iris()
X, y = data.data, data.target
def model(opt):
knr = KNeighborsClassifier(n_neighbors=opt["n_neighbors"])
scores = cross_val_score(knr, X, y, cv=5)
score = scores.mean()
return score
search_space = {
"n_neighbors": list(range(1, 100)),
}
optimizer = RandomAnnealingOptimizer(
epsilon=0.1,
distribution="laplace",
n_neighbours=4,
rand_rest_p=0.1,
annealing_rate=0.999,
start_temp=0.8,
)
hyper = Hyperactive()
hyper.add_search(model, search_space, optimizer=optimizer, n_iter=100)
hyper.run()