-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
27 lines (23 loc) · 997 Bytes
/
example.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
from sklearn import metrics
import crecknn
import math
import numpy as np
# Data load
D = np.load('data_sample/MPEG7-CFD.npy')
# Definition of true labels to compute F-measure
labels_true = [math.floor(i/20) for i in range(len(D))]
# Cluster initialization
cluster = crecknn.Cluster(k=15, ck=4)
cluster.fit(D)
# Cluster evaluation
rand = metrics.adjusted_rand_score(labels_true, cluster.labels_)
nmi_min = metrics.normalized_mutual_info_score(labels_true, cluster.labels_, 'min')
ami = metrics.adjusted_mutual_info_score(labels_true, cluster.labels_, 'min')
ocv = metrics.homogeneity_completeness_v_measure(labels_true, cluster.labels_)
v = metrics.v_measure_score(labels_true, cluster.labels_)
print("adjusted rand score -> ",rand)
print("Normalized mutual info score -> ", nmi_min)
print("Adjusted mutual info score -> ", ami)
print("Homogeneity / Completeness / V-Measure -> ", ocv)
print("V-Measure -> ", v)
print('F-Measure -> ', cluster.calculate_f_measure(cluster.labels_, labels_true))