sklearn中多类分类器、多标签分类器、多输出回归器、多输出-多分类分类器的算法

Summary

 

Number of targets

Target cardinality

Valid type_of_target

Multiclass classification

1

>2

  • ‘multiclass’

Multilabel classification

>1

2 (0 or 1)

  • ‘multilabel-indicator’

Multioutput regression

>1

Continuous

  • ‘continuous-multioutput’

Multioutput- multiclass classification

>1

>2

  • ‘multiclass-multioutput’

 

Warning

 

All classifiers in scikit-learn do multiclass classification out-of-the-box. You don’t need to use the sklearn.multiclass module unless you want to experiment with different multiclass strategies.

The sklearn.multiclass module implements meta-estimators to solve multiclass and multilabel classification problems by decomposing such problems into binary classification problems. multioutput regression is also supported.

  • Multiclass classification: classification task with more than two classes. Each sample can only be labelled as one class.

    For example, classification using features extracted from a set of images of fruit, where each image may either be of an orange, an apple, or a pear. Each image is one sample and is labelled as one of the 3 possible classes. Multiclass classification makes the assumption that each sample is assigned to one and only one label - one sample cannot, for example, be both a pear and an apple.

    Valid multiclass representations for type_of_target (y) are:

    • 1d or column vector containing more than two discrete values. An example of a vector y for 3 samples:

      >>>
      >>> import numpy as np
      >>> y = np.array(['apple', 'pear', 'apple'])
      >>> print(y)
      ['apple' 'pear' 'apple']
      
    • sparse binary matrix of shape (n_samples, n_classes) with a single element per row, where each column represents one class. An example of a sparse binary matrix y for 3 samples, where the columns, in order, are orange, apple and pear:

      >>>
      >>> from scipy import sparse
      >>> row_ind = np.array([0, 1, 2])
      >>> col_ind = np.array([1, 2, 1])
      >>> y_sparse = sparse.csr_matrix((np.ones(3), (row_ind, col_ind)))
      >>> print(y_sparse)
        (0, 1)        1.0
        (1, 2)        1.0
        (2, 1)        1.0
      
  • Multilabel classification: classification task labelling each sample with x labels from n_classes possible classes, where x can be 0 to n_classes inclusive. This can be thought of as predicting properties of a sample that are not mutually exclusive. Formally, a binary output is assigned to each class, for every sample. Positive classes are indicated with 1 and negative classes with 0 or -1. It is thus comparable to running n_classes binary classification tasks, for example with sklearn.multioutput.MultiOutputClassifier. This approach treats each label independently whereas multilabel classifiers may treat the multiple classes simultaneously, accounting for correlated behavior among them.

    For example, prediction of the topics relevant to a text document or video. The document or video may be about one of ‘religion’, ‘politics’, ‘finance’ or ‘education’, several of the topic classes or all of the topic classes.

    A valid representation of multilabel y is an either dense or sparse binary matrix of shape (n_samples, n_classes). Each column represents a class. The 1’s in each row denote the positive classes a sample has been labelled with. An example of a dense matrix y for 3 samples:

    >>>
    >>> y = np.array([[1, 0, 0, 1], [0, 0, 1, 1], [0, 0, 0, 0]])
    >>> print(y)
    [[1 0 0 1]
     [0 0 1 1]
     [0 0 0 0]]
    

    An example of the same y in sparse matrix form:

    >>>
    >>> y_sparse = sparse.csr_matrix(y)
    >>> print(y_sparse)
      (0, 0)    1
      (0, 3)    1
      (1, 2)    1
      (1, 3)    1
    
  • Multioutput regression: predicts multiple numerical properties for each sample. Each property is a numerical variable and the number of properties to be predicted for each sample is greater than or equal to 2. Some estimators that support multioutput regression are faster than just running n_output estimators.

    For example, prediction of both wind speed and wind direction, in degrees, using data obtained at a certain location. Each sample would be data obtained at one location and both wind speed and direction would be output for each sample.

    A valid representation of multioutput y is a dense matrix of shape (n_samples, n_classes) of floats. A column wise concatenation of continuous variables. An example of y for 3 samples:

    >>>
    >>> y = np.array([[31.4, 94], [40.5, 109], [25.0, 30]])
    >>> print(y)
    [[ 31.4  94. ]
     [ 40.5 109. ]
     [ 25.   30. ]]
    
  • Multioutput-multiclass classification (also known as multitask classification): classification task which labels each sample with a set of non-binary properties. Both the number of properties and the number of classes per property is greater than 2. A single estimator thus handles several joint classification tasks. This is both a generalization of the multilabel classification task, which only considers binary attributes, as well as a generalization of the multiclass classification task, where only one property is considered.

    For example, classification of the properties “type of fruit” and “colour” for a set of images of fruit. The property “type of fruit” has the possible classes: “apple”, “pear” and “orange”. The property “colour” has the possible classes: “green”, “red”, “yellow” and “orange”. Each sample is an image of a fruit, a label is output for both properties and each label is one of the possible classes of the corresponding property.

    A valid representation of multioutput y is a dense matrix of shape (n_samples, n_classes) of class labels. A column wise concatenation of 1d multiclass variables. An example of y for 3 samples:

    >>>
    >>> y = np.array([['apple', 'green'], ['orange', 'orange'], ['pear', 'green']])
    >>> print(y)
    [['apple' 'green']
     ['orange' 'orange']
     ['pear' 'green']]
    

    Note that all classifiers handling multioutput-multiclass (also known as multitask classification) tasks, support the multilabel classification task as a special case. Multitask classification is similar to the multioutput classification task with different model formulations. For more information, see the relevant estimator documentation.

All scikit-learn classifiers are capable of multiclass classification, but the meta-estimators offered by sklearn.multiclass permit changing the way they handle more than two classes because this may have an effect on classifier performance (either in terms of generalization error or required computational resources).

Below is a summary of the classifiers supported by scikit-learn grouped by strategy; you don’t need the meta-estimators in this class if you’re using one of these, unless you want custom multiclass behavior:

Warning

 

At present, no metric in sklearn.metrics supports the multioutput-multiclass classification task.

 

Others metrics also work in the multiclass case:

balanced_accuracy_score(y_true, y_pred, \*)

Compute the balanced accuracy

cohen_kappa_score(y1, y2, \*[, labels, …])

Cohen’s kappa: a statistic that measures inter-annotator agreement.

confusion_matrix(y_true, y_pred, \*[, …])

Compute confusion matrix to evaluate the accuracy of a classification.

hinge_loss(y_true, pred_decision, \*[, …])

Average hinge loss (non-regularized)

matthews_corrcoef(y_true, y_pred, \*[, …])

Compute the Matthews correlation coefficient (MCC)

roc_auc_score(y_true, y_score, \*[, …])

Compute Area Under the Receiver Operating Characteristic Curve (ROC AUC) from prediction scores.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值