<div dir="ltr">Here is a possibly useful comment of larsmans on stackoverflow about exactly this procedure<br><br><a href="http://stackoverflow.com/questions/26604175/how-to-predict-a-continuous-dependent-variable-that-expresses-target-class-proba/26614131#comment41846816_26614131">http://stackoverflow.com/questions/26604175/how-to-predict-a-continuous-dependent-variable-that-expresses-target-class-proba/26614131#comment41846816_26614131</a><br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 10, 2016 at 4:04 PM, Sean Violante <span dir="ltr"><<a href="mailto:sean.violante@gmail.com" target="_blank">sean.violante@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">sorry yes there was a misunderstanding:<div><br></div><div>I meant for each feature configuration you should pass in two rows (one for the positive cases and one for the negative)</div><div>and the sample weight being the corresponding count for that configuration and class  </div><div><br></div><div>and I am saying that the total  count is important because you could have a situation where </div><div>one feature combination occurs 10 times and another feature combination 1000 times</div><div><br></div><div><br></div><div><br></div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 10, 2016 at 3:48 PM, Raphael C <span dir="ltr"><<a href="mailto:drraph@gmail.com" target="_blank">drraph@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 10 October 2016 at 12:22, Sean Violante <<a href="mailto:sean.violante@gmail.com" target="_blank">sean.violante@gmail.com</a>> wrote:<br>
> no ( but please check !)<br>
><br>
> sample weights should be the counts for the respective label (0/1)<br>
><br>
> [ I am actually puzzled about the glm help file - proportions loses how<br>
> often an input data 'row' was present relative to the other - though you<br>
> could do this by repeating the row 'n' times]<br>
<br>
I think we might be talking at cross purposes.<br>
<br>
I have a matrix X where each row is a feature vector. I also have an<br>
array y where y[i] is a real number between 0 and 1. I would like to<br>
build a regression model that predicts the y values given the X rows.<br>
<br>
Now each y[i] value in fact comes from simply counting the number of<br>
positive labelled elements in a particular set (set i) and dividing by<br>
the number of elements in that set.  So I can easily fit this into the<br>
model given by the R package glm by replacing each y[i] value by a<br>
pair of "Number of positives" and "Number of negatives" (this is case<br>
2 in the docs I quoted) or using case 3 which asks for the y[i] plus<br>
the total number of elements in set i.<br>
<br>
I don't see how a single integer for sample_weight[i] would cover this<br>
information but I am sure I must have misunderstood.  At best it seems<br>
it could cover the number of positive values but this is missing half<br>
the information.<br>
<br>
Raphael<br>
<br>
><br>
> On Mon, Oct 10, 2016 at 1:15 PM, Raphael C <<a href="mailto:drraph@gmail.com" target="_blank">drraph@gmail.com</a>> wrote:<br>
>><br>
>> How do I use sample_weight for my use case?<br>
>><br>
>> In my case is "y" an array of 0s and 1s and sample_weight then an<br>
>> array real numbers between 0 and 1 where I should make sure to set<br>
>> sample_weight[i]= 0 when y[i] = 0?<br>
>><br>
>> Raphael<br>
>><br>
>> On 10 October 2016 at 12:08, Sean Violante <<a href="mailto:sean.violante@gmail.com" target="_blank">sean.violante@gmail.com</a>><br>
>> wrote:<br>
>> > should be the sample weight function in fit<br>
>> ><br>
>> ><br>
>> > <a href="http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html" rel="noreferrer" target="_blank">http://scikit-learn.org/stable<wbr>/modules/generated/sklearn.<wbr>linear_model.LogisticRegressio<wbr>n.html</a><br>
>> ><br>
>> > On Mon, Oct 10, 2016 at 1:03 PM, Raphael C <<a href="mailto:drraph@gmail.com" target="_blank">drraph@gmail.com</a>> wrote:<br>
>> >><br>
>> >> I just noticed this about the glm package in R.<br>
>> >> <a href="http://stats.stackexchange.com/a/26779/53128" rel="noreferrer" target="_blank">http://stats.stackexchange.com<wbr>/a/26779/53128</a><br>
>> >><br>
>> >> "<br>
>> >> The glm function in R allows 3 ways to specify the formula for a<br>
>> >> logistic regression model.<br>
>> >><br>
>> >> The most common is that each row of the data frame represents a single<br>
>> >> observation and the response variable is either 0 or 1 (or a factor<br>
>> >> with 2 levels, or other varibale with only 2 unique values).<br>
>> >><br>
>> >> Another option is to use a 2 column matrix as the response variable<br>
>> >> with the first column being the counts of 'successes' and the second<br>
>> >> column being the counts of 'failures'.<br>
>> >><br>
>> >> You can also specify the response as a proportion between 0 and 1,<br>
>> >> then specify another column as the 'weight' that gives the total<br>
>> >> number that the proportion is from (so a response of 0.3 and a weight<br>
>> >> of 10 is the same as 3 'successes' and 7 'failures')."<br>
>> >><br>
>> >> Either of the last two options would do for me.  Does scikit-learn<br>
>> >> support either of these last two options?<br>
>> >><br>
>> >> Raphael<br>
>> >><br>
>> >> On 10 October 2016 at 11:55, Raphael C <<a href="mailto:drraph@gmail.com" target="_blank">drraph@gmail.com</a>> wrote:<br>
>> >> > I am trying to perform regression where my dependent variable is<br>
>> >> > constrained to be between 0 and 1. This constraint comes from the<br>
>> >> > fact<br>
>> >> > that it represents a count proportion. That is counts in some<br>
>> >> > category<br>
>> >> > divided by a total count.<br>
>> >> ><br>
>> >> > In the literature it seems that one common way to tackle this is to<br>
>> >> > use logistic regression. However, it appears that in scikit learn<br>
>> >> > logistic regression is only available as a classifier<br>
>> >> ><br>
>> >> ><br>
>> >> > (<a href="http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html" rel="noreferrer" target="_blank">http://scikit-learn.org/stabl<wbr>e/modules/generated/sklearn.<wbr>linear_model.LogisticRegressio<wbr>n.html</a><br>
>> >> > ) . Is that right?<br>
>> >> ><br>
>> >> > Is there another way to perform regression using scikit learn where<br>
>> >> > the dependent variable is a count proportion?<br>
>> >> ><br>
>> >> > Thanks for any help.<br>
>> >> ><br>
>> >> > Raphael<br>
>> >> ______________________________<wbr>_________________<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/mailma<wbr>n/listinfo/scikit-learn</a><br>
>> ><br>
>> ><br>
>> ><br>
>> > ______________________________<wbr>_________________<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/mailma<wbr>n/listinfo/scikit-learn</a><br>
>> ><br>
>> ______________________________<wbr>_________________<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/mailma<wbr>n/listinfo/scikit-learn</a><br>
><br>
><br>
><br>
> ______________________________<wbr>_________________<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/mailma<wbr>n/listinfo/scikit-learn</a><br>
><br>
______________________________<wbr>_________________<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/mailma<wbr>n/listinfo/scikit-learn</a><br>
</blockquote></div><br></div>
</div></div><br>______________________________<wbr>_________________<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" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/scikit-learn</a><br>
<br></blockquote></div><br></div>