ml.random_forest

Random forest regression or classification (scikit-learn). Writes a SpadeModel with an ONNX graph that models.predict scores without Python; before the model is written, the graph scores the training rows and must agree with the fitted forest, or the block fails. Reports out-of-bag metrics, and cross-validated metrics on request. Declares 8 GiB of memory: the training table is held in memory, so sample very large tables upstream.

  • 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.
targetstringThe response column.
featuresstringColumn selector for the predictors: names, globs and exclusions, e.g. B*,MB*,-B0.
taskstringregression (default) predicts a number; classification predicts the target's classes, with a probability for each.
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 numeric-coded predictors to treat as categorical. Categoricals are one-hot encoded, one column per level. 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.
seednumberSeed for the model's randomness and for fold assignment; the same seed gives the same model. Default 0.
cv_foldsnumberK-fold cross-validation (0 for none). The model is always fitted on all rows. Default 0.
cv_groupstringColumn whose values are kept together in one fold (e.g. a county id), so spatially related rows do not leak between folds. Default empty.
n_estimatorsnumberNumber of trees. Default 500.
max_depthnumberMaximum tree depth. Leave empty (the default) for fully grown trees.
min_samples_leafnumberMinimum rows in a leaf. Default 1.
max_featuresstringFeatures considered at each split: 1.0 (default, all features), sqrt or log2.
n_jobsnumberParallel jobs; 0 (default) uses every CPU the sandbox grants.

Outputs🔗

NameTypeDescription
modelfile (SpadeModel)The fitted model with its ONNX graph, for models.predict.
fitjsonRows used and dropped, the arguments that shaped the fit, and metrics: rmse, mae, r_squared (regression) or accuracy, log_loss (classification), plus oob_r_squared or oob_accuracy, with cv_ versions when cross-validated.

Example🔗

- id: "@fit"
  name: ml.random_forest
  inputs:
    - "@plots"
  args:
    target: "biomass_tons_per_acre"
    features: "elevation_m,canopy_cover_pct,stand_age,terrain,forest_type"
    cv_folds: 4
    cv_group: "county"