Skip to content

Commit

Permalink
might testing wip
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelCarliles3 committed Sep 18, 2024
1 parent 2316e4c commit 71cacf3
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions sklearn/ensemble/_forest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2517,7 +2517,8 @@ def __init__(
store_leaf_values=False,
monotonic_cst=None,
stratify=False,
honest_prior="ignore"
honest_prior="ignore",
honest_fraction=0.5
):
self.target_tree_kwargs = {
"criterion": criterion,
Expand All @@ -2538,12 +2539,16 @@ def __init__(
target_tree_class=target_tree_class,
target_tree_kwargs=self.target_tree_kwargs,
stratify=stratify,
honest_prior=honest_prior
honest_prior=honest_prior,
honest_fraction=honest_fraction
),
n_estimators=n_estimators,
estimator_params=(
"target_tree_class",
"target_tree_kwargs"
"target_tree_kwargs",
"stratify",
"honest_prior",
"honest_fraction"
),
# estimator_params=(
# "criterion",
Expand Down Expand Up @@ -2584,6 +2589,45 @@ def __init__(
self.target_tree_class = target_tree_class
self.stratify = stratify
self.honest_prior = honest_prior
self.honest_fraction = honest_fraction


@property
def structure_indices_(self):
"""The indices used to learn the structure of the trees."""
check_is_fitted(self)
return [tree.structure_indices_ for tree in self.estimators_]

@property
def honest_indices_(self):
"""The indices used to fit the leaf nodes."""
check_is_fitted(self)
return [tree.honest_indices_ for tree in self.estimators_]

@property
def oob_samples_(self):
"""The sample indices that are out-of-bag.
Only utilized if ``bootstrap=True``, otherwise, all samples are "in-bag".
"""
if self.bootstrap is False and (
self._n_samples_bootstrap is None or self._n_samples_bootstrap == self._n_samples
):
raise RuntimeError(
"Cannot extract out-of-bag samples when bootstrap is False and "
"n_samples == n_samples_bootstrap"
)
check_is_fitted(self)

oob_samples = []

possible_indices = np.arange(self._n_samples)
for structure_idx, honest_idx in zip(self.structure_indices_, self.honest_indices_):
_oob_samples = np.setdiff1d(
possible_indices, np.concatenate((structure_idx, honest_idx))
)
oob_samples.append(_oob_samples)
return oob_samples


class RandomForestRegressor(ForestRegressor):
Expand Down

0 comments on commit 71cacf3

Please sign in to comment.