The skmultilearn.adapt module implements algorithm adaptation approaches to multi-label classification.

Algorithm adaptation methods for multi-label classification concentrate on adapting single-label classification algorithms to the multi-label case usually by changes in cost/decision functions. You can find more information about this approach in the Mining Multi-label Data paper by Tsoumakas et. al.

Currently scikit-multilearn provides implementations of BRkNN and MLkNN adaptations of the well known k Nearest Neighbours classifier adapted by Zhang & Zhou in their paper A lazy learning approach to multi-label learning.

Provides the following classes:

• BRkNNaClassifier - a Binary Relevance kNN classifier that assigns a label if at least half of the neighbors are also classified with the label
• BRkNNbClassifier- a Binary Relevance kNN classifier that assigns top m labels of neighbors with m - average number of labels assigned to neighbors
• MLkNN - a multi-label adapted kNN classifier with bayesian prior corrections
class skmultilearn.adapt.BRkNNaClassifier(k=10)[source]

Binary Relevance multi-label classifier based on k Nearest Neighbours method.

This version of the classifier assigns the labels that are assigned to at least half of the neighbors.

Parameters: k (int) – number of neighbors
predict_variant(X)[source]
class skmultilearn.adapt.BRkNNbClassifier(k=10)[source]

Binary Relevance multi-label classifier based on k Nearest Neighbours method.

This version of the classifier assigns the most popular m labels of the neighbors, where m is the average number of labels assigned to the object’s neighbors.

Parameters: k (int) – number of neighbors
predict_variant(X)[source]
class skmultilearn.adapt.MLkNN(k=10, s=1.0, ignore_first_neighbours=0)[source]

kNN classification method adapted for multi-label classification

Parameters: k : integer number of neighbours of each input instance to take into account s: boolean the smoothing parameter ignore_first_neighbours : integer ability to ignore first N neighbours, useful for comparing with other classification software, if you don’t know what it does, the default is safe, see https://github.com/scikit-multilearn/scikit-multilearn/issues/22
BRIEFNAME = 'MLkNN'
compute_cond(X, y)[source]
compute_prior(y)[source]
fit(X, y)[source]

Fit classifier with training data

Parameters: X (dense or sparse matrix (n_samples, n_features)) – input features y (dense or sparse matrix of {0, 1} (n_samples, n_labels)) – binary indicator matrix with label assignments Fitted instance of self
predict(X)[source]

Predict labels for X

Parameters: X (dense or sparse matrix (n_samples, n_features)) – input features binary indicator matrix with label assignments sparse matrix of int (n_samples, n_labels)
predict_proba(X)[source]

Predict probabilities of label assignments for X

Parameters: X (dense or sparse matrix (n_samples, n_labels)) – input features matrix with label assignment probabilities sparse matrix of float (n_samples, n_labels)

## Submodules¶

class skmultilearn.adapt.brknn.BRkNNaClassifier(k=10)[source]

Binary Relevance multi-label classifier based on k Nearest Neighbours method.

This version of the classifier assigns the labels that are assigned to at least half of the neighbors.

Parameters: k (int) – number of neighbors
predict_variant(X)[source]
class skmultilearn.adapt.brknn.BRkNNbClassifier(k=10)[source]

Binary Relevance multi-label classifier based on k Nearest Neighbours method.

This version of the classifier assigns the most popular m labels of the neighbors, where m is the average number of labels assigned to the object’s neighbors.

Parameters: k (int) – number of neighbors
predict_variant(X)[source]
class skmultilearn.adapt.brknn.BinaryRelevanceKNN(k=10)[source]

Binary Relevance adapted kNN Multi-Label Classifier.

compute_confidences()[source]
fit(X, y)[source]

Fit classifier with training data

Internally this method uses a sparse CSC representation for y (scipy.sparse.csc_matrix).

Parameters: X (dense or sparse matrix (n_samples, n_features)) – input features y (dense or sparse matrix of {0, 1} (n_samples, n_labels)) – binary indicator matrix with label assignments Fitted instance of self
predict(X)[source]

Predict labels for X

Parameters: X (dense or sparse matrix (n_samples, n_features)) – input features binary indicator matrix with label assignments sparse matrix of int (n_samples, n_labels)

class skmultilearn.adapt.mlknn.MLkNN(k=10, s=1.0, ignore_first_neighbours=0)[source]

kNN classification method adapted for multi-label classification

Parameters: k : integer number of neighbours of each input instance to take into account s: boolean the smoothing parameter ignore_first_neighbours : integer ability to ignore first N neighbours, useful for comparing with other classification software, if you don’t know what it does, the default is safe, see https://github.com/scikit-multilearn/scikit-multilearn/issues/22
BRIEFNAME = 'MLkNN'
compute_cond(X, y)[source]
compute_prior(y)[source]
fit(X, y)[source]

Fit classifier with training data

Parameters: X (dense or sparse matrix (n_samples, n_features)) – input features y (dense or sparse matrix of {0, 1} (n_samples, n_labels)) – binary indicator matrix with label assignments Fitted instance of self
predict(X)[source]

Predict labels for X

Parameters: X (dense or sparse matrix (n_samples, n_features)) – input features binary indicator matrix with label assignments sparse matrix of int (n_samples, n_labels)
predict_proba(X)[source]

Predict probabilities of label assignments for X

Parameters: X (dense or sparse matrix (n_samples, n_labels)) – input features matrix with label assignment probabilities sparse matrix of float (n_samples, n_labels)