Predicts the y value for a given x.
double predict(double x) { double result = 0; double xPower = 1; for (final coef in coefficients) { result += coef * xPower; xPower *= x; } return result; }