Documentation
Classes
RandomForestRegressor

RandomForestRegressor

A random forest regressor.

A random forest is a meta estimator that fits a number of classifying decision trees on various sub-samples of the dataset and uses averaging to improve the predictive accuracy and control over-fitting. The sub-sample size is controlled with the max\_samples parameter if bootstrap=True (default), otherwise the whole dataset is used to build each tree.

Read more in the User Guide.

Python Reference (opens in a new tab)

Constructors

constructor()

Signature

new RandomForestRegressor(opts?: object): RandomForestRegressor;

Parameters

NameTypeDescription
opts?object-
opts.bootstrap?booleanWhether bootstrap samples are used when building trees. If false, the whole dataset is used to build each tree. Default Value true
opts.ccp_alpha?anyComplexity parameter used for Minimal Cost-Complexity Pruning. The subtree with the largest cost complexity that is smaller than ccp\_alpha will be chosen. By default, no pruning is performed. See Minimal Cost-Complexity Pruning for details. Default Value 0
opts.criterion?"squared_error" | "absolute_error" | "friedman_mse" | "poisson"The function to measure the quality of a split. Supported criteria are “squared_error” for the mean squared error, which is equal to variance reduction as feature selection criterion and minimizes the L2 loss using the mean of each terminal node, “friedman_mse”, which uses mean squared error with Friedman’s improvement score for potential splits, “absolute_error” for the mean absolute error, which minimizes the L1 loss using the median of each terminal node, and “poisson” which uses reduction in Poisson deviance to find splits. Training using “absolute_error” is significantly slower than when using “squared_error”. Default Value 'squared_error'
opts.max_depth?numberThe maximum depth of the tree. If undefined, then nodes are expanded until all leaves are pure or until all leaves contain less than min_samples_split samples.
opts.max_features?number | "sqrt" | "log2"The number of features to consider when looking for the best split: Default Value 1
opts.max_leaf_nodes?numberGrow trees with max\_leaf\_nodes in best-first fashion. Best nodes are defined as relative reduction in impurity. If undefined then unlimited number of leaf nodes.
opts.max_samples?numberIf bootstrap is true, the number of samples to draw from X to train each base estimator.
opts.min_impurity_decrease?numberA node will be split if this split induces a decrease of the impurity greater than or equal to this value. The weighted impurity decrease equation is the following: Default Value 0
opts.min_samples_leaf?numberThe minimum number of samples required to be at a leaf node. A split point at any depth will only be considered if it leaves at least min\_samples\_leaf training samples in each of the left and right branches. This may have the effect of smoothing the model, especially in regression. Default Value 1
opts.min_samples_split?numberThe minimum number of samples required to split an internal node: Default Value 2
opts.min_weight_fraction_leaf?numberThe minimum weighted fraction of the sum total of weights (of all the input samples) required to be at a leaf node. Samples have equal weight when sample_weight is not provided. Default Value 0
opts.n_estimators?numberThe number of trees in the forest. Default Value 100
opts.n_jobs?numberThe number of jobs to run in parallel. fit, predict, decision\_path and apply are all parallelized over the trees. undefined means 1 unless in a joblib.parallel\_backend (opens in a new tab) context. \-1 means using all processors. See Glossary for more details.
opts.oob_score?booleanWhether to use out-of-bag samples to estimate the generalization score. Only available if bootstrap=true. Default Value false
opts.random_state?numberControls both the randomness of the bootstrapping of the samples used when building trees (if bootstrap=True) and the sampling of the features to consider when looking for the best split at each node (if max\_features < n\_features). See Glossary for details.
opts.verbose?numberControls the verbosity when fitting and predicting. Default Value 0
opts.warm_start?booleanWhen set to true, reuse the solution of the previous call to fit and add more estimators to the ensemble, otherwise, just fit a whole new forest. See Glossary and Fitting additional weak-learners for details. Default Value false

Returns

RandomForestRegressor

Defined in: generated/ensemble/RandomForestRegressor.ts:25 (opens in a new tab)

Properties

_isDisposed

boolean = false

Defined in: generated/ensemble/RandomForestRegressor.ts:23 (opens in a new tab)

_isInitialized

boolean = false

Defined in: generated/ensemble/RandomForestRegressor.ts:22 (opens in a new tab)

_py

PythonBridge

Defined in: generated/ensemble/RandomForestRegressor.ts:21 (opens in a new tab)

id

string

Defined in: generated/ensemble/RandomForestRegressor.ts:18 (opens in a new tab)

opts

any

Defined in: generated/ensemble/RandomForestRegressor.ts:19 (opens in a new tab)

Accessors

estimator_

The child estimator template used to create the collection of fitted sub-estimators.

Signature

estimator_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/ensemble/RandomForestRegressor.ts:447 (opens in a new tab)

estimators_

The collection of fitted sub-estimators.

Signature

estimators_(): Promise<any>;

Returns

Promise<any>

Defined in: generated/ensemble/RandomForestRegressor.ts:474 (opens in a new tab)

feature_names_in_

Names of features seen during fit. Defined only when X has feature names that are all strings.

Signature

feature_names_in_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/ensemble/RandomForestRegressor.ts:528 (opens in a new tab)

n_features_in_

Number of features seen during fit.

Signature

n_features_in_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/ensemble/RandomForestRegressor.ts:501 (opens in a new tab)

n_outputs_

The number of outputs when fit is performed.

Signature

n_outputs_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/ensemble/RandomForestRegressor.ts:555 (opens in a new tab)

oob_prediction_

Prediction computed with out-of-bag estimate on the training set. This attribute exists only when oob\_score is true.

Signature

oob_prediction_(): Promise<ArrayLike>;

Returns

Promise<ArrayLike>

Defined in: generated/ensemble/RandomForestRegressor.ts:609 (opens in a new tab)

oob_score_

Score of the training dataset obtained using an out-of-bag estimate. This attribute exists only when oob\_score is true.

Signature

oob_score_(): Promise<number>;

Returns

Promise<number>

Defined in: generated/ensemble/RandomForestRegressor.ts:582 (opens in a new tab)

py

Signature

py(): PythonBridge;

Returns

PythonBridge

Defined in: generated/ensemble/RandomForestRegressor.ts:141 (opens in a new tab)

Signature

py(pythonBridge: PythonBridge): void;

Parameters

NameType
pythonBridgePythonBridge

Returns

void

Defined in: generated/ensemble/RandomForestRegressor.ts:145 (opens in a new tab)

Methods

apply()

Apply trees in the forest to X, return leaf indices.

Signature

apply(opts: object): Promise<ArrayLike[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples. Internally, its dtype will be converted to dtype=np.float32. If a sparse matrix is provided, it will be converted into a sparse csr\_matrix.

Returns

Promise<ArrayLike[]>

Defined in: generated/ensemble/RandomForestRegressor.ts:237 (opens in a new tab)

decision_path()

Return the decision path in the forest.

Signature

decision_path(opts: object): Promise<any[]>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples. Internally, its dtype will be converted to dtype=np.float32. If a sparse matrix is provided, it will be converted into a sparse csr\_matrix.

Returns

Promise<any[]>

Defined in: generated/ensemble/RandomForestRegressor.ts:272 (opens in a new tab)

dispose()

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Signature

dispose(): Promise<void>;

Returns

Promise<void>

Defined in: generated/ensemble/RandomForestRegressor.ts:220 (opens in a new tab)

fit()

Build a forest of trees from the training set (X, y).

Signature

fit(opts: object): Promise<any>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe training input samples. Internally, its dtype will be converted to dtype=np.float32. If a sparse matrix is provided, it will be converted into a sparse csc\_matrix.
opts.sample_weight?ArrayLikeSample weights. If undefined, then samples are equally weighted. Splits that would create child nodes with net zero or negative weight are ignored while searching for a split in each node. In the case of classification, splits are also ignored if they would result in any single class carrying a negative weight in either child node.
opts.y?ArrayLikeThe target values (class labels in classification, real numbers in regression).

Returns

Promise<any>

Defined in: generated/ensemble/RandomForestRegressor.ts:310 (opens in a new tab)

init()

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Signature

init(py: PythonBridge): Promise<void>;

Parameters

NameType
pyPythonBridge

Returns

Promise<void>

Defined in: generated/ensemble/RandomForestRegressor.ts:154 (opens in a new tab)

predict()

Predict regression target for X.

The predicted regression target of an input sample is computed as the mean predicted regression targets of the trees in the forest.

Signature

predict(opts: object): Promise<ArrayLike>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLikeThe input samples. Internally, its dtype will be converted to dtype=np.float32. If a sparse matrix is provided, it will be converted into a sparse csr\_matrix.

Returns

Promise<ArrayLike>

Defined in: generated/ensemble/RandomForestRegressor.ts:361 (opens in a new tab)

score()

Return the coefficient of determination of the prediction.

The coefficient of determination \(R^2\) is defined as \((1 - \frac{u}{v})\), where \(u\) is the residual sum of squares ((y\_true \- y\_pred)\*\* 2).sum() and \(v\) is the total sum of squares ((y\_true \- y\_true.mean()) \*\* 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a \(R^2\) score of 0.0.

Signature

score(opts: object): Promise<number>;

Parameters

NameTypeDescription
optsobject-
opts.X?ArrayLike[]Test samples. For some estimators this may be a precomputed kernel matrix or a list of generic objects instead with shape (n\_samples, n\_samples\_fitted), where n\_samples\_fitted is the number of samples used in the fitting for the estimator.
opts.sample_weight?ArrayLikeSample weights.
opts.y?ArrayLikeTrue values for X.

Returns

Promise<number>

Defined in: generated/ensemble/RandomForestRegressor.ts:398 (opens in a new tab)