models.linear

Linear regression by least squares on a table of any size: one streaming pass accumulates the QR factor of the weighted design, a second computes the residual statistics, so memory does not depend on the number of rows (20 million rows fit in about 50 MB). It fits the model stats.lm fits -- the same design columns, coefficients, covariance and statistics, tested to agree to 1e-9 -- and writes the same linear model for models.predict.

Formulas follow R's rules for expansion, ordering and coding of categoricals. Nesting (/, %in%) and cross-validation are not offered; use stats.lm for tables that fit in memory and need them. A collinear design fails, naming the column, rather than dropping it.

  • Kind: standard
  • Network: no

Inputs🔗

NameTypeDescription
datafile (Parquet or CSV)Training table: one row per observation, with the target, the predictor columns, and any weights or id columns.
formulastringModel formula, e.g. ESTIMATE ~ B5 + log(B25) + FORTYPE + 0. Use instead of target and features. Default empty.
targetstringThe response column (when no formula is given). Default empty.
featuresstringColumn selector for the predictors (when no formula is given): names, globs and exclusions, e.g. B*,MB*,-B0. Default empty.
interceptbooleanInclude an intercept when building the model from target and features. With a formula, write + 0 in the formula instead. Default true.
id_columnsstringColumn selector for identifier columns, never used as predictors; kept as text when reading CSV. Default empty.
weightsstringColumn of non-negative observation weights. Empty fits unweighted.
categoricalstringColumn selector for predictors to treat as categorical even though they are stored as numbers. Default empty.
na_actionstringfail (default, naming the columns) or drop: what to do with a row that has a missing value in a model column.

Outputs🔗

NameTypeDescription
modelfile (SpadeModel)The fitted model (family linear), for models.predict.
coefficientsfile (CSV)One row per design column: term, estimate, std_error, statistic, p_value.
fitjsonRows used and dropped, the arguments that shaped the fit, and metrics: rmse, mae, r_squared, adj_r_squared, aic, bic, sigma, df_residual.

Example🔗

- id: "@fit"
  name: models.linear
  inputs:
    - "@pixels"
  args:
    target: "biomass"
    features: "B*,MB*"