modAL-python / modAL

A modular active learning framework for Python
https://modAL-python.github.io/
MIT License
2.24k stars 324 forks source link

MultiLabel classifier SVM does not have attribute estimators. #131

Closed Jahb closed 3 years ago

Jahb commented 3 years ago

Hello, I am currently trying to have the active learner run on an SVM with a multiOutput Classifer I built using sklearn recently:

from sklearn.svm import LinearSVC
from sklearn.multioutput import MultiOutputClassifier

# Create the SVM
svm = LinearSVC()

# Make it an Multilabel classifier
multilabel_classifier = MultiOutputClassifier(svm, n_jobs=-1)

# Fit the data to the Multilabel classifier
multilabel_classifier = multilabel_classifier.fit(story_padded_train, schema_train)

# Get predictions for test data
schema_test_pred = multilabel_classifier.predict(story_padded_test)

Then when trying to use modAL the code is such that:

from modAL.models import ActiveLearner
from sklearn.ensemble import RandomForestClassifier

from modAL.multilabel import SVM_binary_minimum

svm_strat = SVM_binary_minimum(
    classifier = multilabel_classifier,
    X_pool = story_padded_test
)

# initializing the learner
learner = ActiveLearner(
    estimator=RandomForestClassifier(),
    query_strategy= svm_strat,
    X_training=story_padded_train, y_training=schema_train
)

print(learner.score(story_padded_test, schema_test))

This code will produce an error like so: image

The error is shared on multiple mixes of modAL multiLabel strategies and skLearns SVM models. Looking at the documentation at https://scikit-learn.org/stable/modules/classes.html#module-sklearn.svm It seems like none of the models have the estimator attribute which is strange since the doc https://modal-python.readthedocs.io/en/latest/content/apireference/multilabel.html?highlight=multilabel specifically calls for a sklearn SVM model.