Skip to content

random_forest

RandomForestRegressorLearner(*args, **kwargs)

Bases: SupervisedLearner

Wrapper class for sklearn's RandomForestRegressor.

Reference: https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestRegressor.html

Initialize the random forest learner.

Parameters:

Name Type Description Default
*args Any

Positional arguments to pass to the RandomForestRegressor.

()
**kwargs Any

Keyword arguments to pass to the RandomForestRegressor.

{}
Source code in src/flowcean/sklearn/random_forest.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
def __init__(
    self,
    *args: Any,
    **kwargs: Any,
) -> None:
    """Initialize the random forest learner.

    Args:
        *args: Positional arguments to pass to the RandomForestRegressor.
        **kwargs: Keyword arguments to pass to the RandomForestRegressor.
    """
    self.regressor = RandomForestRegressor(
        *args,
        **kwargs,
        random_state=get_seed(),
    )

learn(inputs, outputs)

Fit the random forest regressor on the given inputs and outputs.

Source code in src/flowcean/sklearn/random_forest.py
41
42
43
44
45
46
47
48
49
50
@override
def learn(
    self,
    inputs: pl.DataFrame,
    outputs: pl.DataFrame,
) -> Model:
    """Fit the random forest regressor on the given inputs and outputs."""
    self.regressor.fit(inputs, outputs)
    logger.info("Using Random Forest Regressor")
    return SciKitModel(self.regressor, outputs.columns[0])