数据挖掘 —— 半监督学习(标签传播算法)

数据挖掘 —— 半监督学习(标签传播算法)

  • 标签传播算法
    • 参数解释
    • 代码
    • 结果

标签传播算法

参数解释

标签传播算法要求为标注数据标签为1

LablePropagation(kernel,gamma,n_neighbors)
  • kernel:{“knn”,“rbf”}
  • gamma:rbf中的r
  • n_neighbors:knn中的参数

代码

from sklearn.datasets import load_iris
from sklearn.semi_supervised import LabelPropagation
import numpy as np
import pandas as pd
from sklearn.metrics import accuracy_score,recall_score,f1_score
iris = load_iris()
labels = np.copy(iris.target)
labels[np.random.rand(len(labels)) < 0.3] = -1
label_prop_model = LabelPropagation()
label_prop_model.fit(iris.data,labels)
label_predict = label_prop_model.predict(iris.data)
print("acc_score:",accuracy_score(iris.target,label_predict))
print("acc_score:",recall_score(iris.target,label_predict,average="macro"))
print("acc_score:",f1_score(iris.target,label_predict,average="macro"))

结果

acc_score: 0.98
acc_score: 0.98
acc_score: 0.9799819837854069

by CyrusMay 2022 04 05

你可能感兴趣的:(数据挖掘专题,python,数据挖掘,机器学习,半监督,标签传播算法)