Polynomial regression
Description:
In statistics, linear regression is a technique of fitting a straight line to given data points so that average square error is minimal. By extension polynomial regression is fitting nth degree polynomial which minimizes square error.
In this kata you will try to write a polynomial regression solver which finds nth degree polynomial to fit n+1 data points. Since you will always have n+1 data points, your polynomial function will fit all data points perfectly - you will be looking for a unique least squares solution rather than doing optimisation.
Let's look at some simple examples:
If you're given two data points {x: -1, y: -1} and {x: 1, y: 1}, 1st degree polynomial that fits these point perfectly is f(x) = x.
If you're given three data points {x: -1, y: 1}, {x: 0, y: 0} and {x: 2, y: 4}, polynomial f(x) = x^2 would fit them perfectly.
So, your task is to write function solveRegression. It will accept an array of data points as such:[{x: -1, y: -1}, {x: 0, y: 5}, ...]
Your method should return a string of following form: f(x) = 2x^2 - x + 1.5
. Please note the following rules for result formatting:
- All coefficients should be rounded to 5 decimal places
- If a given coefficient is 0, the term should be ignored, i.e.
f(x) = 0x + 5
is invalid (should bef(x) = 5
- Negative coefficients should be formatted as follows:
f(x) = - 5x - 1
P.S. Please suggest rank for this kata, I was not sure 4 kyu is suitable.
Similar Kata:
Stats:
Created | Apr 24, 2015 |
Published | Apr 24, 2015 |
Warriors Trained | 118 |
Total Skips | 23 |
Total Code Submissions | 141 |
Total Times Completed | 15 |
JavaScript Completions | 15 |
Total Stars | 4 |
% of votes with a positive feedback rating | 80% of 5 |
Total "Very Satisfied" Votes | 3 |
Total "Somewhat Satisfied" Votes | 2 |
Total "Not Satisfied" Votes | 0 |
Total Rank Assessments | 6 |
Average Assessed Rank | 5 kyu |
Highest Assessed Rank | 3 kyu |
Lowest Assessed Rank | 6 kyu |