OLS illustrates the package’s basic binding pattern: PyO3 exposes a Rust class, NumPy arrays cross the boundary, Rust performs the numerical work, and results return as arrays in a Python dictionary. See the class reference for covariance options and signatures.
fit(x, y) clears the previous fitted state and validates finite arrays, compatible row counts, and a usable design.
NumPy inputs are copied into owned Rust arrays. The public OLS() constructor includes an intercept; it has no fit_intercept argument.
A QR least-squares solve obtains the parameters. The wrapper separates the intercept and slopes and retains data needed for inference and resampling.
predict(x_new) checks the fitted feature count and finite values before forming the linear prediction.
Do not interpret a failed refit as leaving an earlier fit available. Python argument-conversion errors occur before Rust entry and are a separate boundary.
Covariance and weights
The point estimate minimizes squared residuals. summary() selects classical, HC0–HC3, Newey-West, or cluster covariance without refitting coefficients. The inverse Gram factor used in covariance is obtained from QR rather than explicitly forming and inverting the normal equations.
fit_weighted() uses square-root transformed rows and analytic weights. Zero-weight rows are excluded from inference counts; zero-only clusters do not increase the cluster count. HAC lags refer to the active-row sequence. These weights are not frequency counts or a survey-design specification.
Bootstrap draws resample stored rows and solve the same least-squares problem. Indices are generated one draw at a time, so they do not require a full n_bootstrap by n index matrix.
fit_sketch() is a separate approximate fitting path. Its summary reports the fit method, sketch size, and seed. A reported covariance is not a proof that sketching preserves interval coverage; see the sketching ablation.