sklearn.multiclass.OutputCodeClassifier¶
class sklearn.multiclass.OutputCodeClassifier(estimator, *, code_size=1.5, random_state=None, n_jobs=None)
[源码]
错误纠正,输出代码多类策略
基于输出代码的策略包括用二进制代码(0和1的数组)表示每个类。在拟合时,在代码簿中每位装配一个二进制分类器。在预测时,分类器用于在类空间中投影新点,并选择最接近这些点的类。这些策略的主要优点是用户可以控制使用的分类器数量,以压缩模型(0 <code_size <1)或使模型对错误更有效(code_size> 1)。有关更多详细信息,请参见文档。
在用户指南中阅读更多内容。
| 参数 | 说明 | 
|---|---|
| estimator | estimator object 一种实现拟合和决策函数(decision_function)或预测概率(predict_proba)之一的估计对象。 | 
| code_size | float 用于创建代码簿的类数的百分比。介于0和1之间的数字需要的分类器比1和其余的要少。大于1的数字将需要比其他分类器更多的分类器。 | 
| random_state | int, RandomState instance or None, optional, default: None 用于初始化密码本的生成器。为多个函数调用传递可重复输出的int值。请参阅词汇表。 | 
| n_jobs | int or None, optional (default=None) 用于计算的数量。 None除非joblib.parallel_backend上下文中,否则表示1 。-1表示使用所有处理器。有关 更多详细信息,请参见词汇表。 | 
| 属性 | 说明 | 
|---|---|
| estimators_estimators | list of int(n_classes * code_size)用于预测的估计量。 | 
| classes_ | numpy array of shape [n_classes] 包含标签的数组。 | 
| code_book_ | numpy array of shape [n_classes, code_size] 包含每个类代码的二进制数组。 | 
参考文献
1 “Solving multiclass learning problems via error-correcting output codes”, Dietterich T., Bakiri G., Journal of Artificial Intelligence Research 2, 1995.
2 “The error coding method and PICTs”, James G., Hastie T., Journal of Computational and Graphical statistics 7, 1998.
3 “The Elements of Statistical Learning”, Hastie T., Tibshirani R., Friedman J., page 606 (second-edition) 2008.
实例
>>> from sklearn.multiclass import OutputCodeClassifier
>>> from sklearn.ensemble import RandomForestClassifier
>>> from sklearn.datasets import make_classification
>>> X, y = make_classification(n_samples=100, n_features=4,
...                            n_informative=2, n_redundant=0,
...                            random_state=0, shuffle=False)
>>> clf = OutputCodeClassifier(
...     estimator=RandomForestClassifier(random_state=0),
...     random_state=0).fit(X, y)
>>> clf.predict([[0, 0, 0, 0]])
array([1])
| 方法 | 说明 | 
|---|---|
| fit(X, y) | 拟合基础估计量。 | 
| get_params([deep]) | 获取此估计量的参数。 | 
| predict(X) | 使用基础估计量预测多类别目标。 | 
| score(X, y[, sample_weight]) | 返回给定测试数据和标签上的平均准确度。 | 
| set_params(**params) | 设置此估算器的参数。 | 
__init__(estimator, *, code_size=1.5, random_state=None, n_jobs=None)
[源码]
初始化self, 请参阅help(type(self))以获得准确的说明。
fit(X, y)
[源码]
拟合基础估计量。
| 参数 | 说明 | 
|---|---|
| X | (sparse) array-like of shape (n_samples, n_features) 数据 | 
| y | numpy array of shape [n_samples] 多类别目标。 | 
| 返回值 | 
|---|
| self | 
get_params(deep=True)
[源码]
获取此估计量的参数。
| 参数 | 说明 | 
|---|---|
| deep | bool, default=True 如果为True,则将返回此估计量和作为估计量的包含子对象的参数。 | 
| 返回值 | 说明 | 
|---|---|
| params | mapping of string to any 参数名称映射到其值。 | 
predict(X)
[源码]
使用基础估计量预测多类别目标。
| 参数 | 说明 | 
|---|---|
| X | (sparse) array-like of shape (n_samples, n_features) 数据 | 
| 返回值 | 说明 | 
|---|---|
| y | numpy array of shape [n_samples] 预测的多类别目标。 | 
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 self.predict(X) wrt. y.的平均准确度。 | 
set_params(**params)
[源码]
设置此估算器的参数。
该方法适用于简单的估计器以及嵌套对象(例如 pipelines)。后者具有形式的参数, <component>__<parameter>以便可以更新嵌套对象的每个组件。
| 参数 | 说明 | 
|---|---|
| **params | dict 估算量参数。 | 
| 返回值 | 说明 | 
|---|---|
| self | object 估算量实例。 | 




