Self-paced

Explore our extensive collection of courses designed to help you master various subjects and skills. Whether you're a beginner or an advanced learner, there's something here for everyone.

Bootcamp

Learn live

Upcoming live events

Learning library

For all the self-taught geeks out there, here is our content library with most of the learning materials we have produced throughout the years.

It makes sense to start learning by reading and watching videos about fundamentals and how things work.

Search from all Lessons

# Learn Linear regression

Lessons, exercises, and projects about Linear regression

To better understand what a **linear regression** is, imagine you have a group of points on a graph. These points represent some relationship between two things. For example, they could be the hours you study and the grades you get on an exam. Linear regression tries to find a straight line that passes as close as possible to all those points. This line is called the "regression line." ## Why represent regression as a line? We use a line because it is the simplest way to show a relationship between two things. If study hours and grades are related, a line can give us a general idea of how one thing changes when the other changes. ## Basic components of linear regression 1. **Variables**: - **Independent variable (X)**: This is what you control. In our example, it would be the hours of study. - **Dependent variable (Y)**: This is what you want to predict or explain. In our example, it would be the exam grade. 2. **Line of best fit**: This line is drawn in such a way that the sum of the vertical distances from all the points to the line is as small as possible. ## Simple example Suppose you have this data: - 1 hour of study -> 60 points on the exam - 2 hours of study -> 70 points on the exam - 3 hours of study -> 80 points on the exam - 4 hours of study -> 90 points on the exam If you plot these on a graph, the points would be almost in a straight line. Linear regression would find that line that passes through these points. ## The formula of the line The regression line can be described with a simple mathematical formula: $Y = a + bX$ Where: - **Y** is the grade we want to predict. - **a** is the point where the line crosses the Y-axis (when X is 0). - **b** is the slope of the line, which tells us how much Y changes when X changes. ## What is it for? Linear regression is used to predict values. For example, if you want to know what grade you might get if you study for 5 hours, you can use the formula of the line. It is also used to understand the relationship between two variables.

### .css-9jay18{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:row;-ms-flex-direction:row;flex-direction:row;-webkit-box-pack:justify;-webkit-justify-content:space-between;justify-content:space-between;}.css-62m12w{transition-property:var(--chakra-transition-property-common);transition-duration:var(--chakra-transition-duration-fast);transition-timing-function:var(--chakra-transition-easing-ease-out);cursor:pointer;-webkit-text-decoration:none;text-decoration:none;outline:2px solid transparent;outline-offset:2px;color:inherit;}.css-62m12w:hover,.css-62m12w[data-hover]{-webkit-text-decoration:underline;text-decoration:underline;}.css-62m12w:focus-visible,.css-62m12w[data-focus-visible]{box-shadow:var(--chakra-shadows-outline);}.css-62m12w::after{content:"";position:absolute;inset:0px;}What is a Linear Regression and how to use it in machine learning models

Discover the power of linear regression, a model that predicts outcomes based on one or more variables. Learn about its five key assumptions and how it can help you understand relationships between data points. Dive into simple and multiple linear regression to enhance your data analysis skills.

2hrs average

### Build a linear regression model using pandas and python

Learn how to build a linear regression model from scratch: understand a new dataset, perform exploratory data analysis (EDA), model the data, and optimize your model. Discover how the $R^2$ evolves by adjusting the Lasso model's hyperparameter up to a value of 20.