半监督学习——LabelPropagation

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。
年轻的时候你以为你会和许多人心灵相通,后来你会发现,这样的事情一辈子只会发生那么几次。 ​

个人微信公众号,专注于学习资源、笔记分享,欢迎关注。我们一起成长,一起学习。一直纯真着,善良着,温情地热爱生活,,如果觉得有点用的话,请不要吝啬你手中点赞的权力,谢谢我亲爱的读者朋友
五角钱的程序员,专注于学习资源、笔记分享。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值