| |
- builtins.object
-
- RandomForestRegressor
class RandomForestRegressor(builtins.object) |
|
RandomForestRegressor(forest_size=100, max_depth=10, min_samples_split=2, n_jobs=-1, random_seed=None, X=None, y=None)
A class representing a Random Forest model for regression.
Attributes:
n_estimators (int): The number of trees in the forest.
max_depth (int): The maximum depth of each tree.
min_samples_split (int): The minimum number of samples required to split an internal node.
n_jobs (int): The number of jobs to run in parallel for fitting.
random_state (int): Seed for random number generation for reproducibility.
trees (list): List holding the fitted RegressorTree instances.
X (numpy.ndarray or None): The feature matrix used for training.
y (numpy.ndarray or None): The target labels used for training.
Methods:
fit(X=None, y=None, verbose=False): Fits the random forest to the data.
calculate_metrics(y_true, y_pred): Calculates the evaluation metrics.
predict(X): Predicts the target values for the input features.
get_stats(verbose=False): Returns the evaluation metrics. |
|
Methods defined here:
- __init__(self, forest_size=100, max_depth=10, min_samples_split=2, n_jobs=-1, random_seed=None, X=None, y=None)
- Initialize the Random Forest Regressor.
- calculate_metrics(self, y_true, y_pred)
- Calculate common regression metrics.
Args:
y_true (array-like): True target values.
y_pred (array-like): Predicted target values.
Returns:
dict: A dictionary containing calculated metrics (MSE, R^2, MAE, RMSE, MAPE).
- fit(self, X=None, y=None, sample_weight=None, verbose=False)
- Fit the random forest to the training data X and y.
Args:
X (array-like): Training input features of shape (n_samples, n_features).
y (array-like): Training target values of shape (n_samples,).
sample_weight (array-like): Sample weights for each instance in X.
verbose (bool): Whether to print progress messages.
Returns:
self: The fitted RandomForestRegressor instance.
- get_params(self)
- Get the parameters of the Random Forest Regressor.
Returns:
dict: A dictionary containing the parameters of the model.
- get_stats(self, y_true, y_pred, verbose=False)
- Calculate and optionally print evaluation metrics.
Args:
y_true (array-like): True target values.
y_pred (array-like): Predicted target values.
verbose (bool): Whether to print progress messages (e.g., residuals).
Returns:
dict: A dictionary containing calculated metrics (MSE, R^2, MAE, RMSE, MAPE).
- predict(self, X)
- Predict target values for input features X using the trained random forest.
Args:
X (array-like): Input features of shape (n_samples, n_features).
Returns:
np.ndarray: Predicted target values of shape (n_samples,).
Data descriptors defined here:
- __dict__
- dictionary for instance variables
- __weakref__
- list of weak references to the object
| |