deepcave.evaluators.epm.random_forest

# RandomForest

This module can be used for training and using a Random Forest Regression model.

A pyrfr wrapper is used for simplification.

## Classes
  • RandomForest: A random forest wrapper for pyrfr.

## Constants

VERY_SMALL_NUMBER : float PYRFR_MAPPING : Dict[str, str]

Classes

RandomForest(configspace[, n_trees, ...])

A random forest wrapper for pyrfr.

class deepcave.evaluators.epm.random_forest.RandomForest(configspace, n_trees=16, ratio_features=0.8333333333333334, min_samples_split=3, min_samples_leaf=3, max_depth=1048576, max_nodes=1048576, eps_purity=1e-08, bootstrapping=True, instance_features=None, pca_components=2, log_y=False, seed=0)[source]

Bases: object

A random forest wrapper for pyrfr.

This is handy because only the configuration space needs to be passed. and have a working version without specifying e.g. types and bounds.

Note

This wrapper also supports instances.

csConfigurationSpace

The configuration space.

log_ybool

Whether y should be treated as a logarithmic transformation.

seedint

The seed. If not provided, it is random.

typesList[int]

The types of the Hyperparameters.

boundsList[Tuple[float, float]]

The bounds of the Hyperparameters.

n_paramsint

The number of Hyperparameters in the configuration space.

n_featuresint

The number of features.

pca_componentsint

The number of components to keep for the principal component analysis (PCA).

pcaPCA

The principal component analysis (PCA) object.

scalerMinMaxScaler

A MinMaxScaler to scale the features.

instance_featuresndarray

The instance features.

get_leaf_values(x)[source]

Get the leaf values of the model.

Parameters:

x (np.ndarray) – Input data array.

Returns:

The leaf values of the model.

Return type:

regression.binary_rss_forest

predict(X)[source]

Predict means and variances for a given X.

Parameters:

X (np.ndarray [n_samples, n_features (config + instance features)]) – Training samples.

Return type:

Tuple[ndarray, ndarray]

Returns:

  • means (np.ndarray [n_samples, n_objectives]) – Predictive mean.

  • vars (np.ndarray [n_samples, n_objectives] or [n_samples, n_samples]) – Predictive variance or standard deviation.

predict_marginalized(X)[source]

Predict mean and variance marginalized over all instances.

Return the predictive mean and variance marginalized over all instances for a set of configurations.

Parameters:

X (np.ndarray) – [n_samples, n_features (config)]

Return type:

Tuple[ndarray, ndarray]

Returns:

  • means (np.ndarray of shape = [n_samples, 1]) – Predictive mean

  • vars (np.ndarray of shape = [n_samples, 1]) – Predictive variance

train(X, Y)[source]

Train the random forest on X and Y.

Transform X if principal component analysis (PCA) is applied. Afterwards, _train is called.

Parameters:
  • X (np.ndarray [n_samples, n_features (config + instance features)]) – Input data points.

  • Y (np.ndarray [n_samples, n_objectives]) – Target values. n_objectives must match the number of target names specified in the constructor.

Return type:

None