SelfTrainingClassifier#
- class sklearn.semi_supervised.SelfTrainingClassifier(estimator=None, base_estimator='deprecated', threshold=0.75, criterion='threshold', k_best=10, max_iter=10, verbose=False)[源代码]#
自训练分类器。
这 metaestimator 允许给定的监督分类器充当半监督分类器,允许其从未标记的数据中学习。它通过迭代预测未标记数据的伪标签并将其添加到训练集中来实现这一目标。
分类器将继续迭代,直到达到max_iter,或者在上一次迭代中没有向训练集中添加伪标签。
阅读更多的 User Guide .
- 参数:
- estimator估计器对象
实现的估计器对象
fit
和predict_proba
.调用fit
方法将适合通过的估计器的克隆,该克隆将存储在estimator_
属性Added in version 1.6:
estimator
添加以取代base_estimator
.- base_estimator估计器对象
实现的估计器对象
fit
和predict_proba
.调用fit
方法将适合通过的估计器的克隆,该克隆将存储在estimator_
属性自 1.6 版本弃用:
base_estimator
在1.6中已废弃,并将在1.8中删除。使用estimator
而不是.- threshold浮动,默认=0.75
使用的决策阈值
criterion='threshold'
.应该在[0,1)中。当使用'threshold'
准则的 well calibrated classifier 应该使用。- criterion' thield ',' k_best ',默认=' thield '
用于选择要添加到训练集中的标签的选择标准。如果
'threshold'
,具有以上预测概率的伪标签threshold
已添加到数据集。如果'k_best'
,k_best
具有最高预测概率的伪标签被添加到数据集。当使用“阈值”标准时, well calibrated classifier 应该使用。- k_bestint,默认值=10
每次迭代中要添加的样本量。仅在当
criterion='k_best'
.- max_iterint或无,默认=10
允许的最大迭代次数。应大于或等于0。如果
None
,分类器将继续预测标签,直到没有添加新的伪标签,或者所有未标记的样本都已被标记。- verbose布尔,默认=假
启用详细输出。
- 属性:
- estimator_估计器对象
匹配的估计量。
- classes_nd数组或形状的nd数组列表(n_classes,)
每个输出的类标签。(摘自训练有素的
estimator_
).- transduction_形状的nd数组(n_samples,)
用于分类器最终匹配的标签,包括在匹配期间添加的伪标签。
- labeled_iter_形状的nd数组(n_samples,)
标记每个样本的迭代。当样本具有迭代0时,该样本已在原始数据集中标记。当样本具有迭代-1时,该样本在任何迭代中都不会被标记。
- n_features_in_int
期间看到的功能数量 fit .
Added in version 0.24.
- feature_names_in_ :nd形状数组 (
n_features_in_
,)nd数组形状( Names of features seen during fit. Defined only when
X
has feature names that are all strings.Added in version 1.0.
- n_iter_int
自训练的轮数,即基本估计器在训练集重新标记的变体上进行匹配的次数。
- termination_condition_' max_iter ',' no_change ',' all_labeled '}
停止试穿的原因。
'max_iter'
:n_iter_
达到max_iter
.'no_change'
:预计不会有新标签。'all_labeled'
:所有未贴标签的样本之前都已贴上标签max_iter
已到达。
参见
LabelPropagation
标签传播分类器。
LabelSpreading
半监督学习的标签传播模型。
引用
示例
>>> import numpy as np >>> from sklearn import datasets >>> from sklearn.semi_supervised import SelfTrainingClassifier >>> from sklearn.svm import SVC >>> rng = np.random.RandomState(42) >>> iris = datasets.load_iris() >>> random_unlabeled_points = rng.rand(iris.target.shape[0]) < 0.3 >>> iris.target[random_unlabeled_points] = -1 >>> svc = SVC(probability=True, gamma="auto") >>> self_training_model = SelfTrainingClassifier(svc) >>> self_training_model.fit(iris.data, iris.target) SelfTrainingClassifier(...)
- decision_function(X, **params)[源代码]#
的呼叫决策功能
estimator
.- 参数:
- X形状(n_samples,n_features)的{类数组,稀疏矩阵}
表示数据的数组。
- **params字符串->对象的字典
传递给基础估计器的参数
decision_function
法Added in version 1.6: 仅在以下情况下可用
enable_metadata_routing=True
,可以使用sklearn.set_config(enable_metadata_routing=True)
.看到 Metadata Routing User Guide 了解更多详细信息。
- 返回:
- y形状的nd数组(n_samples,n_features)
的决策功能的结果
estimator
.
- fit(X, y, **params)[源代码]#
使用匹配自训练分类器
X
,y
作为训练数据。- 参数:
- X形状(n_samples,n_features)的{类数组,稀疏矩阵}
表示数据的数组。
- y形状(n_samples,)的{类数组,稀疏矩阵}
代表标签的数组。未贴标签的样品应带有标签-1。
- **paramsdict
要传递给基础估计器的参数。
Added in version 1.6: 仅在以下情况下可用
enable_metadata_routing=True
,可以使用sklearn.set_config(enable_metadata_routing=True)
.看到 Metadata Routing User Guide 了解更多详细信息。
- 返回:
- self对象
拟合估计量。
- get_metadata_routing()[源代码]#
获取此对象的元数据路由。
请检查 User Guide 关于路由机制如何工作。
Added in version 1.6.
- 返回:
- routingMetadataRouter
A
MetadataRouter
封装路由信息。
- get_params(deep=True)[源代码]#
获取此估计器的参数。
- 参数:
- deep布尔,默认=True
如果为True,将返回此估计量和包含的作为估计量的子对象的参数。
- 返回:
- paramsdict
参数名称映射到其值。
- predict(X, **params)[源代码]#
预测的阶级
X
.- 参数:
- X形状(n_samples,n_features)的{类数组,稀疏矩阵}
表示数据的数组。
- **params字符串->对象的字典
传递给基础估计器的参数
predict
法Added in version 1.6: 仅在以下情况下可用
enable_metadata_routing=True
,可以使用sklearn.set_config(enable_metadata_routing=True)
.看到 Metadata Routing User Guide 了解更多详细信息。
- 返回:
- y形状的nd数组(n_samples,)
带有预测标签的数组。
- predict_log_proba(X, **params)[源代码]#
预测每个可能结果的日志概率。
- 参数:
- X形状(n_samples,n_features)的{类数组,稀疏矩阵}
表示数据的数组。
- **params字符串->对象的字典
传递给基础估计器的参数
predict_log_proba
法Added in version 1.6: 仅在以下情况下可用
enable_metadata_routing=True
,可以使用sklearn.set_config(enable_metadata_routing=True)
.看到 Metadata Routing User Guide 了解更多详细信息。
- 返回:
- y形状的nd数组(n_samples,n_features)
具有日志预测概率的数组。
- predict_proba(X, **params)[源代码]#
预测每个可能结果的可能性。
- 参数:
- X形状(n_samples,n_features)的{类数组,稀疏矩阵}
表示数据的数组。
- **params字符串->对象的字典
传递给基础估计器的参数
predict_proba
法Added in version 1.6: 仅在以下情况下可用
enable_metadata_routing=True
,可以使用sklearn.set_config(enable_metadata_routing=True)
.看到 Metadata Routing User Guide 了解更多详细信息。
- 返回:
- y形状的nd数组(n_samples,n_features)
预测概率的数组。
- score(X, y, **params)[源代码]#
呼叫分数
estimator
.- 参数:
- X形状(n_samples,n_features)的{类数组,稀疏矩阵}
表示数据的数组。
- y形状类似阵列(n_samples,)
代表标签的数组。
- **params字符串->对象的字典
传递给基础估计器的参数
score
法Added in version 1.6: 仅在以下情况下可用
enable_metadata_routing=True
,可以使用sklearn.set_config(enable_metadata_routing=True)
.看到 Metadata Routing User Guide 了解更多详细信息。
- 返回:
- score浮子
评分结果
estimator
.