Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions mlxtend/feature_selection/sequential_feature_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,14 @@ def __init__(
clone_estimator=True,
fixed_features=None,
feature_groups=None,
tol = None
):
self.estimator = estimator
self.k_features = k_features
self.forward = forward
self.floating = floating
self.pre_dispatch = pre_dispatch
self.tol = tol
# Want to raise meaningful error message if a
# cross-validation generator is inputted
if isinstance(cv, types.GeneratorType):
Expand Down Expand Up @@ -569,6 +571,13 @@ def fit(self, X, y, groups=None, **fit_params):
"avg_score": k_score,
}

if self.tol is not None and k > 1:
prev_k = k - 1 if self.forward else k + 1
if prev_k in self.subsets_:
diff = k_score - self.subsets_[prev_k]["avg_score"]
if diff < self.tol:
k_stop = k

if self.floating:
# floating direction is opposite of self.forward, i.e. in
# forward selection, we do floating in backward manner,
Expand Down
Loading