<html><head><meta http-equiv="Content-Security-Policy" content="script-src 'self'; img-src * cid: data:;"><style id="outgoing-font-settings">#response_container_BBPPID{font-family: initial; font-size:initial; color: initial;}</style></head><body style="background-color: rgb(255, 255, 255); background-image: initial; line-height: initial;"><div id="response_container_BBPPID" style="outline:none;" dir="auto" contenteditable="false"> <div name="BB10" id="BB10_response_div_BBPPID" dir="auto" style="width:100%;"> Actually I don't see anything mentioning it in the road map currently. Should it be added?</div>                                                                                                                                      <div name="BB10" id="response_div_spacer_BBPPID" dir="auto" style="width:100%;"> <br style="display:initial"></div>                            <div id="blackberry_signature_BBPPID" name="BB10" dir="auto">     <div id="_signaturePlaceholder_BBPPID" name="BB10" dir="auto"><p dir="ltr">Sent from my phone - sorry to be brief and potential misspell. </p></div> </div></div><div id="_original_msg_header_BBPPID" dir="auto">                                                                                                                                             <table width="100%" style="background-color: white; border-spacing: 0px; display: table; outline: none;" contenteditable="false"><tbody><tr><td colspan="2" style="padding: initial; font-size: initial; text-align: initial; background-color: rgb(255, 255, 255);">                           <div style="border-right: none; border-bottom: none; border-left: none; border-image: initial; border-top: 1pt solid rgb(181, 196, 223); padding: 3pt 0in 0in; font-family: Tahoma, "BB Alpha Sans", "Slate Pro"; font-size: 10pt;">  <div id="from"><b>From:</b> luiz.gh@gmail.com</div><div id="sent"><b>Sent:</b> 19 September 2018 7:12 pm</div><div id="to"><b>To:</b> scikit-learn@python.org</div><div id="reply_to"><b>Reply to:</b> scikit-learn@python.org</div><div id="subject"><b>Subject:</b> Re: [scikit-learn] Issues with clone for ensemble of, classifiers</div></div></td></tr></tbody></table> <br> </div><!--start of _originalContent --><div name="BB10" dir="auto" style="background-image: initial; line-height: initial; outline: none;" contenteditable="false"><div dir="ltr"><p>Guillaume - thank you for the comments. Indeed, an approach to 
"freeze" a fitted classifier would solve our problem. The Github issue seems 
to be inactive for a while, but I will check if anyone else is working 
on it.</p>
<p>Luiz Gustavo</p><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 19, 2018 at 12:02 PM <<a href="mailto:scikit-learn-request@python.org">scikit-learn-request@python.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 0.8ex;border-left:1px #ccc solid;padding-left:1ex">Send scikit-learn mailing list submissions to<br>
        <a href="mailto:scikit-learn@python.org">scikit-learn@python.org</a><br>
<br>
To subscribe or unsubscribe via the World Wide Web, visit<br>
        <a href="https://mail.python.org/mailman/listinfo/scikit-learn">https://mail.python.org/mailman/listinfo/scikit-learn</a><br>
or, via email, send a message with subject or body 'help' to<br>
        <a href="mailto:scikit-learn-request@python.org">scikit-learn-request@python.org</a><br>
<br>
You can reach the person managing the list at<br>
        <a href="mailto:scikit-learn-owner@python.org">scikit-learn-owner@python.org</a><br>
<br>
When replying, please edit your Subject line so it is more specific<br>
than "Re: Contents of scikit-learn digest..."<br>
<br>
<br>
Today's Topics:<br>
<br>
   1. Re: Issues with clone for ensemble of classifiers<br>
      (Guillaume Lema?tre)<br>
<br>
<br>
----------------------------------------------------------------------<br>
<br>
Message: 1<br>
Date: Wed, 19 Sep 2018 17:38:46 +0200<br>
From: Guillaume Lema?tre <<a href="mailto:g.lemaitre58@gmail.com">g.lemaitre58@gmail.com</a>><br>
To: Scikit-learn user and developer mailing list<br>
        <<a href="mailto:scikit-learn@python.org">scikit-learn@python.org</a>><br>
Subject: Re: [scikit-learn] Issues with clone for ensemble of<br>
        classifiers<br>
Message-ID:<br>
        <CACDxx9gyszjJP-5ZB_bvH4nCkdn-sb6CCb=<a href="mailto:k2j_kOOnFPBQt0g@mail.gmail.com">k2j_kOOnFPBQt0g@mail.gmail.com</a>><br>
Content-Type: text/plain; charset="UTF-8"<br>
<br>
However, there is some issue to frozen a fitted classifier. You can refer to:<br>
<br>
<a href="https://github.com/scikit-learn/scikit-learn/issues/8370">https://github.com/scikit-learn/scikit-learn/issues/8370</a><br>
<br>
with the associated discussion.<br>
On Wed, 19 Sep 2018 at 17:34, Guillaume Lema?tre <<a href="mailto:g.lemaitre58@gmail.com">g.lemaitre58@gmail.com</a>> wrote:<br>
><br>
> Ups I misread your comment. I don't think that we have currently a<br>
> mechanism to avoid cloning classifier internally.<br>
> On Wed, 19 Sep 2018 at 17:31, Guillaume Lema?tre <<a href="mailto:g.lemaitre58@gmail.com">g.lemaitre58@gmail.com</a>> wrote:<br>
> ><br>
> > You don't have anywhere in your class MyClassifier where you are<br>
> > calling base_<wbr><a href="http://classifier.fit">classifier.fit</a><wbr>(...) therefore when calling<br>
> > base_<wbr><a href="http://classifier.predict">classifier.predict</a><wbr>(...) it will let you know that you did not fit<br>
> > it.<br>
> ><br>
> > On Wed, 19 Sep 2018 at 16:43, Luiz Gustavo Hafemann <<a href="mailto:luiz.gh@gmail.com">luiz.gh@gmail.com</a>> wrote:<br>
> > ><br>
> > > Hello,<br>
> > ><br>
> > > I am one of the developers of a library for Dynamic Ensemble Selection (DES) methods (the library is called DESlib), and we are currently working to get the library fully compatible with scikit-learn (to submit it to scikit-learn-contrib). We have "check_estimator" working for most of the classes, but now I am having problems to make the classes compatible with GridSearch / other CV functions.<br>
> > ><br>
> > > One of the main use cases of this library is to facilitate research on this field, and this led to a design decision that the base classifiers are fit by the user, and the DES methods receive a pool of base classifiers that were already fit (this allow users to compare many DES techniques with the same base classifiers). This is creating an issue with GridSearch, since the clone method (defined in <wbr><a href="http://sklearn.base">sklearn.base</a><wbr>) is not cloning the classes as we would like. It does a shallow (non-deep) copy of the parameters, but we would like the pool of base classifiers to be deep-copied.<br>
> > ><br>
> > > I analyzed this issue and I could not find a solution that does not require changes on the scikit-learn code. Here is the sequence of steps that cause the problem:<br>
> > ><br>
> > > GridSearchCV calls "clone" on the DES estimator (link)<br>
> > > The clone function calls the "get_params" function of the DES estimator (link, line 60). We don't re-implement this function, so it gets all the parameters, including the pool of classifiers (at this point, they are still "fitted")<br>
> > > The clone function then clones each parameter with safe=False (line 62). When cloning the pool of classifiers, the result is a pool that is not "fitted" anymore.<br>
> > ><br>
> > > The problem is that, to my knowledge, there is no way for my classifier to inform "clone" that a parameter should be always deep copied. I see that other ensemble methods in sklearn always fit the base classifiers within the "fit" method of the ensemble, so this problem does not happen there. I would like to know if there is a solution for this problem while having the base classifiers fitted elsewhere.<br>
> > ><br>
> > > Here is a short code that reproduces the issue:<br>
> > ><br>
> > > ---------------------------<br>
> > ><br>
> > > from sklearn.model_selection import GridSearchCV, train_test_split<br>
> > > from <wbr><a href="http://sklearn.base">sklearn.base</a><wbr> import BaseEstimator, ClassifierMixin<br>
> > > from <wbr><a href="http://sklearn.ensemble">sklearn.ensemble</a><wbr> import BaggingClassifier<br>
> > > from <wbr><a href="http://sklearn.datasets">sklearn.datasets</a><wbr> import load_iris<br>
> > ><br>
> > ><br>
> > > class MyClassifier(BaseEstimator, ClassifierMixin):<br>
> > >     def __init__(self, base_classifiers, k):<br>
> > >         self.base_classifiers = base_classifiers  # Base classifiers that are already trained<br>
> > >         self.k = k  # Simulate a parameter that we want to do a grid search on<br>
> > ><br>
> > >     def fit(self, X_dsel, y_dsel):<br>
> > >         pass  # Here we would fit any parameters for the Dynamic selection method, not the base classifiers<br>
> > ><br>
> > >     def predict(self, X):<br>
> > >         return self.base_<wbr><a href="http://classifiers.predict">classifiers.predict</a><wbr>(X)  # In practice the methods would do something with the predictions of each classifier<br>
> > ><br>
> > ><br>
> > > X, y = load_iris(return_X_y=True)<br>
> > > X_train, X_dsel, y_train, y_dsel = train_test_split(X, y, test_size=0.5)<br>
> > ><br>
> > > base_classifiers = BaggingClassifier()<br>
> > > base_<wbr><a href="http://classifiers.fit">classifiers.fit</a><wbr>(X_train, y_train)<br>
> > ><br>
> > > clf = MyClassifier(base_classifiers, k=1)<br>
> > ><br>
> > > params = {'k': [1, 3, 5, 7]}<br>
> > > grid = GridSearchCV(clf, params)<br>
> > ><br>
> > > <wbr><a href="http://grid.fit">grid.fit</a><wbr>(X_dsel, y_dsel)  # Raises error that the bagging classifiers are not fitted<br>
> > ><br>
> > > ---------------------------<br>
> > ><br>
> > > Btw, here is the branch that we are using to make the library compatible with sklearn: <a href="https://github.com/Menelau/DESlib/tree/sklearn-estimators">https://github.com/Menelau/DESlib/tree/sklearn-estimators</a>. The failing test related to this issue is in <a href="https://github.com/Menelau/DESlib/blob/sklearn-estimators/deslib/tests/test_des_integration.py#L36">https://github.com/Menelau/DESlib/blob/sklearn-estimators/deslib/tests/test_des_integration.py#L36</a><br>
> > ><br>
> > > Thanks in advance for any help on this case,<br>
> > ><br>
> > > Luiz Gustavo Hafemann<br>
> > ><br>
> > > _______________________________________________<br>
> > > scikit-learn mailing list<br>
> > > <a href="mailto:scikit-learn@python.org">scikit-learn@python.org</a><br>
> > > <a href="https://mail.python.org/mailman/listinfo/scikit-learn">https://mail.python.org/mailman/listinfo/scikit-learn</a><br>
> ><br>
> ><br>
> ><br>
> > --<br>
> > Guillaume Lemaitre<br>
> > INRIA Saclay - Parietal team<br>
> > Center for Data Science Paris-Saclay<br>
> > <a href="https://glemaitre.github.io/">https://glemaitre.github.io/</a><br>
><br>
><br>
><br>
> --<br>
> Guillaume Lemaitre<br>
> INRIA Saclay - Parietal team<br>
> Center for Data Science Paris-Saclay<br>
> <a href="https://glemaitre.github.io/">https://glemaitre.github.io/</a><br>
<br>
<br>
<br>
-- <br>
Guillaume Lemaitre<br>
INRIA Saclay - Parietal team<br>
Center for Data Science Paris-Saclay<br>
<a href="https://glemaitre.github.io/">https://glemaitre.github.io/</a><br>
<br>
<br>
------------------------------<br>
<br>
Subject: Digest Footer<br>
<br>
_______________________________________________<br>
scikit-learn mailing list<br>
<a href="mailto:scikit-learn@python.org">scikit-learn@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scikit-learn">https://mail.python.org/mailman/listinfo/scikit-learn</a><br>
<br>
<br>
------------------------------<br>
<br>
End of scikit-learn Digest, Vol 30, Issue 14<br>
********************************************<br>
</blockquote></div></div>
<!--end of _originalContent --></div></body></html>