Random Forest model implementation for time series forecasting
RandomForestHyperparams
random_forest_model.RandomForestHyperparams · inherits PydanticBaseModel
| Attribute | Type | Default | Description |
|---|---|---|---|
n_estimators |
int |
- | Number of trees in the forest |
max_depth |
int |
- | Maximum depth of trees |
min_samples_split |
int |
2 |
Minimum samples to split a node |
min_samples_leaf |
int |
1 |
Minimum samples in a leaf |
max_features |
Literal["sqrt", "log2", "auto"] |
"sqrt" |
Number of features to consider for splits |
RandomForestModel
random_forest_model.RandomForestModel · inherits BaseModel
__init__(self, params: Dict[str, Any], settings: Dict[str, Any])
Initialize Random Forest model with model-specific parameters.
| Parameter | Type | Default | Description |
|---|---|---|---|
params |
Dict[str, Any] |
- | (undocumented) |
settings |
Dict[str, Any] |
- | (undocumented) |
train(self, y_context: numpy.ndarray, y_target: numpy.ndarray, timestamps_context: numpy.ndarray, timestamps_target: numpy.ndarray, x_context: Optional[numpy.ndarray] = None, x_target: Optional[numpy.ndarray] = None, **kwargs: dict) -> RandomForestModel
Train the Random Forest model on given data.
TECHNIQUE: Single Model with Timestamp Features - Creates lag features from historical target values - Adds rolling statistics (mean, std, min, max) - Includes trend features using linear regression - Incorporates timestamp features for time-aware splits - Uses a single model to predict all forecast horizon steps
| Parameter | Type | Default | Description |
|---|---|---|---|
y_context |
numpy.ndarray |
- | Past target values (time series) - used for training |
y_target |
numpy.ndarray |
- | Future target values (optional, for validation) |
timestamps_context |
numpy.ndarray |
- | Timestamps for y_context (optional) |
timestamps_target |
numpy.ndarray |
- | Timestamps for y_target (optional) |
x_context |
Optional[numpy.ndarray] |
None |
(undocumented) |
x_target |
Optional[numpy.ndarray] |
None |
(undocumented) |
**kwargs |
dict |
- | Additional keyword arguments |
Returns: RandomForestModel (The fitted model instance.)
predict(self, y_context: numpy.ndarray, timestamps_context: numpy.ndarray, timestamps_target: numpy.ndarray, x_context: Optional[numpy.ndarray] = None, x_target: Optional[numpy.ndarray] = None, **kwargs: dict) -> numpy.ndarray
Make predictions using the trained Random Forest model.
TECHNIQUE: Single Model with Timestamp Features - Uses last lookback_window values to create features - Incorporates timestamp features for time-aware prediction - Predicts all forecast horizon steps with a single model
| Parameter | Type | Default | Description |
|---|---|---|---|
y_context |
numpy.ndarray |
- | Past target values (time series) - used for prediction |
timestamps_context |
numpy.ndarray |
- | Timestamps for y_context (optional) |
timestamps_target |
numpy.ndarray |
- | Timestamps for y_target (optional) |
x_context |
Optional[numpy.ndarray] |
None |
(undocumented) |
x_target |
Optional[numpy.ndarray] |
None |
(undocumented) |
**kwargs |
dict |
- | Additional keyword arguments |
Returns: numpy.ndarray (Model predictions with shape (1, forecast_horizon))
Raises: ValueError (Model is not trained yet. Call train() first.)