机器学习学习笔记--Hello-K-means

K-means是无监督学习 聚类

#-*- coding:utf-8 -*-

import numpy as np

import matplotlib.pyplot as plt

from sklearn.cluster import KMeans

from sklearn.datasets import make_blobs

def show_kmeans():

print(__doc__)

plt.figure(figsize=(12,12))

n_samples=1500

random_state=170

x,y=make_blobs(n_samples=n_samples,random_state=random_state)

y_pred = KMeans(n_clusters=3,random_state=random_state).fit_predict(x)

plt.subplot(221)

plt.scatter(x[:,0],x[:,1],c=y_pred)

plt.title("Hello Keams")

plt.show()

if __name__ == '__main__':

show_kmeans()



机器学习学习笔记--Hello-K-means_第1张图片

你可能感兴趣的:(机器学习学习笔记--Hello-K-means)