-
Notifications
You must be signed in to change notification settings - Fork 6
/
example_modelorderselection.py
30 lines (25 loc) · 1.03 KB
/
example_modelorderselection.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
import numpy as np
from skstab import ModelOrderSelection
from skstab.datasets import load_dataset
from sklearn.cluster import KMeans
from sklearn.neighbors import KNeighborsClassifier
dataset = 'exemples2_5g'
X, y = load_dataset(dataset)
print('Dataset: {} (true number of clusters: K = {})'.format(dataset, len(np.unique(y))))
algorithm = KMeans
km_kwargs = {'init': 'k-means++', 'n_init': 10}
k_values = list(range(2, 11))
print('Evaluated numbers of clusters:', k_values)
stab = ModelOrderSelection(X, algorithm,
param_name='n_clusters',
param_values=k_values,
classifier=KNeighborsClassifier,
norm_samples=20,
runs=20,
algo_kwargs=km_kwargs,
clf_kwargs={'n_neighbors': 1},
n_jobs=-1)
score = stab.score()
print('Model order selection scores:\n', score)
k_hat = stab.select_param()[0]
print('Selected number of clusters: K =', k_hat)