GNGiseldo Neo and Alana NeoBooks
Linear Regression with Python3 / 19

Introduction to Linear Regression

Chapter Objective

Present the definition, history, importance, advantages, limitations, and examples of linear regression.

2.1 Definition of Linear Regression

Linear regression is a statistical technique used to model the relationship between a continuous dependent variable and one or more independent variables. When there is only one independent variable, it is called simple linear regression (or simply linear regression); when there is more than one independent variable, it is called multiple regression. The main goal is to find the best-fitting straight line that describes the relationship between the variables by minimizing the sum of the squared differences between the observed values and the predicted values.

Mathematically, the linear (or multiple) regression equation can be expressed as:

y=β0+β1x1+β2x2+⋯+βnxn+ϵy = \beta_0 + \beta_1x_1 + \beta_2x_2 + \cdots + \beta_nx_n + \epsilon

where:

  • yy is the dependent variable,

  • x1,x2,…,xnx_1, x_2, \ldots, x_n are the independent variables,

  • β0\beta_0 is the intercept,

  • β1,β2,…,βn\beta_1, \beta_2, \ldots, \beta_n are the coefficients of the independent variables,

  • ϵ\epsilon is the error term.

2.2 History and Evolution of the Concept

The concept of linear regression began with Sir Francis Galton, who introduced the term “regression” in an 1877 study on the inheritance of height. He observed that the heights of children tended to regress toward the mean height of their parents, a phenomenon he called “regression toward the mean” (Galton 1877).

Later, Karl Pearson expanded on Galton’s work and formalized the linear regression method. In 1896, Pearson applied the method of least squares to estimate regression coefficients, laying the foundation for modern linear regression (Pearson 1896).

In addition, Ronald A. Fisher made significant contributions to linear regression during the 1920s and 1930s, helping extend linear regression to include multiple independent variables (Fisher 1925)—namely, multiple regression. Fisher also introduced the concept of maximum likelihood, which further refined parameter estimation methods.

The introduction of advanced computational methods and the emergence of statistical software, such as R, Python, and Stata, made applying linear regression more accessible and powerful. This enabled the processing of large volumes of data and the use of linear regression across a broad range of scientific and industrial disciplines (Chambers 1992; McKinney 2010). See Figure 2.1 for a timeline of this evolution.

Timeline

Figure 2.1. Timeline

Python Python was created by Guido van Rossum and first released in 1991. Van Rossum began developing Python in the late 1980s as a successor to the ABC language. The goal was to create a programming language that was easy to understand and use, with clear and readable syntax. The name “Python” was chosen as a reference to the British comedy troupe Monty Python, of which Van Rossum was a fan. Since its release, Python has evolved significantly, with several versions released over the years, including the Python 2.x and Python 3.x series, the latter being the current standard recommended for new projects.

The R Language The R programming language emerged in the mid-1990s. It was created by Ross Ihaka and Robert Gentleman, two statisticians at the University of Auckland in New Zealand. Initial development of R began in 1992, and the first public version was released in 1995. R was designed as a language for statistics and data analysis, heavily influenced by the S language, which had been developed earlier at Bell Laboratories. One of R’s main strengths is its ability to provide a broad array of statistical and graphical tools, making it popular among statisticians, data scientists, and researchers across many disciplines. Since its release, R has expanded through contributions from an active community, leading to the development of countless packages that extend its capabilities.

2.3 Importance in Machine Learning

Linear regression (throughout this book we will often use just the term “linear regression,” or simply “regression,” though the same applies to multiple regression) is frequently used as a starting point for understanding more complex methods. Its simplicity and intuitive nature make it accessible to beginners, offering a clear way to grasp the linear relationship between independent and dependent variables (Mohri, Rostamizadeh, and Talwalkar 2018).

It is also used not only to predict outcomes, but also to understand the underlying relationships between variables (Hastie, Tibshirani, and Friedman 2009; James et al. 2013). This ability to interpret the model’s coefficients provides direct insights into the influence of each independent variable on the dependent variable. This is crucial in applications where model explainability is just as important as predictive accuracy (Hastie, Tibshirani, and Friedman 2009).

The computational efficiency of linear regression allows it to be applied to large and complex datasets. It serves as an effective baseline for comparison with more sophisticated models (Friedman, Hastie, and Tibshirani 2001). Finally, studying linear regression helps practitioners understand underlying statistical assumptions and the implications of violating them—an essential skill in data modeling (Montgomery, Peck, and Vining 2021).

2.4 Real-World Application Examples

Linear regression is a widely used statistical tool across diverse fields due to its simplicity and effectiveness in modeling relationships between variables. One of the most common applications of linear regression is predicting real estate prices. In this context, linear regression is used to estimate the price of a property based on features such as location, size, and number of bedrooms. This approach helps buyers and sellers gain a better understanding of a home’s market value by taking into account relevant factors that influence price. One key application of regression in real estate market analysis is property price valuation.

Another example is sales analysis in businesses. Organizations use linear regression to forecast future sales based on historical data. These forecasts support strategic decision-making, such as inventory planning and marketing campaigns. The ability to anticipate shifts in demand enables companies to adapt quickly to the market, improving operational efficiency and maximizing profits.

In the health sciences, linear regression plays a key role in analyzing clinical data. Researchers use this technique to explore the relationship between variables such as age, blood pressure, and cholesterol levels in order to identify disease risk factors. This type of analysis helps establish critical correlations for developing prevention and treatment strategies.

In engineering, linear regression is applied in quality control to predict the strength of materials based on their physical and chemical properties. This application helps ensure the safety and reliability of materials used in construction and manufacturing. By identifying the properties that affect material strength, engineers can optimize production processes and develop more robust materials.

Examples of Regression Applications

Real Estate Price Prediction: Linear regression can be used to predict the price of a house based on features such as location, size, and number of bedrooms.

Sales Analysis: Companies use linear regression to forecast future sales based on historical data, supporting strategic decision-making.

Health Sciences: Researchers use linear regression to analyze relationships among variables such as age, blood pressure, and cholesterol, helping identify risk factors for diseases.

Engineering: In quality control, linear regression can help predict the strength of materials based on their physical and chemical properties.

2.5 Advantages and Limitations

One of the main advantages of linear regression is its simplicity and ease of interpretation. It is an easy-to-implement technique, allowing even users without an advanced background in statistics to quickly understand relationships between variables. This makes linear regression an accessible and widely adopted tool across many fields of knowledge.

In addition, linear regression is computationally efficient, as it requires fewer resources compared to more complex models. This efficiency makes it well suited for analyzing large datasets, where speed and resource economy are critical.

Finally, linear regression serves as a foundation for more complex Machine Learning models. It provides an initial understanding of the data, enabling researchers and analysts to build more sophisticated models—such as polynomial regression and neural networks—on top of this groundwork. This makes linear regression a crucial first step in the data modeling and analysis process.

However, it is important to recognize the limitations of linear regression. It assumes a linear relationship between variables, which does not always reflect the complexity of real-world interactions. Moreover, the presence of outliers can distort the results, making the model less accurate. Therefore, it is essential for analysts to take these limitations into account when using linear regression in research and professional practice.

Advantages and Limitations

Advantages

Simplicity and Interpretability: Easy to implement and interpret, allowing users to quickly understand relationships between variables.

Computational Efficiency: Requires fewer computational resources compared to more complex models.

Foundation for Complex Models: Serves as a foundation for understanding and developing more advanced Machine Learning models.
Limitations

Linearity: Assumes that the relationship between variables is linear, which may not hold true for all datasets.

Sensitivity to Outliers: Outliers can significantly influence the results of linear regression.

Independence Assumption: Assumes that the independent variables are truly independent of one another, which may not always be the case.