Results

Every fit returns a result that holds the working directory’s trees and binned data until it is closed: see Memory, disk and threads.

class forest_stream.CausalForestResult[source]

A fitted causal forest. See ForestResult.

Besides predict and oob_predictions, it estimates the average treatment effect with average_treatment_effect.

plot(kind=None, *, ax=None, title=None, **options)[source]

Draw a picture of the effects with matplotlib, which is not a dependency (pip install forest-stream[plot]).

Parameters:
  • kind (str, optional) – "effects" (the default): a histogram of the out-of-bag effect estimates, with the average effect and its interval. "heterogeneity": the mean estimate against a feature (feature=; default the most important one), in groups= (20) groups of rows of equal weight, and the average. The bars are 1.96 standard errors of each group’s mean estimate (from the spread of the estimates in the group), not intervals for the group’s true effect. "importance": bars of variable_importance. "calibration": the two coefficients of calibration_test with intervals, against their ideal value of one. "projection": the coefficients of best_linear_projection (data=, which it needs, and terms=) with intervals.

  • ax (matplotlib.axes.Axes, optional) – Draw here instead of on a new figure.

  • title (str, optional)

Returns:

matplotlib.figure.Figure

__init__(fml, formula, engine, centering_s, options)[source]
oob_predictions(variance=None, n_threads=None)[source]

See ForestResult.oob_predictions. The estimates are computed once and kept in the run directory.

average_treatment_effect(n_threads=None)[source]

The average of the treatment effect over the training rows, with a standard error.

Each row’s score is its out-of-bag effect estimate plus a correction from its residual: tau_i + (w_i / v_i) (y_i - tau_i w_i), with y_i and w_i the residualized outcome and treatment, and v_i an estimate of the variance of w_i given the features (a regression forest of the squared residualized treatment). The average of the scores is the estimate; its standard error is that of a mean of the scores, clustered when the forest was fitted with cluster=. With sample weights the average is weighted, and its standard error is that of a weighted mean: sqrt(m / (m - 1) sum(w^2 (score - estimate)^2)) / sum(w) for m rows.

For an instrumental forest the score is tau_i + (z_i / c_i) (y_i - tau_i w_i), with z_i the residualized instrument and c_i an estimate of the covariance of w_i and z_i given the features (at least a tenth of its average in size, with its sign), and the average is of the local effects: each row’s effect among the rows its instrument moves.

Returns:

TreatmentEffect

best_linear_projection(data, terms=None, vcov=None, n_threads=None)[source]

The best linear projection of the treatment effect on features: the regression of each row’s doubly robust score (see average_treatment_effect) on an intercept and terms. It tells how the average effect differs with the terms, without assuming that the effect is linear in them.

Parameters:
  • data (str, polars.DataFrame or polars.LazyFrame) – The data the forest was fitted on (the same rows in the same order), with the columns of terms. The terms’ columns are read into memory for the rows that were fitted.

  • terms (list of str, optional) – Columns to project on. Default: the forest’s features.

  • vcov (str or dict, optional) – The variance estimator, spelled as in hdfe-stream: "HC0", "HC1" (or "hetero"), "HC2" or "HC3", or the forest’s clustering as {"CRV1": "school"} (or "CRV1:school"), with the column the forest was fitted with as cluster=; the names are case-insensitive. CRV1 has hdfe-stream’s small-sample factor, G/(G-1) (n-1)/(n-k), and its p-values use G-1 degrees of freedom. Default "HC3", or CRV1 by the forest’s clusters when it was fitted with cluster=.

  • n_threads (int, optional)

Returns:

LinearProjection – Coefficients Intercept and one per term.

calibration_test(vcov=None, n_threads=None)[source]

A test of whether the forest’s effect estimates are well calibrated (the test of Chernozhukov, Demirer, Duflo and Fernandez-Val’s best linear predictor, as grf runs it). It regresses the residualized outcome on the residualized treatment times the average out-of-bag estimate (mean.forest.prediction) and times the estimate’s deviation from that average (differential.forest.prediction).

With sample weights the regression is weighted, and the average estimate is a weighted mean.

A coefficient of one on the first means the average effect is right. A coefficient of one on the second means the heterogeneity is right; a positive coefficient (significant, in a one-sided test: halve the p-value of a positive estimate) means the forest found heterogeneity that is there; zero means it found none.

Parameters:
Returns:

LinearProjection

classmethod __new__(*args, **kwargs)
close()

Delete the run directory. The forest cannot predict afterwards.

predict(data, variance=None, n_threads=None, *, include_fixed_effects=False, new_groups='error', keep=None, output=None, batch_rows=None)

Predictions at the rows of data, read and predicted in batches, so that only a batch’s features, and the predictions, are in memory (and with output, not even those).

Parameters:
  • data (str, polars.DataFrame or polars.LazyFrame) – A Parquet path or glob, or a frame, with the feature columns.

  • variance (bool, optional) – Also return each estimate’s variance (little-bags, with a debiasing correction). Default: when variance_group_size is above 1, which it needs to be.

  • n_threads (int, optional) – Threads for the compiled passes. Default: all that the job may use.

  • include_fixed_effects (bool, default False) – For a forest fitted with fixed effects ("backfit" or "outcome_within"), add each row’s group effects to its prediction, which is otherwise net of them: prediction is then the forest’s estimate plus the effects, and fixed_effect is the effects’ sum. The data need the fixed-effect columns. The variance is the forest’s, and does not allow for the error in the effects.

  • new_groups ({"error", "nan", "zero"}, default "error") – With include_fixed_effects, what to do with a row whose group was not in the data the forest was fitted on: raise an error, give it a missing prediction, or give it a zero effect.

  • keep (list of str, optional) – Columns of data to carry into the output, in front of the predictions (an identifier, say).

  • output (str or path, optional) – Write the predictions to this Parquet file, batch by batch, and return its path, instead of returning them.

  • batch_rows (int, optional) – Rows per batch. Default 250,000.

Returns:

polars.DataFrame or pathlib.Path – One row per row of data: any keep columns, the estimate (tau for a causal forest, prediction for a regression forest, or class and prob_<label> for a classification forest), with variance its variance (variance_<label>), and with include_fixed_effects fixed_effect. With output, the path.

summary()

Print summary_text.

summary_text()

The fit’s description as text.

variable_importance(decay_exponent=2.0, max_depth=4)

How much the trees split on each feature: the share of splits on it at each depth, over the trees’ first max_depth levels, averaged with weights proportional to depth ** -decay_exponent (so splits near the root count most). The importances sum to one.

Returns:

polars.DataFrame – feature and importance, in the order of the formula (with the groups’ feature means last, for fixed_effects="group_means").

class forest_stream.InstrumentalForestResult[source]

A fitted instrumental forest: estimates of the effect of the treatment among the rows that the instrument moves, as a function of the features. See CausalForestResult, whose methods work on the instrument’s local effects; instrument names the instrument.

calibration_test is not available.

__init__(fml, formula, engine, centering_s, options)
classmethod __new__(*args, **kwargs)
average_treatment_effect(n_threads=None)

The average of the treatment effect over the training rows, with a standard error.

Each row’s score is its out-of-bag effect estimate plus a correction from its residual: tau_i + (w_i / v_i) (y_i - tau_i w_i), with y_i and w_i the residualized outcome and treatment, and v_i an estimate of the variance of w_i given the features (a regression forest of the squared residualized treatment). The average of the scores is the estimate; its standard error is that of a mean of the scores, clustered when the forest was fitted with cluster=. With sample weights the average is weighted, and its standard error is that of a weighted mean: sqrt(m / (m - 1) sum(w^2 (score - estimate)^2)) / sum(w) for m rows.

For an instrumental forest the score is tau_i + (z_i / c_i) (y_i - tau_i w_i), with z_i the residualized instrument and c_i an estimate of the covariance of w_i and z_i given the features (at least a tenth of its average in size, with its sign), and the average is of the local effects: each row’s effect among the rows its instrument moves.

Returns:

TreatmentEffect

best_linear_projection(data, terms=None, vcov=None, n_threads=None)

The best linear projection of the treatment effect on features: the regression of each row’s doubly robust score (see average_treatment_effect) on an intercept and terms. It tells how the average effect differs with the terms, without assuming that the effect is linear in them.

Parameters:
  • data (str, polars.DataFrame or polars.LazyFrame) – The data the forest was fitted on (the same rows in the same order), with the columns of terms. The terms’ columns are read into memory for the rows that were fitted.

  • terms (list of str, optional) – Columns to project on. Default: the forest’s features.

  • vcov (str or dict, optional) – The variance estimator, spelled as in hdfe-stream: "HC0", "HC1" (or "hetero"), "HC2" or "HC3", or the forest’s clustering as {"CRV1": "school"} (or "CRV1:school"), with the column the forest was fitted with as cluster=; the names are case-insensitive. CRV1 has hdfe-stream’s small-sample factor, G/(G-1) (n-1)/(n-k), and its p-values use G-1 degrees of freedom. Default "HC3", or CRV1 by the forest’s clusters when it was fitted with cluster=.

  • n_threads (int, optional)

Returns:

LinearProjection – Coefficients Intercept and one per term.

close()

Delete the run directory. The forest cannot predict afterwards.

oob_predictions(variance=None, n_threads=None)

See ForestResult.oob_predictions. The estimates are computed once and kept in the run directory.

plot(kind=None, *, ax=None, title=None, **options)

Draw a picture of the effects with matplotlib, which is not a dependency (pip install forest-stream[plot]).

Parameters:
  • kind (str, optional) – "effects" (the default): a histogram of the out-of-bag effect estimates, with the average effect and its interval. "heterogeneity": the mean estimate against a feature (feature=; default the most important one), in groups= (20) groups of rows of equal weight, and the average. The bars are 1.96 standard errors of each group’s mean estimate (from the spread of the estimates in the group), not intervals for the group’s true effect. "importance": bars of variable_importance. "calibration": the two coefficients of calibration_test with intervals, against their ideal value of one. "projection": the coefficients of best_linear_projection (data=, which it needs, and terms=) with intervals.

  • ax (matplotlib.axes.Axes, optional) – Draw here instead of on a new figure.

  • title (str, optional)

Returns:

matplotlib.figure.Figure

predict(data, variance=None, n_threads=None, *, include_fixed_effects=False, new_groups='error', keep=None, output=None, batch_rows=None)

Predictions at the rows of data, read and predicted in batches, so that only a batch’s features, and the predictions, are in memory (and with output, not even those).

Parameters:
  • data (str, polars.DataFrame or polars.LazyFrame) – A Parquet path or glob, or a frame, with the feature columns.

  • variance (bool, optional) – Also return each estimate’s variance (little-bags, with a debiasing correction). Default: when variance_group_size is above 1, which it needs to be.

  • n_threads (int, optional) – Threads for the compiled passes. Default: all that the job may use.

  • include_fixed_effects (bool, default False) – For a forest fitted with fixed effects ("backfit" or "outcome_within"), add each row’s group effects to its prediction, which is otherwise net of them: prediction is then the forest’s estimate plus the effects, and fixed_effect is the effects’ sum. The data need the fixed-effect columns. The variance is the forest’s, and does not allow for the error in the effects.

  • new_groups ({"error", "nan", "zero"}, default "error") – With include_fixed_effects, what to do with a row whose group was not in the data the forest was fitted on: raise an error, give it a missing prediction, or give it a zero effect.

  • keep (list of str, optional) – Columns of data to carry into the output, in front of the predictions (an identifier, say).

  • output (str or path, optional) – Write the predictions to this Parquet file, batch by batch, and return its path, instead of returning them.

  • batch_rows (int, optional) – Rows per batch. Default 250,000.

Returns:

polars.DataFrame or pathlib.Path – One row per row of data: any keep columns, the estimate (tau for a causal forest, prediction for a regression forest, or class and prob_<label> for a classification forest), with variance its variance (variance_<label>), and with include_fixed_effects fixed_effect. With output, the path.

summary()

Print summary_text.

summary_text()

The fit’s description as text.

variable_importance(decay_exponent=2.0, max_depth=4)

How much the trees split on each feature: the share of splits on it at each depth, over the trees’ first max_depth levels, averaged with weights proportional to depth ** -decay_exponent (so splits near the root count most). The importances sum to one.

Returns:

polars.DataFrame – feature and importance, in the order of the formula (with the groups’ feature means last, for fixed_effects="group_means").

class forest_stream.TreatmentEffect[source]

An average treatment effect with its standard error, from a causal forest’s doubly robust scores.

beta holds the one estimate and vcov its variance; tidy, confint, summary, etable and the rest of RegressionResult apply. Inference uses the normal distribution.

estimand

What the average is of.

Type:

str

n_dropped

Rows left out because no tree was out of bag for them.

Type:

int

__init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', estimand='average treatment effect', n_dropped=0)
classmethod __new__(*args, **kwargs)
summary(logger=None, level=20)

Print the report, or write it to logger (one record, at level).

summary_text()

The summary() report as a string.

class forest_stream.LinearProjection[source]

A least-squares fit on a causal forest’s out-of-bag quantities: the best linear projection of the treatment effect on features, or the calibration test. tidy, confint, summary, etable and the rest of RegressionResult apply; p-values use the t distribution with df_t degrees of freedom.

estimand

What the regression is.

Type:

str

n_dropped

Rows left out because no tree was out of bag for them.

Type:

int

__init__(*, fml, depvar, coefnames, beta, vcov, vcov_type, df_t, n_obs, all_vcovs=<factory>, n_clusters=<factory>, collin_vars=<factory>, diagnostics=<factory>, weights=None, weights_type='aweights', estimand='', n_dropped=0)
classmethod __new__(*args, **kwargs)
summary(logger=None, level=20)

Print the report, or write it to logger (one record, at level).

summary_text()

The summary() report as a string.

class forest_stream.QuantileForestResult[source]

A fitted quantile forest: honest trees that keep the outcomes of their estimation rows, so that any conditional quantile of the outcome can be read off at prediction time. See ForestResult.

quantiles

The quantile levels the trees were grown to separate, which are also the default levels of predict.

Type:

list of float

__init__(fml, formula, engine, centering_s, options)[source]
predict(data, quantiles=None, n_threads=None, *, keep=None, output=None, batch_rows=None)[source]

Conditional quantiles of the outcome at the rows of data, read and predicted in batches.

Parameters:
  • data (str, polars.DataFrame or polars.LazyFrame) – A Parquet path or glob, or a frame, with the feature columns.

  • quantiles (float or sequence of float, optional) – Levels strictly between 0 and 1. Default: the levels the trees were grown for (quantiles). Any levels can be asked for; the forest does not have to be fitted again.

  • n_threads (int, optional)

  • keep – As in ForestResult.predict.

  • output – As in ForestResult.predict.

  • batch_rows – As in ForestResult.predict.

Returns:

polars.DataFrame or pathlib.Path – One row per row of data: any keep columns, then one column for each level, named q0.1, q0.5 and so on. A quantile is the smallest outcome whose weight in the forest reaches the level; it is one of the training outcomes. With output, the path.

oob_predictions(quantiles=None, n_threads=None)[source]

Out-of-bag quantiles at the rows the forest was fitted on: each row’s estimate pools only the trees whose subsample does not contain the row (or its cluster).

Returns:

polars.DataFrame – row_id and a column for each level, as predict names them.

oob_score(quantiles=None, n_threads=None)[source]

How well the out-of-bag quantiles fit the outcome: for each level, the mean pinball (check) loss, which the true quantile minimizes, and the share of outcomes at or below the estimate, which should be near the level. Weighted by the sample weights, if any.

Returns:

polars.DataFrame – quantile, pinball_loss, coverage and n (rows with a tree out of bag), one row for each level.

classmethod __new__(*args, **kwargs)
close()

Delete the run directory. The forest cannot predict afterwards.

plot(kind=None, *, ax=None, title=None, **options)

Draw a picture of the fit with matplotlib, which is not a dependency (pip install forest-stream[plot]).

Parameters:
  • kind (str, optional) – What to draw; the first of the kinds below is the default. "importance": bars of variable_importance (top= limits the number). For regression and classification forests also "calibration": the mean outcome (or, for a class, its observed share) against the mean out-of-bag prediction, by groups of the prediction (groups=, default 10), with the diagonal. A decision tree’s default is "tree": its nodes (max_depth= shows fewer levels). A causal forest’s are described in CausalForestResult.plot.

  • ax (matplotlib.axes.Axes, optional) – Draw here instead of on a new figure.

  • title (str, optional)

Returns:

matplotlib.figure.Figure

summary()

Print summary_text.

variable_importance(decay_exponent=2.0, max_depth=4)

How much the trees split on each feature: the share of splits on it at each depth, over the trees’ first max_depth levels, averaged with weights proportional to depth ** -decay_exponent (so splits near the root count most). The importances sum to one.

Returns:

polars.DataFrame – feature and importance, in the order of the formula (with the groups’ feature means last, for fixed_effects="group_means").

class forest_stream.RegressionForestResult[source]

A fitted regression forest: honest trees whose leaves average the outcome. See ForestResult.

__init__(fml, formula, engine, centering_s, options)
classmethod __new__(*args, **kwargs)
close()

Delete the run directory. The forest cannot predict afterwards.

group_effects()

The fixed effects of the fit, as {term: table}: each table has the term’s columns and the effect of each group (the effects of a row’s groups, and intercept, add up to the part of its outcome that the fixed effects explain). For a forest fitted with fixed_effects="backfit" or "outcome_within".

oob_predictions(variance=None, n_threads=None)

Out-of-bag predictions at the rows the forest was fitted on: each row’s estimate uses only the trees whose subsample does not contain the row (or its cluster).

Returns:

polars.DataFrame – row_id (the row’s position in the data, from 0), the estimate and, with variance, variance.

oob_score(n_threads=None)

How well the out-of-bag predictions predict the outcome the forest was fitted to (net of the fixed effects, when there are any).

Returns:

dict – For a regression forest rmse and r2 (one minus the sum of squared errors over the outcome’s variation); for a classification forest accuracy and log_loss; weighted by the sample weights, if there are any. n is the rows scored (those with a tree out of bag).

plot(kind=None, *, ax=None, title=None, **options)

Draw a picture of the fit with matplotlib, which is not a dependency (pip install forest-stream[plot]).

Parameters:
  • kind (str, optional) – What to draw; the first of the kinds below is the default. "importance": bars of variable_importance (top= limits the number). For regression and classification forests also "calibration": the mean outcome (or, for a class, its observed share) against the mean out-of-bag prediction, by groups of the prediction (groups=, default 10), with the diagonal. A decision tree’s default is "tree": its nodes (max_depth= shows fewer levels). A causal forest’s are described in CausalForestResult.plot.

  • ax (matplotlib.axes.Axes, optional) – Draw here instead of on a new figure.

  • title (str, optional)

Returns:

matplotlib.figure.Figure

predict(data, variance=None, n_threads=None, *, include_fixed_effects=False, new_groups='error', keep=None, output=None, batch_rows=None)

Predictions at the rows of data, read and predicted in batches, so that only a batch’s features, and the predictions, are in memory (and with output, not even those).

Parameters:
  • data (str, polars.DataFrame or polars.LazyFrame) – A Parquet path or glob, or a frame, with the feature columns.

  • variance (bool, optional) – Also return each estimate’s variance (little-bags, with a debiasing correction). Default: when variance_group_size is above 1, which it needs to be.

  • n_threads (int, optional) – Threads for the compiled passes. Default: all that the job may use.

  • include_fixed_effects (bool, default False) – For a forest fitted with fixed effects ("backfit" or "outcome_within"), add each row’s group effects to its prediction, which is otherwise net of them: prediction is then the forest’s estimate plus the effects, and fixed_effect is the effects’ sum. The data need the fixed-effect columns. The variance is the forest’s, and does not allow for the error in the effects.

  • new_groups ({"error", "nan", "zero"}, default "error") – With include_fixed_effects, what to do with a row whose group was not in the data the forest was fitted on: raise an error, give it a missing prediction, or give it a zero effect.

  • keep (list of str, optional) – Columns of data to carry into the output, in front of the predictions (an identifier, say).

  • output (str or path, optional) – Write the predictions to this Parquet file, batch by batch, and return its path, instead of returning them.

  • batch_rows (int, optional) – Rows per batch. Default 250,000.

Returns:

polars.DataFrame or pathlib.Path – One row per row of data: any keep columns, the estimate (tau for a causal forest, prediction for a regression forest, or class and prob_<label> for a classification forest), with variance its variance (variance_<label>), and with include_fixed_effects fixed_effect. With output, the path.

summary()

Print summary_text.

variable_importance(decay_exponent=2.0, max_depth=4)

How much the trees split on each feature: the share of splits on it at each depth, over the trees’ first max_depth levels, averaged with weights proportional to depth ** -decay_exponent (so splits near the root count most). The importances sum to one.

Returns:

polars.DataFrame – feature and importance, in the order of the formula (with the groups’ feature means last, for fixed_effects="group_means").

class forest_stream.RandomForestResult[source]

A fitted random forest for a numeric outcome. See ForestResult.

__init__(fml, formula, engine, centering_s, options)
classmethod __new__(*args, **kwargs)
class forest_stream.ClassificationForestResult[source]

A fitted random forest for class labels.

predict and oob_predictions return one probability column per class, prob_<label>, the predicted class (the likeliest), and with variance a variance_<label> column per class.

classes

The class labels, in the order of the probability columns.

Type:

list

__init__(fml, formula, engine, centering_s, options)
classmethod __new__(*args, **kwargs)
oob_predictions(variance=None, n_threads=None)

Out-of-bag predictions at the rows the forest was fitted on: each row’s estimate uses only the trees whose subsample does not contain the row (or its cluster).

Returns:

polars.DataFrame – row_id (the row’s position in the data, from 0), the estimate and, with variance, variance.

oob_score(n_threads=None)

How well the out-of-bag predictions predict the outcome the forest was fitted to (net of the fixed effects, when there are any).

Returns:

dict – For a regression forest rmse and r2 (one minus the sum of squared errors over the outcome’s variation); for a classification forest accuracy and log_loss; weighted by the sample weights, if there are any. n is the rows scored (those with a tree out of bag).

predict(data, variance=None, n_threads=None, *, include_fixed_effects=False, new_groups='error', keep=None, output=None, batch_rows=None)

Predictions at the rows of data, read and predicted in batches, so that only a batch’s features, and the predictions, are in memory (and with output, not even those).

Parameters:
  • data (str, polars.DataFrame or polars.LazyFrame) – A Parquet path or glob, or a frame, with the feature columns.

  • variance (bool, optional) – Also return each estimate’s variance (little-bags, with a debiasing correction). Default: when variance_group_size is above 1, which it needs to be.

  • n_threads (int, optional) – Threads for the compiled passes. Default: all that the job may use.

  • include_fixed_effects (bool, default False) – For a forest fitted with fixed effects ("backfit" or "outcome_within"), add each row’s group effects to its prediction, which is otherwise net of them: prediction is then the forest’s estimate plus the effects, and fixed_effect is the effects’ sum. The data need the fixed-effect columns. The variance is the forest’s, and does not allow for the error in the effects.

  • new_groups ({"error", "nan", "zero"}, default "error") – With include_fixed_effects, what to do with a row whose group was not in the data the forest was fitted on: raise an error, give it a missing prediction, or give it a zero effect.

  • keep (list of str, optional) – Columns of data to carry into the output, in front of the predictions (an identifier, say).

  • output (str or path, optional) – Write the predictions to this Parquet file, batch by batch, and return its path, instead of returning them.

  • batch_rows (int, optional) – Rows per batch. Default 250,000.

Returns:

polars.DataFrame or pathlib.Path – One row per row of data: any keep columns, the estimate (tau for a causal forest, prediction for a regression forest, or class and prob_<label> for a classification forest), with variance its variance (variance_<label>), and with include_fixed_effects fixed_effect. With output, the path.

class forest_stream.DecisionTreeResult[source]

A fitted decision tree for a numeric outcome. See ForestResult; there is no variance. tree lists its nodes.

__init__(fml, formula, engine, centering_s, options)
classmethod __new__(*args, **kwargs)
oob_score(n_threads=None)

As for a forest, for the rows that are not in the tree’s sample. A tree grown on all the rows (sample_fraction=1 without replacement) has none: score it on other data with predict.

predict(data, variance=None, n_threads=None, *, include_fixed_effects=False, new_groups='error', keep=None, output=None, batch_rows=None)

Predictions at the rows of data, read and predicted in batches, so that only a batch’s features, and the predictions, are in memory (and with output, not even those).

Parameters:
  • data (str, polars.DataFrame or polars.LazyFrame) – A Parquet path or glob, or a frame, with the feature columns.

  • variance (bool, optional) – Also return each estimate’s variance (little-bags, with a debiasing correction). Default: when variance_group_size is above 1, which it needs to be.

  • n_threads (int, optional) – Threads for the compiled passes. Default: all that the job may use.

  • include_fixed_effects (bool, default False) – For a forest fitted with fixed effects ("backfit" or "outcome_within"), add each row’s group effects to its prediction, which is otherwise net of them: prediction is then the forest’s estimate plus the effects, and fixed_effect is the effects’ sum. The data need the fixed-effect columns. The variance is the forest’s, and does not allow for the error in the effects.

  • new_groups ({"error", "nan", "zero"}, default "error") – With include_fixed_effects, what to do with a row whose group was not in the data the forest was fitted on: raise an error, give it a missing prediction, or give it a zero effect.

  • keep (list of str, optional) – Columns of data to carry into the output, in front of the predictions (an identifier, say).

  • output (str or path, optional) – Write the predictions to this Parquet file, batch by batch, and return its path, instead of returning them.

  • batch_rows (int, optional) – Rows per batch. Default 250,000.

Returns:

polars.DataFrame or pathlib.Path – One row per row of data: any keep columns, the estimate (tau for a causal forest, prediction for a regression forest, or class and prob_<label> for a classification forest), with variance its variance (variance_<label>), and with include_fixed_effects fixed_effect. With output, the path.

tree()

The fitted tree, one row per node, in depth-first order.

A row sends an observation to left when its feature is below threshold, and to right otherwise. Leaves have no feature. n is the number of rows (counted as many times as they are in the sample, when it is drawn with replacement) that estimate the node’s value, and, with sample weights, weight their total weight: the estimation half of the sample with honesty, else the sample the tree was grown on. The value is prediction for a regression tree; for a classification tree class and one prob_<label> per class. Nodes that pruning removed (honesty) are not listed.

class forest_stream.ClassificationTreeResult[source]

A fitted decision tree for class labels. See ClassificationForestResult; there is no variance. tree lists its nodes.

__init__(fml, formula, engine, centering_s, options)
classmethod __new__(*args, **kwargs)
class forest_stream.FixedEffectsWarning[source]

The fixed-effects handling did not converge, or its assumption looks violated by the data.

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)