## Table of contents

**Introduction**

Linear regression stands as one of the foundational algorithms in the realm of machine learning. It serves as a cornerstone for understanding more complex models and techniques. Let's delve into what linear regression is, its types, assumptions, real-world applications, and its mathematical formulation.

**What is Linear Regression?**

Linear regression is a statistical method used to model the relationship between a dependent variable (often denoted as ๐ฆ*y*) and one or more independent variables (denoted as ๐ฅ*x*). The relationship is assumed to be linear, hence the name. The goal is to find the best-fitting line that describes the relationship between the variables.

**Importance in Machine Learning**

Linear regression serves various purposes in machine learning:

**Prediction**: It's widely used for predictive analysis. By understanding the relationship between variables, we can predict future outcomes.**Inference**: Linear regression helps in understanding the relationships between variables. For example, how does an increase in temperature affect sales?**Model Evaluation**: It serves as a benchmark for evaluating the performance of other algorithms.**Feature Engineering**: It helps identify which features are most relevant in predicting the target variable.

**Types of Linear Regression**

**Simple Linear Regression**: It involves only one independent variable. The relationship between the independent and dependent variables is approximated by a straight line.**Multiple Linear Regression**: It involves two or more independent variables. The relationship between the independent variables and the dependent variable is linear.

**Assumptions of Linear Regression**

Linear regression relies on several assumptions:

**Linearity**: The relationship between the independent and dependent variables is linear.**Independence**: The residuals (the differences between observed and predicted values) are independent of each other.**Homoscedasticity**: The variance of the residuals is constant across all levels of the independent variables.**Normality**: The residuals are normally distributed.**No Multicollinearity**: In multiple linear regression, the independent variables are not highly correlated with each other.

**Applications of Linear Regression**

Linear regression finds applications in various fields:

**Economics**: Predicting sales based on advertising expenditure.**Finance**: Predicting stock prices based on various factors.**Healthcare**: Predicting patient recovery time based on medical history.**Marketing**: Estimating the impact of marketing campaigns on sales.

**Mathematical Formulation**

The simple linear regression model can be represented as:

๐ฆ=๐ฝ0+๐ฝ1๐ฅ+๐*y*\=*ฮฒ*0โ+*ฮฒ*1โ*x*+*ฯต*

Where:

๐ฆ

*y*is the dependent variable.๐ฅ

*x*is the independent variable.๐ฝ0

*ฮฒ*0โ is the intercept.๐ฝ1

*ฮฒ*1โ is the slope coefficient.๐

*ฯต*is the error term.

For multiple linear regression, the equation extends to include multiple independent variables:

๐ฆ=๐ฝ0+๐ฝ1๐ฅ1+๐ฝ2๐ฅ2+...+๐ฝ๐๐ฅ๐+๐*y*\=*ฮฒ*0โ+*ฮฒ*1โ*x*1โ+*ฮฒ*2โ*x*2โ+...+*ฮฒn*โ*xn*โ+*ฯต*

Where:

๐ฅ1,๐ฅ2,...,๐ฅ๐

*x*1โ,*x*2โ,...,*xn*โ are the independent variables.๐ฝ1,๐ฝ2,...,๐ฝ๐

*ฮฒ*1โ,*ฮฒ*2โ,...,*ฮฒn*โ are the coefficients.

### Example

you can get it from my github here is the link:-

https://github.com/Prajwal18-MD/Student_performance

here is the code snippet

here is the output:-

**Conclusion**

Linear regression serves as a fundamental tool in understanding relationships between variables, making predictions, and deriving insights from data. Its simplicity, interpretability, and wide applicability make it an indispensable tool in the arsenal of a machine learning practitioner. Understanding its principles lays a solid foundation for exploring more advanced techniques in the field.