Topics
Several common models are linear in a particular mathematical sense, but not always on the raw outcome scale. Ordinary linear regression models the conditional mean as linear in the chosen features. Logistic regression models the log-odds linearly. LDA obtains linear decision boundaries from Gaussian class models with a common covariance matrix.
Understanding this linear assumption is critical for ensuring model performance, as fitting a model that assumes linearity to non-linear data can lead to poor predictions. This article will explore models that assume linear relationships, discuss why it’s important to recognize these assumptions, and examine what to do when the assumption is not valid.
The practical question is not "is the world linear?" It is whether a linear approximation is good enough for the decision being made. Linear models often remain strong baselines because they are stable, interpretable, fast to train, and easier to audit than more flexible alternatives.
Algorithms That Assume Linear Relationships
Several machine learning models are built on the assumption that the relationship between predictors and the outcome is linear. The most common ones include:
1. Linear Regression
Linear regression estimates the relationship between input features and the target by fitting a straight line through the data points, using the following equation:
Here the coefficients describe the fitted linear predictor conditional on the model and included covariates. Calling them the “influence” of a predictor is too strong unless the design supports a causal interpretation.
2. Logistic Regression
Although logistic regression models binary outcomes, it still assumes a linear relationship between the predictors and the log-odds of the outcome. The logistic function then transforms the linear combination of predictors into probabilities.
3. Linear Discriminant Analysis (LDA)
LDA assumes that the data from each class is drawn from a Gaussian distribution with identical covariance matrices but different means. The decision boundaries between classes are linear functions of the input features.
4. Principal Component Regression (PCR)
PCR first forms unsupervised linear combinations of the predictors with PCA and then regresses the outcome on selected components. The regression is linear in those components, but the leading PCA directions are chosen to explain predictor variance rather than outcome relevance.
Importance of Understanding Linear Assumptions
1. Performance Issues with Non-Linear Data
If a model assumes a linear relationship between $X$ and $Y$, but the data does not follow this pattern, the model will struggle to provide accurate predictions. The residuals (errors) between the predicted and actual values will exhibit patterns, indicating the model’s poor fit. When the linear assumption is violated, the model might either underfit the data or miss important non-linear patterns. In such cases, switching to a non-linear model like decision trees or neural networks might lead to better performance.
2. Interpretability of Linear Models
Linear models are favored in business and regulatory environments because of their interpretability. These models provide clear insights into how each predictor affects the target variable. This interpretability can be crucial in industries such as finance or healthcare, where regulatory compliance demands transparency.
3. Generalization of Linear Models
Linear models have another advantage: they can generalize better in situations where the relationship between predictors and the outcome is genuinely linear. Additionally, non-linear models like decision trees often struggle to make accurate predictions for data points outside the range of the training set, whereas linear models can extrapolate more effectively when the linear assumption holds.
4. Efficiency in Model Training
Linear models are computationally efficient, making them suitable for high-dimensional data or large datasets where the linear assumption holds. Training a linear model is faster compared to non-linear models, which may require more complex optimization techniques.
Handling Non-Linear Relationships
When a linear relationship does not exist between the predictors and the outcome, several strategies can be used to improve model performance: Before changing models, diagnose the problem. Useful checks include:
- residual plots against fitted values and individual predictors;
- partial dependence or accumulated local effects plots;
- calibration curves for probabilistic classifiers;
- comparison against a simple tree-based baseline;
- cross-validation split by time, group, or geography when those structures matter.
If the residuals show a clear pattern, the model is missing structure. If the pattern only appears in one segment, the issue may be interaction effects or population heterogeneity rather than global non-linearity.
1. Transforming Variables
One common approach to reveal linear relationships is to apply mathematical transformations to the predictors. For instance, logarithmic or polynomial transformations can convert non-linear data into a form that better fits the assumptions of linear models. For example, if a relationship between two variables follows a quadratic pattern, squaring one of the predictors could transform the problem into a linear one.
2. Discretization
Discretizing continuous variables into bins or categories can also simplify non-linear relationships and make them more suitable for linear models. For example, a continuous variable like age could be split into age ranges, making it easier to model relationships.
3. Using Non-Linear Models
When transformations are not effective, switching to a non-linear model like Random Forests, Gradient Boosting, or Neural Networks might be the best approach. These models can capture more complex interactions between predictors and the outcome, leading to better performance.
4. Adding Interactions and Splines
There is a middle ground between a plain linear model and a fully flexible black-box model. Interaction terms allow the effect of one variable to depend on another, while spline functions let the model learn smooth non-linear shapes. Generalized additive models are especially useful when interpretability remains important but straight-line effects are too restrictive.
Real-Life Example: Predicting House Prices
Let’s look at a practical application of linear relationships in a common machine learning problem: predicting the sale price of houses. House prices can be influenced by various features such as total square footage, quality of materials, and number of rooms.
Dataset and Setup
We use the House Price dataset from Kaggle, which contains numerous predictors for residential homes. You can download the dataset here. In this example, we focus on a subset of features to demonstrate linear and non-linear relationships with the target variable, Sale Price.
Identifying Linear and Non-Linear Variables
Using scatter plots, we can visualize how different predictors relate to the target:
- Linear Relationships: Features like
OverallQual,TotalBsmtSF, andGrLivAreashow a roughly linear relationship with Sale Price. - Non-Linear Relationships: Features like
WoodDeckSFandBsmtUnfSFshow non-linear patterns.
Performance of Linear Models
A linear model can be a strong baseline for house prices, especially after appropriate transformations and interactions. Whether an individual raw feature is “linear” should be diagnosed conditionally rather than from one marginal scatter plot. When we fit the model, we can assess its performance by calculating the mean squared error (MSE) on the test set. A low MSE suggests that the linear model is well-suited for predicting Sale Price for those variables.
Example of Linear vs Non-Linear Performance
For non-linear variables, a Random Forest Regressor can perform better than linear regression. Random forests can capture the non-linear relationships that are missed by linear models. However, random forests may struggle to generalize beyond the training data’s value ranges, making them less reliable when predictions are needed outside the observed data.
Key Takeaway
In real-world problems like predicting house prices, linear relationships between predictors and outcomes can offer advantages in terms of interpretability, efficiency, and generalization. However, non-linear patterns should not be ignored, and switching to more flexible models when necessary can lead to better results.
Conclusion
In machine learning, understanding the assumptions of linear models is essential for choosing the right algorithm and ensuring accurate predictions. While linear models like Linear Regression, Logistic Regression, and LDA offer simplicity and interpretability, they perform best when the relationship between predictors and the target is genuinely linear. When this assumption is not met, transformations or non-linear models can provide more effective solutions.
For practitioners, the ability to recognize linear and non-linear relationships in the data is crucial for building models that both perform well and meet business or regulatory requirements. Linear models should usually be the first serious baseline, not the final answer by default. Fit them, inspect their errors, compare them against more flexible models, and choose the simplest model that captures the structure required by the use case.
References
- Hosmer, D. W., Lemeshow, S., & Sturdivant, R. X. (2013). Applied Logistic Regression (3rd ed.). Wiley.
- Jolliffe, I. T., & Cadima, J. (2016). Principal component analysis: a review and recent developments. Philosophical Transactions of the Royal Society A, 374(2065).
- Breiman, L., Friedman, J., Olshen, R., & Stone, C. (1984). Classification and Regression Trees. Wadsworth.
- Breiman, L. (2001). Random forests. Machine Learning, 45(1), 5-32.
- Friedman, J. H. (2001). Greedy function approximation: a gradient boosting machine. Annals of Statistics, 29(5), 1189-1232.
- Wood, S. N. (2017). Generalized Additive Models: An Introduction with R (2nd ed.). CRC Press.
Embed interactive plots, widgets, and demos using <figure>, <iframe>, or <div class="interactive-embed"> containers. Ensure each embed includes descriptive captions for accessibility.
How to cite
Use the quick export buttons to save citations for reference managers or copy the formatted text directly.
Diogo Ribeiro (2022). Linear Relationships in Machine Learning Models: Why They Matter. Faculty of Media Arts and Design, Technical University of Porto. https://diogoribeiro7.github.io/machine-learning/linear_relashionships/.


