alsdb.processing.biomass.wrap_sklearn_model#
- alsdb.processing.biomass.wrap_sklearn_model(estimator, features: list[str] | None = None) Callable[source]#
Wrap a fitted scikit-learn estimator as a
model_fnforcompute_biomass.Handles the reshaping between the per-cell metric dict used internally and the
(n_samples, n_features)matrix expected by sklearn, and masks NaN pixels so they are never passed topredict().- Parameters:
estimator – Any fitted sklearn-compatible estimator that exposes a
predict(X)method (e.g.RandomForestRegressor,GradientBoostingRegressor,Pipeline, …).features – Ordered list of metric names to use as model features. Defaults to all sixteen standard metrics (
_METRIC_NAMES): height percentiles, canopy cover, density, FHD, VCI, CRR, and the six height-stratum proportions. The order must match the feature order used during training. Pass an explicit list (e.g.["h50", "h95", "cc"]) when the model was trained on a subset.
- Returns:
A function
model_fn(metrics) → np.ndarraycompatible with themodel_fnparameter ofcompute_biomass.- Return type:
Callable
Examples
from sklearn.ensemble import RandomForestRegressor from alsdb.processing.biomass import compute_biomass, wrap_sklearn_model rf = RandomForestRegressor(n_estimators=200) rf.fit(X_train, y_train) # X columns must match _METRIC_NAMES order model_fn = wrap_sklearn_model(rf) compute_biomass(provider, store, resolution=10.0, year=2021, model_fn=model_fn)