# coding: utf-8 from sklearn import datasets from sklearn import svm from sklearn.decomposition import PCA import numpy as np import matplotlib.pyplot as plt
plt.contourf( x,y,z.reshape(x.shape),levels=[-0.5,0.5,1.5,2.5], colors=["r","g","b"]) for i,c in zip([0,1,2],["r","g","b"]): d=data[iris.target==i] plt.scatter(d[:,0],d[:,1],c=c) plt.show()
kmeans=KMeans(n_clusters=3) kmeans.fit(x) markers=["o","v","x"] for i in range(3): xx=x[kmeans.labels_==i] plt.scatter(xx[:,0],xx[:,1],c="k",marker=markers[i])