Linear Regression of Y on X
Description:
Background:
A linear regression line has an equation in the form , where is the explanatory variable and is the dependent variable. The parameter represents the slope of the line, while is called the intercept (the value of when ).
For more details visit the related wikipedia page.
Task:
The function that you have to write accepts two list/array, and , representing the coordinates of the points to regress (so that, for example, the first point has coordinates (x[0], y[0]
)).
Your function should return a tuple (in Python) or an array (any other language) of two elements: a
(intercept) and b
(slope) in this order.
You must round your result to the first 4 decimal digits
Formula:
and is and co-ordinate of -th point;
is length of input.
Examples:
regressionLine([25,30,35,40,45,50], [78,70,65,58,48,42]) == (114.381, -1.4457)
regressionLine([56,42,72,36,63,47,55,49,38,42,68,60], [147,125,160,118,149,128,150,145,115,140,152,155]) == (80.7777, 1.138)
Similar Kata:
Stats:
Created | Mar 27, 2015 |
Published | Mar 27, 2015 |
Warriors Trained | 2922 |
Total Skips | 278 |
Total Code Submissions | 4039 |
Total Times Completed | 1629 |
Python Completions | 1363 |
JavaScript Completions | 227 |
Ruby Completions | 75 |
Total Stars | 95 |
% of votes with a positive feedback rating | 92% of 181 |
Total "Very Satisfied" Votes | 156 |
Total "Somewhat Satisfied" Votes | 22 |
Total "Not Satisfied" Votes | 3 |