sklearn.multioutput.MultiOutputClassifier¶
class sklearn.multioutput.MultiOutputClassifier(estimator, *, n_jobs=None)
[源码]
多目标分类
该策略包括为每个目标拟合一个分类器。这是扩展本机不支持多目标分类的分类器的简单策略
| 参数 | 说明 |
|---|---|
| estimator | estimator object 实现fit,score和 predict_proba的估计器对象。 |
| n_jobs | int or None, optional (default=None) 用于计算的作业数。它并行执行y中的每个目标变量。 None除非joblib.parallel_backend上下文中,否则表示1 。 -1表示使用所有处理器。有关 更多详细信息,请参见词汇表。v0.20版中的更改:n_jobs默认从1更改为None |
| 属性 | 说明 |
|---|---|
| classes_ | array, shape = (n_classes,) 类标签。 |
| estimators_ | list of n_output estimators用于预测的估计量。 |
实例
>>> import numpy as np
>>> from sklearn.datasets import make_multilabel_classification
>>> from sklearn.multioutput import MultiOutputClassifier
>>> from sklearn.neighbors import KNeighborsClassifier
>>> X, y = make_multilabel_classification(n_classes=3, random_state=0)
>>> clf = MultiOutputClassifier(KNeighborsClassifier()).fit(X, y)
>>> clf.predict(X[-2:])
array([[1, 1, 0], [1, 1, 1]])
| 方法 | 说明 |
|---|---|
fit(X, Y[, sample_weight]) |
使模型拟合数据矩阵X和目标Y。 |
get_params([deep]) |
获取此估计量的参数。 |
partial_fit(X, y[, classes, sample_weight]) |
使模型逐渐拟合数据。 |
predict(X) |
使用模型预测多输出变量 |
score(X, y) |
返回给定测试数据和标签的平均准确度。 |
set_params(**params) |
设置此估算量的参数。 |
__init__(estimator, *, n_jobs=None)
[源码]
初始化self, 请参阅help(type(self))以获得准确的说明。
fit(X, Y, sample_weight=None, **fit_params)
[源码]
使模型拟合数据矩阵X和目标Y。
| 参数 | 说明 |
|---|---|
| X | {array-like, sparse matrix} of shape (n_samples, n_features) 输入数据。 |
| Y | array-like of shape (n_samples, n_classes) 目标值。 |
| sample_weight | array-like of shape (n_samples,) or None 样本权重。如果为None,则对样本进行平均加权。仅当基础分类器支持样本权重时才支持。 |
| **fit_params | dict of string -> object 参数传递给 estimator.fit每个步骤的方法。 |
| 返回值 | 说明 |
|---|---|
| self | object |
get_params(deep=True)
[源码]
获取此估计量的参数。
| 参数 | 说明 |
|---|---|
| deep | bool, default=True 如果为True,则将返回此估算器和作为估算器的所包含子对象的参数。 |
| 返回值 | 说明 |
|---|---|
| params | mapping of string to any 参数名称映射到其值。 |
partial_fit(X, y, classes=None, sample_weight=None)
[源码]
使模型逐渐拟合数据。为每个输出变量拟合一个单独的模型。
| 参数 | 说明 |
|---|---|
| X | (sparse) array-like, shape (n_samples, n_features) 数据。 |
| y | (sparse) array-like, shape (n_samples, n_outputs) 多输出目标。 |
| classes | list of numpy arrays, shape (n_outputs) 每个数组都是str / int中一个输出的唯一类。可以通过via获得 ,其中y是整个数据集的目标矩阵。第一次调用partial_fit时需要此参数,在随后的调用中可以将其省略。请注意,y不需要包含中 [np.unique(y[:, i]) for i in range(y.shape[1])]``classes的所有标签。 |
| sample_weight | array-like of shape (n_samples,), default=None 样本权重。如果为None,则对样本进行平均加权。仅当基础回归变量支持样本权重时才支持。 |
| 返回值 | 说明 |
|---|---|
| self | object |
predict(X)
[源码]
使用模型预测多输出变量
针对每个目标变量进行训练。
| 参数 | 说明 |
|---|---|
| X | (sparse) array-like, shape (n_samples, n_features) 数据 |
| 返回值 | 说明 |
|---|---|
| y | (sparse) array-like, shape (n_samples, n_outputs) 跨多个预测变量预测的多输出目标。注意:为每个预测变量生成单独的模型。 |
property predict_proba
概率估计。返回每个输出的每个类的预测概率。
ValueError如果没有任何估算器,则此方法将引发predict_proba。
| 参数 | 返回值 |
|---|---|
| X | array-like, shape (n_samples, n_features) 数据 |
| 返回值 | 说明 |
|---|---|
| p | array of shape (n_samples, n_classes), or a list of n_outputs such arrays if n_outputs > 1. 输入样本的分类概率。类的顺序与属性classes_中的顺序相对应。 在版本0.19中更改:此函数现在返回一个数组列表,其中列表的长度为, 对于该特定输出 n_outputs,每个数组为(n_samples``n_classes)。 |
score(X, y)
[源码]
返回给定测试数据和标签的平均准确度。
| 参数 | 说明 |
|---|---|
| X | array-like, shape [n_samples, n_features] 测试样本 |
| y | array-like, shape [n_samples, n_outputs] X的真实值 |
| 返回值 | 说明 |
|---|---|
| scores | float self.predict(X)对y的accuracy_score |
set_params(**params)
[源码]
设置此估算器的参数。
该方法适用于简单的估计器以及嵌套对象(例如 pipelines)。后者具有形式的参数, <component>__<parameter>以便可以更新嵌套对象的每个组件。
| 参数 | 说明 |
|---|---|
| **params | dict 估算量参数。 |
| 返回值 | 说明 |
|---|---|
| self | object 估算量实例。 |



