scikit-learn based embeddings

class skmultilearn.embedding.SKLearnEmbedder(embedder=None, pass_input_space=False)[source]

Bases: sklearn.base.BaseEstimator

Embed the label space using a scikit-compatible matrix-based embedder

Parameters:
  • embedder (sklearn.base.BaseEstimator) – a clonable instance of a scikit-compatible embedder, will be automatically put under self.embedder, see .
  • pass_input_space (bool (default is False)) – whether to take X into consideration upon clustering, use only if you know that the embedder can handle two parameters for clustering, will be automatically put under self.pass_input_space.

Example code for using this embedder looks like this:

from skmultilearn.embedding import SKLearnEmbedder, EmbeddingClassifier
from sklearn.manifold import SpectralEmbedding
from sklearn.ensemble import RandomForestRegressor
from skmultilearn.adapt import MLkNN

clf = EmbeddingClassifier(
    SKLearnEmbedder(SpectralEmbedding(n_components = 10)),
    RandomForestRegressor(n_estimators=10),
    MLkNN(k=5)
)

clf.fit(X_train, y_train)

predictions = clf.predict(X_test)
fit(X, y)[source]

Fits the embedder to data

Parameters:
  • X (array_like, numpy.matrix or scipy.sparse matrix, shape=(n_samples, n_features)) – input feature matrix
  • y (array_like, numpy.matrix or scipy.sparse matrix of {0, 1}, shape=(n_samples, n_labels)) – binary indicator matrix with label assignments
Returns:

fitted instance of self

Return type:

self

fit_transform(X, y)[source]

Fit the embedder and transform the output space

Parameters:
  • X (array_like, numpy.matrix or scipy.sparse matrix, shape=(n_samples, n_features)) – input feature matrix
  • y (array_like, numpy.matrix or scipy.sparse matrix of {0, 1}, shape=(n_samples, n_labels)) – binary indicator matrix with label assignments
Returns:

results of the embedding, input and output space

Return type:

X, y_embedded