# Getting negative predicted values after linear regression

I'm using linear regression to predict a price which is obviously positive. I have only one feature which is gross_area. I standardized it (z-score) I got this kind of value:

array([[ 1.        , -0.48311432],
[ 1.        ,  0.68052306],
[ 1.        ,  2.1426852 ],
[ 1.        , -1.17398593],
[ 1.        , -0.16265712]])


Where the 1 is the constant for the intercept term. I predict the parameters(predictors) and I got this:

array([[ 31780004.85045217],
[ 27347542.4693376 ]])


Where the first cell is the intercept term and the second cell correspond to the parameter found for my feature gross_area.

My problem is the following, when I take for example the fourth line and I compute the matrix multiplication XB to get my prediction, I got this:

In : np.dot(training, theta)
Out: array([-325625.35640697])


Which is totally wrong since I cannot have negative value for my dependent variable. It seems like because of my normalization where I got negative value for my feature, I ended up with a negative predicted value for some tuple. How can is it possible and how can I fix this ? Thank you.

This is what I have predict graphically: with y=price , x =gross area

• Can you elaborate on how price and area are related? The solution is either to use log price (though prediction gets tricky) or you need to use some sort of GLM, but the details will depend on what you're trying to model. Apr 8, 2015 at 18:27
• The Pearson's correlation coefficient is about 0.84392 between gross_area and price Apr 8, 2015 at 18:37
• I don't mean statistically. Why would price change with area? What is the mechanism or model? Apr 8, 2015 at 18:48
• Because as the gross area increases, the prices increases as well.. But I don't think that I understand what do you mean exactly :( Apr 8, 2015 at 18:53
• See the discussion in this answer, this one and this one, and perhaps also this. Apr 10, 2015 at 9:42

• There's no mystery here. A straight line $y = a + bx$ will predict negative $y$ for some $x$ unless $a > 0$ and $b = 0$. That can bite within the range of your data, and is biting you. Using logarithmic scale seems natural not just because you reasonably prefer positive predictions, but also because curvature is evident too from your graph, and indeed uneven scatter. Whether you are better off with log transformation or a GLM with logarithmic link is a more subtle question. Apr 8, 2015 at 19:00
• There are also many posts explaining why that statement (precisely that within "") is wrong. At most, there are some nice properties if the error distribution is normal. Suppose $y = a + bx + \epsilon$ and the error $\epsilon$ is uniformly distributed on $[-c, c]$. Is regression then invalid? Not so. Functional form is primary; marginal or conditional distribution is secondary. Apr 8, 2015 at 19:37