sklearn.semi_supervised.LabelSpreading?

class sklearn.semi_supervised.LabelSpreading(kernel='rbf', *, gamma=20, n_neighbors=7, alpha=0.2, max_iter=30, tol=0.001, n_jobs=None)

用于半監督學習的LabelSpreading模型

該模型類似于基本的標簽傳播算法,但是使用基于歸一化圖拉普拉斯算子和跨標簽的軟夾持的關聯矩陣。

用戶指南中閱讀更多內容。

參數 說明
kernel {‘knn’, ‘rbf’} or callable, default=’rbf’
要使用的內核函數或內核函數本身的字符串標識符。只有'rbf'和'knn'字符串是有效輸入。傳遞的函數應采用兩個輸入,每個輸入的形狀為(n_samples,n_features),并返回一個(n_samples,n_samples)形狀的權重矩陣。
gamma float, default=20
rbf內核的參數。
n_neighbors int, default=7
knn內核的參數,它是嚴格的正整數。
alpha float, default=0.2
軟夾持系數。(0,1)中的一個值,指定一個實例從它的鄰居(而不是它的初始標簽)接收的信息的相對數量。alpha = 0表示保留初始標簽信息;alpha = 1表示替換所有初始信息。
max_iter int, default=1000
允許的最大迭代次數。
tol float, 1e-3
收斂容差:認為系統處于穩定狀態的閾值。
n_jobs int, default=None
要運行的核心數。 除非在上下文中設置了joblib.parallel_backend,否則None表示1 。 -1表示使用所有處理器。有關更多詳細信息,請參見詞匯表
屬性 說明
X_ ndarray of shape (n_samples, n_features)
輸入數組。
classes_ ndarray of shape (n_classes,)
用于分類的不同類別標簽。
label_distributions_ ndarray of shape (n_samples, n_classes)
每個項目的分類分布。
transduction_ ndarray of shape (n_samples)
通過轉換分配給每個項目的標簽。
n_iter_ int
運行的迭代次數。

另見

LabelPropagation

基于非正規圖的半監督學習

參考

Dengyong Zhou, Olivier Bousquet, Thomas Navin Lal, Jason Weston, Bernhard Schoelkopf. Learning with local and global consistency (2004) http://citeseer.ist.psu.edu/viewdoc/summary?doi=10.1.1.115.3219

示例

>>> import numpy as np
>>> from sklearn import datasets
>>> from sklearn.semi_supervised import LabelSpreading
>>> label_prop_model = LabelSpreading()
>>> iris = datasets.load_iris()
>>> rng = np.random.RandomState(42)
>>> random_unlabeled_points = rng.rand(len(iris.target)) < 0.3
>>> labels = np.copy(iris.target)
>>> labels[random_unlabeled_points] = -1
>>> label_prop_model.fit(iris.data, labels)
LabelSpreading(...)

方法

方法 說明
fit(X, y) 擬合基于半監督的標簽傳播模型。
get_params([deep]) 獲取此估計器的參數。
predict(X) 在模型上執行歸納推理。
predict_proba(X) 預測每種可能結果的概率。
score(X, y[, sample_weight]) 返回給定測試數據和標簽上的平均準確度。
set_params(**params) 設置此估計器的參數。
__init__(kernel='rbf', *, gamma=20, n_neighbors=7, alpha=0.2, max_iter=30, tol=0.001, n_jobs=None)

[源碼]

初始化self。請參閱help(type(self))獲取更準確的信息。

fit(X, y)

[源碼]

擬合基于半監督的標簽傳播模型。

提供所有輸入數據的矩陣X(標記和未標記)和對應的標記矩陣y,對未標記樣本有一個專用的標記值。

參數 說明
X array-like of shape (n_samples, n_features)
形狀為(n_samples,n_samples)的矩陣。
y array-like of shape (n_samples,)
n_labeled_samples(未標記的點被標記為-1)所有未標記的樣本將被轉換指定的標簽。
返回值 說明
self object
get_params(deep=True)

[源碼]

獲取此估計量的參數。

參數 說明
deep bool, default=True
如果為True,則將返回此估算器和所包含子對象的參數。
返回值 說明
params mapping of string to any
參數名稱映射到其值。
predict(X )

[源碼]

在模型上執行歸納推理。

參數 說明
X array-like of shape (n_samples, n_features)
數據矩陣。
返回值 說明
y ndarray of shape (n_samples,)
輸入數據的預測值。
predict_proba(X )

[源碼]

預測每種可能類別的概率。

計算X中每個樣本的概率估計值,以及訓練過程中看到的每個可能結果(分類分布)。

參數 說明
X array-like of shape (n_samples, n_features)
數據矩陣。
參數 說明
probabilities ndarray of shape (n_samples, n_classes)
跨類標簽的歸一化概率分布。
score(X,y,sample_weight = None )

[源碼]

返回給定測試數據和標簽上的平均準確度。

在多標簽分類中,這是子集準確性,這是一個苛刻的指標,因為需要為每個樣本正確預測對應的標簽集。

參數 說明
X array-like of shape (n_samples, n_features)
測試樣本。
y array-like of shape (n_samples,) or (n_samples, n_outputs)
X的真實標簽。
sample_weight array-like of shape (n_samples,), default=None
樣本權重。
返回值 說明
score float
真實值與測試值的平均準確度。
set_params(**params)

[源碼]

設置此估算器的參數。

該方法適用于簡單的估計器以及嵌套對象(例如管道)。后者具有<component>__<parameter>形式的參數, 以便可以更新嵌套對象的每個組件。

參數 說明
**params dict
估計器參數。
返回值 說明
self object
估計器實例。