Given a set of coordinates in the form of (X, Y), the task is to find the least regression line that can be formed.
In statistics, Linear Regression is a linear approach to model the relationship between a scalar response (or dependent variable), say Y, and one or more explanatory variables (or independent variables), say X.
Regression Line: If our data shows a linear relationship between X and Y, then the straight line which best describes the relationship is the regression line. It is the straight line that covers the maximum points in the graph.
Input: X = [95, 85, 80, 70, 60]
Y = [90, 80, 70, 65, 60]
Output: Y = 5.685 + 0.863*X
The graph of the data given below is:
X = [95, 85, 80, 70, 60]
Y = [90, 80, 70, 65, 60]
The regression line obtained is Y = 5.685 + 0.863*X
The graph shows that the regression line is the line that covers the maximum of the points.
Input: X = [100, 95, 85, 80, 70, 60]
Y = [90, 95, 80, 70, 65, 60]
Output: Y = 4.007 + 0.89*X
A regression line is given as Y = a + b*X where the formula of b and a are given as:
b = (nΣ(xiyi) – Σ(xi)Σ(yi)) ÷ (nΣ(xi2)-Σ(xi)2)
a = ȳ – b.x̄
where x̄ and ȳ are mean of x and y respectively.
- To find regression line, we need to find a and b.
- Calculate a, which is given by
- Calculate b, which is given by
- Put value of a and b in the equation of regression line.
Below is the implementation of the above approach.
Regression line: Y = 5.685 + 0.863*X
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Slope of the line parallel to the line with the given slope
- Equation of straight line passing through a given point which bisects it into two equal line segments
- Least number to be added to or subtracted from N to make it a Perfect Square
- Count square and non-square numbers before n
- Check if a number is perfect square without finding square root
- Smallest N digit number whose sum of square of digits is a Perfect Square
- Find smallest perfect square number A such that N + A is also a perfect square number
- Check if a number is a perfect square having all its digits as a perfect square
- Find the subarray with least average
- Smallest number with at least n trailing zeroes in factorial
- Smallest number with at least n digits in factorial
- Probability of getting at least K heads in N tosses of Coins
- Nearest element with at-least one common prime factor
- Smallest number divisible by n and has at-least k trailing zeros
- Least Common Denominator (LCD)
- Count divisors of n that have at-least one digit common with n
- Convert a number of length N such that it contains any one digit at least 'K' times
- Check if at least half array is reducible to zero by performing some operations
- Least Greater number with same digit sum
- Count pairs in an array such that frequency of one is at least value of other
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.