<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<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.<br>
</p>
<p>Nicolas<br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">On 12/4/20 10:40 AM, Sole Galli via
scikit-learn wrote:<br>
</div>
<blockquote type="cite"
cite="mid:xHCo3nlA5pIjSkEFpDmhZXy0YnWvLhNH9Ev2V-yuhfBVAFyr-KEwcGeztAaR3MRWq1jM2VNOcNRRHBB5afeFzPwVz522sp7SNUHsTRSYhzc=@protonmail.com">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<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"
moz-do-not-send="true">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"
moz-do-not-send="true">https://stackoverflow.com/questions/30972029/how-does-the-class-weight-parameter-in-scikit-learn-work/30982811#30982811</a><br>
</div>
<div><br>
</div>
<div class="protonmail_signature_block">
<div class="protonmail_signature_block-user">
<div>Soledad Galli<br>
</div>
<div><a href="https://www.trainindata.com/"
moz-do-not-send="true">https://www.trainindata.com/</a><br>
</div>
</div>
<div class="protonmail_signature_block-proton
protonmail_signature_block-empty"><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 class="moz-txt-link-rfc2396E" href="mailto:scikit-learn@python.org"><scikit-learn@python.org></a> wrote:<br>
</div>
<div> <br>
</div>
<blockquote class="protonmail_quote" 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 class="protonmail_signature_block">
<div class="protonmail_signature_block-proton
protonmail_signature_block-empty"><br>
</div>
</div>
<div><br>
</div>
</blockquote>
<div><br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
scikit-learn mailing list
<a class="moz-txt-link-abbreviated" href="mailto:scikit-learn@python.org">scikit-learn@python.org</a>
<a class="moz-txt-link-freetext" href="https://mail.python.org/mailman/listinfo/scikit-learn">https://mail.python.org/mailman/listinfo/scikit-learn</a>
</pre>
</blockquote>
</body>
</html>