pub fn polyfit_py(
py: Python<'_>,
x: &Bound<'_, PyArray1<f64>>,
y: &Bound<'_, PyArray1<f64>>,
deg: usize,
) -> PyResult<Py<PyAny>>Expand description
Fit a polynomial of specified degree to data.
Fits a polynomial p(x) = c[0] + c[1]*x + c[2]*x^2 + … + c[deg]*x^deg using least squares regression.
Parameters: x: Independent variable data (1D array) y: Dependent variable data (1D array, same length as x) deg: Degree of the fitting polynomial
Returns: Dictionary containing: - coefficients: Polynomial coefficients (c[0], c[1], …, c[deg]) - r_squared: Coefficient of determination - adj_r_squared: Adjusted R-squared - residuals: Residual values (y - fitted) - fitted_values: Fitted (predicted) y values
Example: >>> import scirs2 >>> x = [0, 1, 2, 3, 4] >>> y = [1, 3, 9, 19, 33] # y ≈ 1 + 2x + x^2 >>> result = scirs2.polyfit(x, y, deg=2) >>> print(result[“coefficients”]) # Should be close to [1, 2, 1]
TODO: Registration issue - function compiles but doesn’t register with PyO3 See /tmp/scirs2_session10_polyfit_issue.md for details