简体   繁体   中英

How to use Linear regression when my **X** values are normally distributed?

To be more specific the error variance of the x value is half of the variance of error in y .

I looked over sklearn and couldn't find a function which takes the error variance of x into account.

Not 100% sure I understand the question. But if I understand it correctly, you are trying to use linear regression to find the linear model with maximum likelihood. In other words, an error for data where X and Y are uncertain is less serious that one where X and Y are very accurate.

If that is so, what people do in such case, is usually to weight each sample with inverse of error variance.

With sklearn , weight is simply the 3rd (optionnal) parameter of .fit

So I would

lin=LinearRegression()
lin.fit(X, Y, 1/variance(X))

variance(X) being your evaluation of X variance.

Edit (after your comment)

Then I don't get the question. The fact that X and Y measure have an error, that those error do not have the same magnitude (anyway, "same magnitude" about a weight and a size would be meaningless), etc. is not a problem. If there were no error, then you wouldn't be doing a linear regression, would you? As long as those error have a 0 expected value (and if not, just remove the expected value of the error from the variable:D), and are not correlated... (so, being independent is a sufficient condition)

That is Gauss-Markov hypothesis, and it is the foundation of the least square method (the one used by sklearn).

If you know something else from your error, then, back to my first answer. But if all you know is that the error on Y tends to be bigger than error on X, then, there is no problem to solve.

for anyone who might find it useful, the lecturer told us the answer, it required using DEMING REGRESSION

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM