import matplotlib.pyplot as plt
import seaborn as sns;sns.set()
from sklearn.datasets import make_moons
from sklearn.cluster import KMeans
from sklearn.metrics import accuracy_score
from sklearn.metrics import normalized_mutual_info_score
from sklearn.metrics import adjusted_rand_score
fig = plt.figure(1)
plt.subplot(1,2,1)#一行一列
x1, y1 = make_moons(n_samples=400, noise=0.1)
plt.title('make_moons function')
plt.scatter(x1[:, 0], x1[:, 1], marker='o',s=15, c=y1,cmap='viridis')
plt.subplot(1,2,2)#一行两列
kmeans = KMeans(n_clusters=2)#2个聚类中心
kmeans.fit(x1)
y_kmeans = kmeans.predict(x1)
plt.scatter(x1[:, 0], x1[:, 1], c=y_kmeans, s=15,cmap='viridis')
##三大指标
acc=accuracy_score(y1,y_kmeans)
nmi=normalized_mutual_info_score(y1,y_kmeans)
ari=adjusted_rand_score(y1,y_kmeans)
print("ACC=",acc)
print("NMI=",nmi)
print("ARI=",ari)
plt.show()
输出示例