skmultilearn.ensemble.voting module

class skmultilearn.ensemble.MajorityVotingClassifier(classifier=None, clusterer=None, require_dense=None)[source]

Bases: skmultilearn.ensemble.partition.LabelSpacePartitioningClassifier

Majority Voting ensemble classifier

Divides the label space using provided clusterer class, trains a provided base classifier type classifier for each subset and assign a label to an instance if more than half of all classifiers (majority) from clusters that contain the label assigned the label to the instance.

Parameters:
  • classifier (BaseEstimator) – the base classifier that will be used in a class, will be automatically put under self.classifier.
  • clusterer (LabelSpaceClustererBase) – object that partitions the output space, will be automatically put under self.clusterer.
  • require_dense ([bool, bool]) – whether the base classifier requires [input, output] matrices in dense representation, will be automatically put under self.require_dense.
model_count_

number of trained models, in this classifier equal to the number of partitions

Type:int
partition_

list of lists of label indexes, used to index the output space matrix, set in _generate_partition() via fit()

Type:List[List[int]], shape=(model_count_,)
classifiers

list of classifiers trained per partition, set in fit()

Type:List[BaseEstimator], shape=(model_count_,)

Examples

Here’s an example of building an overlapping ensemble of chains

from skmultilearn.ensemble import MajorityVotingClassifier
from skmultilearn.cluster import FixedLabelSpaceClusterer
from skmultilearn.problem_transform import ClassifierChain
from sklearn.naive_bayes import GaussianNB

classifier = MajorityVotingClassifier(
    clusterer = FixedLabelSpaceClusterer(clusters = [[1,2,3], [0, 2, 5], [4, 5]]),
    classifier = ClassifierChain(classifier=GaussianNB())
)
classifier.fit(X_train,y_train)
predictions = classifier.predict(X_test)

More advanced examples can be found in the label relations exploration guide

predict(X)[source]

Predict label assignments for X

Parameters:X (numpy.ndarray or scipy.sparse.csc_matrix) – input features of shape (n_samples, n_features)
Returns:binary indicator matrix with label assignments with shape (n_samples, n_labels)
Return type:scipy.sparse of float