<div dir="auto">I have been using both in time-series classification. I put a exponential decay in sample_weights AND class weights as a dictionary. </div><div dir="auto"><br></div><div dir="auto">BR/Schots </div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Em sex., 4 de dez. de 2020 às 12:01, Nicolas Hug <<a href="mailto:niourf@gmail.com">niourf@gmail.com</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div>
    <p>Basically passing class weights should be equivalent to passing
      per-class-constant sample weights.</p>
    <p>> why do some estimators allow to pass weights both as a dict
      in the init or as sample weights in fit? what's the logic?</p>
    <p>SW is a per-sample property (aligned with X and y) so we avoid
      passing those to init because the data isn't known when
      initializing the estimator. It's only known when calling fit. In
      general we avoid passing data-related info into init so that the
      same instance can be fitted on any data (with different number of
      samples, different classes, etc.).<br>
    </p>
    <p>We allow to pass class_weight in init because the 'balanced'
      option is data-agnostic. Arguably, allowing a dict with actual
      class values violates the above argument (of not having
      data-related stuff in init), so I guess that's where the logic
      ends ;)</p>
    <p>As to why one would use both, I'm not so sure honestly.</p></div><div><p><br>
    </p>
    <p>Nicolas<br>
    </p>
    <p><br>
    </p>
    <div>On 12/4/20 10:40 AM, Sole Galli via
      scikit-learn wrote:<br>
    </div>
    <blockquote type="cite">
      
      <div>Actually, I found the answer. Both seem to be optimising the
        loss function for the various algorithms, below I include some
        links.<br>
      </div>
      <div><br>
      </div>
      <div> If, we pass <b>class_weight</b> and <b>sample_weight,</b>
        then the final cost / weight is a combination of both.<br>
      </div>
      <div><br>
      </div>
      <div>I have a follow up question: in which scenario would we use
        both? why do some estimators allow to pass weights both as a
        dict in the init or as sample weights in fit? what's the logic?
        I found it a bit confusing at the beginning.<br>
      </div>
      <div><br>
      </div>
      <div>Thank you!<br>
      </div>
      <div><br>
      </div>
      <div><a href="https://stackoverflow.com/questions/30805192/scikit-learn-random-forest-class-weight-and-sample-weight-parameters" target="_blank">https://stackoverflow.com/questions/30805192/scikit-learn-random-forest-class-weight-and-sample-weight-parameters</a><br>
      </div>
      <div><br>
      </div>
      <div><a href="https://stackoverflow.com/questions/30972029/how-does-the-class-weight-parameter-in-scikit-learn-work/30982811#30982811" target="_blank">https://stackoverflow.com/questions/30972029/how-does-the-class-weight-parameter-in-scikit-learn-work/30982811#30982811</a><br>
      </div>
      <div><br>
      </div>
      <div>
        <div>
          <div>Soledad Galli<br>
          </div>
          <div><a href="https://www.trainindata.com/" target="_blank">https://www.trainindata.com/</a><br>
          </div>
        </div>
        <div><br>
        </div>
      </div>
      <div><br>
      </div>
      <div>‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐<br>
      </div>
      <div> On Thursday, December 3, 2020 11:55 AM, Sole Galli via
        scikit-learn <a href="mailto:scikit-learn@python.org" target="_blank"><scikit-learn@python.org></a> wrote:<br>
      </div>
      <div> <br>
      </div>
      <blockquote type="cite">
        <div>Hello team,<br>
        </div>
        <div><br>
        </div>
        <div>What is the difference in the implementation of
          class_weight and sample_weight in those algorithms that
          support both? like random forest or logistic regression?<br>
        </div>
        <div><br>
        </div>
        <div>Are both modifying the loss function? in a similar way?<br>
        </div>
        <div><br>
        </div>
        <div>Thank you!<br>
        </div>
        <div><br>
        </div>
        <div>Sole<br>
        </div>
        <div>
          <div><br>
          </div>
        </div>
        <div><br>
        </div>
      </blockquote>
      <div><br>
      </div>
      <br>
      <fieldset></fieldset>
      <pre>_______________________________________________
scikit-learn mailing list
<a href="mailto:scikit-learn@python.org" target="_blank">scikit-learn@python.org</a>
<a href="https://mail.python.org/mailman/listinfo/scikit-learn" target="_blank">https://mail.python.org/mailman/listinfo/scikit-learn</a>
</pre>
    </blockquote>
  </div>

_______________________________________________<br>
scikit-learn mailing list<br>
<a href="mailto:scikit-learn@python.org" target="_blank">scikit-learn@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/scikit-learn" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/scikit-learn</a><br>
</blockquote></div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Schots</div>