# Should I include non-linear features in my linear regression model?

I'm building my first linear regression model with multiple features (predicting house prices in a specific city). After reading up on ways to improve my model, I see people talking about plotting the relationship between the target variable and the features. I then realized that one of my features, the construction year of the house, is kind of "jumpy" which probably messes up the coefficient.

My question: How does one handle features as this one? Drop them? Transform them somehow? Turn them into categorial variables?

Chart below. Y axis is mean house price (in Swedish kronor) per year.

Edit: Added plot of residuals below.

• What is depicted on the Y axis here? Jun 8, 2017 at 19:11
• Oh, sorry. That is the price the house was sold for.
– user153009
Jun 8, 2017 at 19:11
• 0.1e+7-1.0e+7. Mean prices per year. I've updated the question.
– user153009
Jun 8, 2017 at 19:39
• There is nothing "non-linear" with that feature, and there is no indication of doing anything in particular. But you should ask yourself why the mean price is highest arouind construction 1870-1880, maybe because construction then was in a now very centric and popualr zone? I guess there is a string interaction construction year with zoning, you should look at that sort of things. Jun 8, 2017 at 20:03
• It is almost never reasonable to convert a numeric into a factor, so no. What you see in a plot like this is a marginal relationship, but what you are modelling is a conditional relationship taking into account all other variables. You could think about using splines, maybe, but first, and more important, understand your variables and the relationships between them! nand think about intyeractions ... Jun 8, 2017 at 20:18

Your residual plot appears normal enough to use linear regression with Ordinary Least Squares (OLS) loss.

The linear in linear regression refers to the OLS loss function:

$$\hat{Y_i} = \beta_{0} + \beta_{1} X_{i} + \epsilon_i$$

Which is linear in each term. It does not refer to the linearity of the independent variables which are being regressed against the dependent output.

If you are looking for a linear regression-like model that fits a non-linear equation, check out Support Vector Machines (SVM) with a polynomial kernel.

• Yeah, I realized I phrased that poorly. However, my question remains. How does one deal with features that don't seem to follow any discernible pattern across all values. How would you handle this particular feature?
– user153009
Jun 8, 2017 at 20:43
• there's nothing special to do. what is the distribution of your residuals? Jun 8, 2017 at 21:47
• Oh ok. I added a plot of the residuals in my post. Does it look problematic?
– user153009
Jun 8, 2017 at 22:04
• please share a histogram Jun 8, 2017 at 22:24
• Given the lack of fit in residuals vs fitted, I'm not sure there's much value in the histogram of residuals. I'd also worry about the dependence of errors and heteroskedasticy Jun 9, 2017 at 4:19

You can relax linearity assumptions by adding nonlinear terms into your model. Usually polynomials or splines.

Transformations of such variables is also possible. For example things in nature are often related on a log scale, so a log transform would be appropriate. However such transformations doesn't help to any nonlinearity, only the ones following the speciffic distribution.

Discretization of continuous variables is not recommended due to many problems it creates.