[scikit-learn] Combine already fitted models
Sebastian Raschka
se.raschka at gmail.com
Sun Oct 1 19:39:29 EDT 2017
Hi, Rares,
> vc = VotingClassifier(...)
> vc.estimators_ = [e1, e2, ...]
> vc.le_ = ...
> vc.predict(...)
>
> But I am not sure it is recommended to modify the "private" estimators_ and le_ attributes.
I think that this may work if you don't call the fit method of the VotingClassifier after that due to
https://github.com/scikit-learn/scikit-learn/blob/ef5cb84a/sklearn/ensemble/voting_classifier.py#L186
Also, I see that we have only added one check in predict(), "check_is_fitted(self, 'estimators_')", for checking that the VotingClassifier was fit, so your proposed method could/should work as a workaround ;)
Best,
Sebastian
> On Oct 1, 2017, at 7:22 PM, Rares Vernica <rvernica at gmail.com> wrote:
>
> > > I am looking at VotingClassifier but it seems that it is expected that the estimators are fitted when VotingClassifier.fit() is called. I don't see how I can have already fitted classifiers combined under a VotingClassifier.
> >
> > I think the opposite is true: The classifiers provided via an `estimators` argument upon initialization will be cloned and fitted if you call VotingClassifier's fit(). Based on your follow-up question, I think you meant "it is expected that the estimators are *not* fitted when VotingClassifier.fit() is called," right?!
>
> Yes, you are right. Sorry for the confusion. Thanks for the pointer!
>
> I am also exploring something like:
>
> vc = VotingClassifier(...)
> vc.estimators_ = [e1, e2, ...]
> vc.le_ = ...
> vc.predict(...)
>
> But I am not sure it is recommended to modify the "private" estimators_ and le_ attributes.
>
> --
> Rares
>
>
> _______________________________________________
> scikit-learn mailing list
> scikit-learn at python.org
> https://mail.python.org/mailman/listinfo/scikit-learn
More information about the scikit-learn
mailing list