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
predictandoob_predictions, it estimates the average treatment effect withaverage_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), ingroups=(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 ofvariable_importance."calibration": the two coefficients ofcalibration_testwith intervals, against their ideal value of one."projection": the coefficients ofbest_linear_projection(data=, which it needs, andterms=) with intervals.ax (matplotlib.axes.Axes, optional) – Draw here instead of on a new figure.
title (str, optional)
- Returns:
matplotlib.figure.Figure
- 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), withy_iandw_ithe residualized outcome and treatment, andv_ian estimate of the variance ofw_igiven 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 withcluster=. 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), withz_ithe residualized instrument andc_ian estimate of the covariance ofw_iandz_igiven 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 andterms. 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 ascluster=; 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 withcluster=.n_threads (int, optional)
- Returns:
LinearProjection – Coefficients
Interceptand 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:
vcov (str or dict, optional) – As in
best_linear_projection: default"HC3", or CRV1 by the forest’s clusters.n_threads (int, optional)
- 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 withoutput, 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_sizeis 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:predictionis then the forest’s estimate plus the effects, andfixed_effectis 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
datato 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: anykeepcolumns, the estimate (taufor a causal forest,predictionfor a regression forest, orclassandprob_<label>for a classification forest), withvarianceitsvariance(variance_<label>), and withinclude_fixed_effectsfixed_effect. Withoutput, 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_depthlevels, averaged with weights proportional todepth ** -decay_exponent(so splits near the root count most). The importances sum to one.- Returns:
polars.DataFrame –
featureandimportance, in the order of the formula (with the groups’ feature means last, forfixed_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;instrumentnames the instrument.calibration_testis 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), withy_iandw_ithe residualized outcome and treatment, andv_ian estimate of the variance ofw_igiven 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 withcluster=. 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), withz_ithe residualized instrument andc_ian estimate of the covariance ofw_iandz_igiven 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 andterms. 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 ascluster=; 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 withcluster=.n_threads (int, optional)
- Returns:
LinearProjection – Coefficients
Interceptand 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), ingroups=(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 ofvariable_importance."calibration": the two coefficients ofcalibration_testwith intervals, against their ideal value of one."projection": the coefficients ofbest_linear_projection(data=, which it needs, andterms=) 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 withoutput, 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_sizeis 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:predictionis then the forest’s estimate plus the effects, andfixed_effectis 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
datato 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: anykeepcolumns, the estimate (taufor a causal forest,predictionfor a regression forest, orclassandprob_<label>for a classification forest), withvarianceitsvariance(variance_<label>), and withinclude_fixed_effectsfixed_effect. Withoutput, 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_depthlevels, averaged with weights proportional todepth ** -decay_exponent(so splits near the root count most). The importances sum to one.- Returns:
polars.DataFrame –
featureandimportance, in the order of the formula (with the groups’ feature means last, forfixed_effects="group_means").
- class forest_stream.TreatmentEffect[source]¶
An average treatment effect with its standard error, from a causal forest’s doubly robust scores.
betaholds the one estimate andvcovits variance;tidy,confint,summary,etableand the rest ofRegressionResultapply. Inference uses the normal distribution.- __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, atlevel).
- 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,etableand the rest ofRegressionResultapply; p-values use the t distribution withdf_tdegrees of freedom.- __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, atlevel).
- 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.
- 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: anykeepcolumns, then one column for each level, namedq0.1,q0.5and so on. A quantile is the smallest outcome whose weight in the forest reaches the level; it is one of the training outcomes. Withoutput, 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_idand a column for each level, aspredictnames 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,coverageandn(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 ofvariable_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 inCausalForestResult.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_depthlevels, averaged with weights proportional todepth ** -decay_exponent(so splits near the root count most). The importances sum to one.- Returns:
polars.DataFrame –
featureandimportance, in the order of the formula (with the groups’ feature means last, forfixed_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 theeffectof each group (the effects of a row’s groups, andintercept, add up to the part of its outcome that the fixed effects explain). For a forest fitted withfixed_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, withvariance,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
rmseandr2(one minus the sum of squared errors over the outcome’s variation); for a classification forestaccuracyandlog_loss; weighted by the sample weights, if there are any.nis 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 ofvariable_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 inCausalForestResult.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 withoutput, 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_sizeis 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:predictionis then the forest’s estimate plus the effects, andfixed_effectis 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
datato 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: anykeepcolumns, the estimate (taufor a causal forest,predictionfor a regression forest, orclassandprob_<label>for a classification forest), withvarianceitsvariance(variance_<label>), and withinclude_fixed_effectsfixed_effect. Withoutput, 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_depthlevels, averaged with weights proportional todepth ** -decay_exponent(so splits near the root count most). The importances sum to one.- Returns:
polars.DataFrame –
featureandimportance, in the order of the formula (with the groups’ feature means last, forfixed_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.
predictandoob_predictionsreturn one probability column per class,prob_<label>, the predictedclass(the likeliest), and withvarianceavariance_<label>column per class.- __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, withvariance,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
rmseandr2(one minus the sum of squared errors over the outcome’s variation); for a classification forestaccuracyandlog_loss; weighted by the sample weights, if there are any.nis 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 withoutput, 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_sizeis 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:predictionis then the forest’s estimate plus the effects, andfixed_effectis 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
datato 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: anykeepcolumns, the estimate (taufor a causal forest,predictionfor a regression forest, orclassandprob_<label>for a classification forest), withvarianceitsvariance(variance_<label>), and withinclude_fixed_effectsfixed_effect. Withoutput, the path.
- class forest_stream.DecisionTreeResult[source]¶
A fitted decision tree for a numeric outcome. See
ForestResult; there is no variance.treelists 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=1without replacement) has none: score it on other data withpredict.
- 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 withoutput, 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_sizeis 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:predictionis then the forest’s estimate plus the effects, andfixed_effectis 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
datato 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: anykeepcolumns, the estimate (taufor a causal forest,predictionfor a regression forest, orclassandprob_<label>for a classification forest), withvarianceitsvariance(variance_<label>), and withinclude_fixed_effectsfixed_effect. Withoutput, the path.
- tree()¶
The fitted tree, one row per node, in depth-first order.
A row sends an observation to
leftwhen itsfeatureis belowthreshold, and torightotherwise. Leaves have no feature.nis 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,weighttheir total weight: the estimation half of the sample with honesty, else the sample the tree was grown on. The value ispredictionfor a regression tree; for a classification treeclassand oneprob_<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.treelists its nodes.- __init__(fml, formula, engine, centering_s, options)¶
- classmethod __new__(*args, **kwargs)¶