标签传播算法(llgc 或 lgc)

动手实践标签传播算法

复现论文:Learning with Local and Global Consistency1

lgc 算法可以参考:DecodePaper/notebook/lgc

初始化算法

载入一些必备的库:

from IPython.display import set_matplotlib_formats
%matplotlib inline
#set_matplotlib_formats('svg', 'pdf')

import numpy as np
import matplotlib.pyplot as plt
from scipy.spatial.distance import cdist
from sklearn.datasets import make_moons

save_dir = '../data/images'

创建一个简单的数据集

利用 make_moons 生成一个半月形数据集。

n = 800   # 样本数
n_labeled = 10 # 有标签样本数
X, Y = make_moons(n, shuffle=True, noise=0.1, random_state=1000)

X.shape, Y.shape
((800, 2), (800,))
def one_hot(Y, n_classes):
    '''
    对标签做 one_hot 编码
    
    参数
    =====
    Y: 从 0 开始的标签
    n_classes: 类别数
    '''
    out = Y[:, None] == np.arange(n_classes)
    return out.astype(float)
color = ['red' if l =
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值