Multi-Label Classification Example with MultiOutputClassifier and XGBoost in Python

  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.

Preparing the data

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

Next, we’ll split the data into the train and test parts.

xtrain, xtest, ytrain, ytest=train_test_split(x, y, train_size=0.8, random_state=88)

Defining the model

We’ll fit the model with training data and check the training accuracy., ytrain)
print(clf.score(xtrain, ytrain))

Source code listing



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store