Weighted linear regression with Scikit-learn python -
my data:
state n var1 var2 alabama 23 54 42 alaska 4 53 53 arizona 53 75 65
var1 , var2 aggregated percentage values @ state level. n number of participants in each state. run linear regression between var1 , var2 consideration of n weight sklearn in python 2.7.
the general line is:
fit(x, y[, sample_weight])
say data loaded df using pandas , n becomes df["n"], fit data following line or need process n somehow before using "sample_weight" in command?
fit(df["var1"], df["var2"], sample_weight=df["n"])
Comments
Post a Comment