modAL icon indicating copy to clipboard operation
modAL copied to clipboard

sklearn interface get_params/set_params not supported

Open BoyanH opened this issue 4 years ago • 1 comments

Every sklearn estimator provides the get_params(deep=True) and set_params(params) methods. These are used e.g. when cloning an estimator. The parameters of an estimator are the arguments of its __init__ method and, as of sklearn's convention, these are all set as class attributes (see BaseEstimator._get_param_names()). When an argument of __init__ is not set as a class attribute, as is the case with ActiveLearner.bootstrap_init, BaseEstimator.get_params() prints a warning. As of version 0.24 of sklearn, an error will be thrown.

This is a minimalistic code snippet which should reproduce the issue.

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

learner = ActiveLearner(
    estimator=RandomForestClassifier(),
    query_strategy=uncertainty_sampling
)
learner.set_params(learner.get_params(deep=True))

A simple solution would be to save all arguments of the __init__ method as class attributes.

BoyanH avatar Sep 21 '20 15:09 BoyanH

Thanks for the report, I am investigating this!

cosmic-cortex avatar Sep 22 '20 06:09 cosmic-cortex