# PolyFit class Null safety

The PolynomialRegression class performs a polynomial regression on an set of N data points (yi, xi). That is, it fits a polynomial y = β0 + β1 x + β2 x2 + ... + βd xd (where y is the response variable, x is the predictor variable, and the βi are the regression coefficients) that minimizes the sum of squared residuals of the multiple regression model. It also computes associated the coefficient of determination R2. This implementation performs a QR-decomposition of the underlying Vandermonde matrix, so it is neither the fastest nor the most numerically stable way to perform the polynomial regression.

1. "Polynomial regression". https://en.wikipedia.org/wiki/Polynomial_regression. Retrieved 2019-07-22.
2. "Polynomial regression". //https://rosettacode.org/wiki/Polynomial_regression#C_sharp. Retrieved 2019-07-22.
3. "polynomial.py". https://github.com/numpy/numpy/blob/v1.15.0/numpy/lib/polynomial.py#L393-L606. Retrieved 2019-07-22.
4. "numpy.polyfit". https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.polyfit.html. Retrieved 2019-07-22.
5. "Princeton Analysis Polynomial Regression". https://algs4.cs.princeton.edu/14analysis/PolynomialRegression.java.html. Retrieved 2019-07-22.

# Examples

``````const int degree = 2;
var x = Array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]);
var y = Array([1.0, 6.0, 17.0, 34.0, 57.0, 86.0, 121.0, 162.0, 209.0, 262.0, 321.0]);
var p = PolyFit(x, y, degree);

print(p);

/*
2.999999999999736 x^2 +  2.0000000000002807 x +  1.0000000000000122   (R^2 = 0.9922700105981427)
*/
``````