赞
踩
from sklearn import datasets
from sklearn.utils.linear_assignment_ import linear_assignment
import seaborn as sns
import matplotlib.pyplot as plt
import copy
from sklearn.metrics import confusion_matrix
from sklearn import metrics
from sklearn.cluster import KMeans
import pandas as pd
import numpy as np
def purity(cluster, label): cluster = np.array(cluster) label = np. array(label) indedata1 = {} for p in np.unique(label): indedata1[p] = np.argwhere(label == p) indedata2 = {} for q in np.unique(cluster): indedata2[q] = np.argwhere(cluster == q) count_all = [] for i in indedata1.values(): count = [] for j in indedata2.values(): a = np.intersect1d(i, j).shape[0] count.append(a) count_all.append(count) return sum(np.max(count_all, axis=0))/len(cluster)
def jaccard(cluster, label):
dist_cluster = np.abs(np.tile(cluster, (len(cluster), 1)) -
np.tile(cluster, (len(cluster), 1)).T)
dist_label = np.abs(np.tile(label, (len(label), 1)) -
np.tile(label, (len(label), 1)).T)
a_loc = np.argwhere(dist_cluster+dist_label == 0)
n = len(cluster)
a = (a_loc.shape[0]-n)/2
same_cluster_index = np.argwhere(dist_cluster == 0)
same_label_index = np.argwhere(dist_label == 0)
bc = same_cluster_index.shape[0]+same_label_index.shape[0]-2*n-2*a
return a/(a+bc)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。