sklearn.semi_supervised.LabelPropagation?

class sklearn.semi_supervised.LabelPropagation(kernel='rbf', *, gamma=20, n_neighbors=7, max_iter=1000, tol=0.001, n_jobs=None)

[源碼]

標簽傳播分類器。

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

參數 說明
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內核的參數必須嚴格為正。
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
運行的迭代次數。

另見:

參考

Xiaojin Zhu and Zoubin Ghahramani. Learning from labeled and unlabeled data with label propagation. Technical Report CMU-CALD-02-107, Carnegie Mellon University, 2002 http://pages.cs.wisc.edu/~jerryzhu/pub/CMU-CALD-02-107.pdf

示例

>>> import numpy as np
>>> from sklearn import datasets
>>> from sklearn.semi_supervised import LabelPropagation
>>> label_prop_model = LabelPropagation()
>>> 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)
LabelPropagation(...)

方法

方法 說明
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,max_iter = 1000,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
估計器實例。