python中带有multioutputclassifier和xgboost的多标签分类示例

  • Post author:
  • Post category:python


Scikit-learn API provides a MulitOutputClassifier class that helps to classify multi-output data. In this tutorial, we’ll learn how to classify multi-output (multi-label) data with this method in Python. Multi-output data contains more than one y label data for a given X input data. The tutorial covers:

Scikit-learn API提供了MulitOutputClassifier类,该类有助于对多输出数据进行分类。 在本教程中,我们将学习如何在Python中使用此方法对多输出(多标签)数据进行分类。 对于给定的X输入数据,多输出数据包含多个y标签数据。 本教程涵盖:

  1. Preparing the data

    准备数据

  2. Defining the model

    定义模型

  3. Predicting and accuracy check

    预测和准确性检查

  4. Source code listing

    源代码清单

我们将从加载本教程所需的库开始。

(

We’ll start by loading the required libraries for this tutorial.

)

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)


from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
from sklearn.metrics import roc_auc_score
from sklearn.metrics import classification_report
from sklearn.datasets import make_multilabel_classification
from xgboost import XGBClassifier
from sklearn.model_selection import KFold
from sklearn.multioutput import MultiOutputClassifier
from sklearn.pipeline import Pipeline


准备数据


(


Preparing the data


)

We can generate a multi-output data with a make_multilabel_classification function. The target dataset contains 20 features (x), 5 classes (y), and 10000 samples.

我们可以使用make_multilabel_classification函数生成多输出数据。 目标数据集包含20个要素(x),5个类(y)和10000个样本。

We’ll define them in the parameters of the function.

我们将在函数的参数中定义它们。

x, y = make_multilabel_classification(n_samples=10000, n_features=20, n_classes=5, random_state=88)

The generated data looks as below. There are 20 features and 5 labels in this dataset.

生成的数据如下。 该数据集中有20个要素和5个标签。<