-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_usage.py
29 lines (23 loc) · 843 Bytes
/
example_usage.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
import pandas as pd
import numpy as np
import skperopt as sk
from sklearn.datasets import make_classification
from sklearn.neighbors import KNeighborsClassifier
#generate classification data
data = make_classification(n_samples=1000, n_features=10, n_classes=2)
X = pd.DataFrame(data[0])
y = pd.DataFrame(data[1])
#init the classifier
kn = KNeighborsClassifier()
param = {"n_neighbors": [int(x) for x in np.linspace(1, 60, 30)],
"leaf_size": [int(x) for x in np.linspace(1, 60, 30)],
"p": [1, 2, 3, 4, 5, 10, 20],
"algorithm": ['auto', 'ball_tree', 'kd_tree', 'brute'],
"weights": ["uniform", "distance"]}
#search parameters
search = sk.HyperSearch(kn, X, y, params=param)
search.search()
#gather and apply the best parameters
kn.set_params(**search.best_params)
#view run results
print(search.stats)