Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH Mention scaling behavior of binning and splines #739

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Changes from all 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
20 changes: 14 additions & 6 deletions python_scripts/linear_models_feature_engineering_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ def plot_decision_boundary(model, title=None):
# %%
from sklearn.preprocessing import KBinsDiscretizer

classifier = make_pipeline(KBinsDiscretizer(n_bins=5), LogisticRegression())
classifier = make_pipeline(
KBinsDiscretizer(n_bins=5, encode="onehot"), # already the default params
LogisticRegression(),
)
classifier

# %%
Expand Down Expand Up @@ -279,15 +282,20 @@ def plot_decision_boundary(model, title=None):
# We can see that the decision boundary is now smooth, and while it favors
# axis-aligned decision rules when extrapolating in low density regions, it can
# adopt a more curvy decision boundary in the high density regions.
#
# Note however, that the number of knots is a hyperparameter that needs to be
# tuned. If we use too few knots, the model would underfit the data, as shown on
# the moons dataset. If we use too many knots, the model would overfit the data.
#
# However, as for the binning transformation, the model still fails to separate
# the data for the XOR dataset, irrespective of the number of knots, for the
# same reasons: **the spline transformation is a feature-wise transformation**
# and thus **cannot capture interactions** between features.
#
# Take into account that the number of knots is a hyperparameter that needs to be
# tuned. If we use too few knots, the model would underfit the data, as shown on
# the moons dataset. If we use too many knots, the model would overfit the data.
#
# ```{note}
# Notice that `KBinsDiscretizer(encode="onehot")` and `SplineTransformer` do not
# require additional scaling. Indeed, they can replace the scaling step for
# numerical features: they both create features with values in the [0, 1] range.
# ```

# %% [markdown]
#
Expand Down