mixle.models._forest moduleΒΆ

Native numpy random forest (CART trees + bootstrap bagging) used by mixle.models.random_forest.

Pure numpy so mixle carries no scikit-learn dependency. Supports weighted observations (needed for EM responsibilities), classification (Gini impurity, averaged leaf class distributions) and regression (weighted variance reduction, averaged leaf means), per-split random feature subsets, and bootstrap resampling per tree. Split finding is the standard sorted-cumulative-statistic scan: O(n log n) per feature per node.

class NativeRandomForest(task, n_estimators=100, max_depth=None, min_samples_split=2, min_samples_leaf=1, max_features='auto', random_state=None)[source]

Bases: object

Bootstrap-bagged ensemble of weighted CART trees with a scikit-learn-like predict interface.

Parameters:
  • task (str)

  • n_estimators (int)

  • max_depth (int | None)

  • min_samples_split (int)

  • min_samples_leaf (int)

  • max_features (Any)

  • random_state (int | None)

fit(X, y, sample_weight=None)[source]

Fit the bagged tree ensemble from a weighted design matrix and target vector.

Parameters:
Return type:

NativeRandomForest

predict_proba(X)[source]

Return class probabilities averaged over all fitted trees.

Parameters:

X (ndarray)

Return type:

ndarray

predict_log_proba(X)[source]

Return log class probabilities, preserving -inf for impossible classes.

Parameters:

X (ndarray)

Return type:

ndarray

predict(X)[source]

Return class labels for classification or mean predictions for regression.

Parameters:

X (ndarray)

Return type:

ndarray