#!/usr/bin/env Python3
-- coding: utf-8 --
@Software: PyCharm
@virtualenv:ai
@contact: 1040691703@qq.com
@Desc:对K-means.py 文件的解析
author = ‘未昔/AngelFate’
date = ‘2019/8/15 20:10’
import numpy as np
def kmeans_():
“”"
聚类,找出原始数据集的中心点
:return:
“”"
from sklearn.cluster import KMeans
X = np.loadtxt(‘test.txt’, dtype=float, delimiter=’,’)
kmeans = KMeans(n_clusters=2, random_state=0).fit(X)
print(kmeans.labels_)
print('kmeans.predict: ',kmeans.predict([[0, 0], [12, 3]]))
#这个聚类中心点的值,和生成时用的正态分布的mean很接近.
print(kmeans.cluster_centers_)
if name == ‘main’:
kmeans_()