Mojo struct
RandomForest
@memory_only
struct RandomForest
A random forest supporting both classification and regression.
Aliases
__del__is_trivial = False
Fields
- n_trees (
Int): The number of trees in the forest. - min_samples_split (
Int): The minimum number of samples required to split an internal node. - max_depth (
Int): The maximum depth of the tree. - n_feats (
Int): The number of features to consider when looking for the best split. - criterion (
String): The function to measure the quality of a split: For classification -> 'entropy', 'gini'; For regression -> 'mse'. - trees (
UnsafePointer[DecisionTree, MutAnyOrigin])
Implemented traits
AnyType, CV, ImplicitlyDestructible
Methods
__init__
fn __init__(out self, n_trees: Int = 10, min_samples_split: Int = 2, max_depth: Int = 100, n_feats: Int = -1, criterion: String = "gini", random_state: Int = 42)
Args:
- n_trees (
Int) - min_samples_split (
Int) - max_depth (
Int) - n_feats (
Int) - criterion (
String) - random_state (
Int) - self (
Self)
Returns:
Self
fn __init__(out self, params: Dict[String, String])
Args:
- params (
Dict) - self (
Self)
Returns:
Self
Raises:
__del__
fn __del__(deinit self)
Args:
- self (
Self)
fit
fn fit(mut self, X: Matrix, y: Matrix)
Build a forest of trees from the training set.
Args:
- self (
Self) - X (
Matrix) - y (
Matrix)
Raises:
predict
fn predict(self, X: Matrix) -> Matrix
Predict class or regression value for X.
Args:
- self (
Self) - X (
Matrix)
Returns:
Matrix: The predicted values.
Raises: