Terraflux Terraflux
Download

Machine learning

5 operators. Inputs marked required must be connected or given; the others have defaults.

ml.fit#

A random forest or a histogram gradient boosting fitted to records (scikit-learn's RandomForestClassifier and HistGradientBoostingClassifier for classes, their regressors for values, the same trees): the rows of a table, or the cells of maps (the predictors a stack, the target a map; a sample of the cells, drawn as numpy's default_rng(seed) draws it). Its predictors' importances: a forest's mean decrease of impurity, a boosting's share of the gain of its splits.

InputTypeWhat it is
tabletablethe records: the predictors and the target, a column each
predictorsstackor maps: a layer per predictor (stack.of)
targetmapwith maps: the classes or values to learn
cellsmapwith maps: the cells to learn from (non-zero; default all)
OutputTypeWhat it is
modelml_modelthe fitted forest
importancetablethe importance of each predictor (they add up to 1)
SettingTypeWhat it is
columntextwith a table: the target's column (default target)
columnsanywith a table: the predictors' columns (default: all but the target's)
tasktextclasses or values; auto (default): classes when the target holds 50 whole numbers or fewer
samplenumberthe records to learn from: a number (1 or more) or a share (below 1) drawn at random (default all)
stratifybooldraw the sample from each class apart (default false)
seedintegerthe seed of the sample's draw (numpy's; default 1)
methodtextrandom_forest (default; scikit-learn's RandomForest) or gradient_boosting (its HistGradientBoosting, without early stopping)
n_estimatorsintegerrandom_forest: the trees (default 100)
max_depthintegerthe trees' depth at most (default none)
min_samples_splitintegerrandom_forest: the records a node needs to split (default 2)
min_samples_leafintegerthe records of a leaf at least (default: 1 for a forest, 20 for boosting)
max_featuresanythe predictors tried at each split: sqrt, log2, all, a number or a share (default: sqrt for classes, all for values, as scikit-learn); gradient_boosting: a share (default 1)
bootstrapboolrandom_forest: each tree on a bootstrap (default true)
learning_ratenumbergradient_boosting: the shrinkage of the leaves (0.1)
max_iterintegergradient_boosting: the iterations (100)
max_leaf_nodesintegergradient_boosting: the leaves of a tree at most (31; null for no limit)
l2_regularizationnumbergradient_boosting: the leaves' L2 penalty (0)
max_binsintegergradient_boosting: the bins of a predictor, 2-255 (255)
random_stateintegerscikit-learn's seed of the model (default 0)

ml.importance#

The permutation importance of each predictor of a fitted model (scikit-learn's permutation_importance, the same numbers): how much its score (a classifier's accuracy, a regressor's R²) drops when the predictor's values are shuffled among the records, shuffle after shuffle (numpy's RandomState); best on records the model did not learn from.

InputTypeWhat it is
modelrequiredml_modelthe fitted model (ml.fit)
tablerequiredtablethe records: the predictors and the target, a column each
OutputTypeWhat it is
importancetablethe mean drop of the score, a column per predictor
sdtableits standard deviation over the shuffles
repeatstablethe drop at every shuffle: repeat, then a column per predictor
scorenumberthe score on the records as they are
SettingTypeWhat it is
columntextthe target's column (default target)
n_repeatsintegerthe shuffles of each predictor (default 5)
random_stateintegerthe seed of the shuffles (default 0)

ml.partial_dependence#

How a fitted model's prediction follows a predictor (scikit-learn's partial_dependence, its brute method): every record with the predictor set to each value of a grid (its distinct values when fewer than the grid's resolution, else from one percentile of it to another, as scipy's mquantiles), the predictions averaged: the value of a regressor, the probability of each class of a classifier (the second of two).

InputTypeWhat it is
modelrequiredml_modelthe fitted model (ml.fit)
tablerequiredtablethe records, a column per predictor
OutputTypeWhat it is
tabletablea row per value of the grid: the predictor's value, then the mean prediction (value, or p_)
SettingTypeWhat it is
predictorrequiredtextthe predictor followed
grid_resolutionintegerthe values of the grid (default 100)
percentilesanythe grid's ends, as shares (default [0.05, 0.95])

ml.potential#

The potential of each class from a model per class (landschaft's Estimator with scikit-learn's RandomForestClassifier, or HistGradientBoostingClassifier, the same maps): where each class is (presence, as lulcc's models), or where it appeared between two maps among the cells without it (expansion: PLUS's land expansion analysis, LEAS, the growth probability CARS takes); with each driver's contribution (the models' importances).

InputTypeWhat it is
landscaperequiredmapthe map at the start
latermapthe later map (expansion)
driversrequiredstackthe explanatory variables, a layer each
cellsmapthe cells to learn from (non-zero; default all)
OutputTypeWhat it is
potentialstackthe probability of each class (of its presence, or of its expansion), where the drivers have values
importancetablea row per class: class, then each driver's contribution (they add up to 1)
modelml_modelthe forests, for ml.predict on other drivers
SettingTypeWhat it is
targettextexpansion (where the class appeared; needs the later map) or presence (where it is); default: expansion with a later map, else presence
classesanythe classes to model (default: those of the maps)
samplenumberthe cells each class's forest learns from: a number (1 or more) or a share (below 1) drawn at random (default all)
stratifybooldraw the sample from the presences and the absences apart, in their proportions (default false)
balanceboolas many absences as presences (default false)
seedintegerthe seed of the draws (numpy's default_rng; default 1)
methodtextrandom_forest (default; scikit-learn's RandomForest) or gradient_boosting (its HistGradientBoosting, without early stopping)
n_estimatorsintegerrandom_forest: the trees (default 100)
max_depthintegerthe trees' depth at most (default none)
min_samples_splitintegerrandom_forest: the records a node needs to split (default 2)
min_samples_leafintegerthe records of a leaf at least (default: 1 for a forest, 20 for boosting)
max_featuresanythe predictors tried at each split: sqrt, log2, all, a number or a share (default: sqrt for classes, all for values, as scikit-learn); gradient_boosting: a share (default 1)
bootstrapboolrandom_forest: each tree on a bootstrap (default true)
learning_ratenumbergradient_boosting: the shrinkage of the leaves (0.1)
max_iterintegergradient_boosting: the iterations (100)
max_leaf_nodesintegergradient_boosting: the leaves of a tree at most (31; null for no limit)
l2_regularizationnumbergradient_boosting: the leaves' L2 penalty (0)
max_binsintegergradient_boosting: the bins of a predictor, 2-255 (255)
random_stateintegerscikit-learn's seed of the model (default 0)

ml.predict#

A fitted model (ml.fit, ml.potential) on maps or on the rows of a table: the value, or the class of the largest probability (the first on ties, as scikit-learn's predict) and the probability of each class (a forest's predict_proba, or each class's potential). No value where a predictor has none.

InputTypeWhat it is
modelrequiredml_modelthe fitted model
predictorsstackmaps: a layer per predictor, named as in the fit
tabletableor the rows of a table, a column per predictor
OutputTypeWhat it is
mapmapwith maps: the value, or the class of the largest probability
probabilitystackwith maps: the probability of each class
tabletablewith a table: its columns, then prediction and the probability of each class (p_)