[scikit-learn] Combine already fitted models

Andreas Mueller t3kcit at gmail.com
Sat Oct 7 10:53:58 EDT 2017


For some reason I thought we had a "prefit" parameter.

I think we should.


On 10/01/2017 07:39 PM, Sebastian Raschka wrote:
> 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
> _______________________________________________
> 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