print(__doc__)
import numpy as np
import matplotlib.pyplot as plt
from sklearn import datasets
from sklearn import svm
from sklearn.semi_supervised import label_propagation
rng = np.random.RandomState(0)
iris = datasets.load_iris()
X = iris.data[:,:2]
y = iris.target
#step size in the mesh
h = .02
y_30 = np.copy(y)
# len(y_30)
y_30[rng.rand(len(y)) < 0.3]
y_50 = np.copy(y)
y_50[rng.rand(len(y)) < 0.5]
ls30 = (label_propagation.LabelSpreading().fit(X,y_30),y_30)
ls50 = (label_propagation.LabelSpreading().fit(X,y_50),y_50)
ls100 = (label_propagation.LabelSpreading().fit(X,y),y)
rbf_svc = (svm.SVC(kernel = 'rbf', gamma= .5).fit(X,y),y)
#create a mesh to plot in
x_min,x_max = X[:,0].min() - 1 ,X[:,0].max() + 1
y_min,y_max = X[:,1].min() - 1, X[:,1].max() + 1
xx,yy = np.meshgrid(np.arange(x_min,x_max,h),
np.arange(y_min,y_max,h))
color_map = {-1:(1,1,1),0:(0,0,.9),1:(1,0,0),2:(.8,.6,0)} #(1,1,1)白色
titles = ['30%','50%','100%','svc']
for i ,(clf,y_train) in enumerate((ls30,ls50,ls100,rbf_svc)):
plt.subplot(2,2,i+1)
Z = clf.predict(np.c_[xx.ravel(),yy.ravel()])
Z = Z.reshape(xx.shape)
plt.contourf(xx,yy,Z,cmap = plt.cm.Paired)
plt.axis('off')
colors = [color_map[y] for y in y_train]
plt.scatter(X[:,0],X[:,1],c=colors,edgecolors='black')
plt.title(titles[i])
plt.suptitle('XXXX')
plt.show()
When you’re young, you just believe there will be many people with whom you’ll connect. Later in life, you realize it only happens a few times。
年輕的時候你以爲你會和許多人心靈相通,後來你會發現,這樣的事情一輩子只會發生那麼幾次。
個人微信公衆號,專注於學習資源、筆記分享,歡迎關注。我們一起成長,一起學習。一直純真着,善良着,溫情地熱愛生活,,如果覺得有點用的話,請不要吝嗇你手中點讚的權力,謝謝我親愛的讀者朋友。