[go: up one dir, main page]

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

FIX Target encoder const y #28233

Merged
merged 10 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 2 additions & 2 deletions sklearn/preprocessing/_target_encoder_fast.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ctypedef fused Y_DTYPE:

def _fit_encoding_fast(
INT_DTYPE[:, ::1] X_int,
Y_DTYPE[:] y,
const Y_DTYPE[:] y,
cnp.int64_t[::1] n_categories,
double smooth,
double y_mean,
Expand Down Expand Up @@ -79,7 +79,7 @@ def _fit_encoding_fast(

def _fit_encoding_fast_auto_smooth(
INT_DTYPE[:, ::1] X_int,
Y_DTYPE[:] y,
const Y_DTYPE[:] y,
cnp.int64_t[::1] n_categories,
double y_mean,
double y_variance,
Expand Down
7 changes: 7 additions & 0 deletions sklearn/preprocessing/tests/test_target_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,3 +701,10 @@ def test_target_encoding_for_linear_regression(smooth, global_random_seed):
# cardinality yet non-informative feature instead of the lower
# cardinality yet informative feature:
assert abs(coef[0]) < abs(coef[2])


def test_27879():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use a better function name?

Suggested change
def test_27879():
def test_pandas_copy_on_write_true():
"""Check target encoder works with copy on write.
Non-regression test for gh-27879.
"""

pd = pytest.importorskip("pandas")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the failing CI, it is using a really old version of pandas that does not have mode.copy_on_write. Here we can set the min version here:

Suggested change
pd = pytest.importorskip("pandas")
pd = pytest.importorskip("pandas", minversion="2.0")

with pd.option_context("mode.copy_on_write", True):
df = pd.DataFrame({"x": ["a", "b", "b"], "y": [4.0, 5.0, 6.0]})
TargetEncoder(target_type="continuous").fit(df[["x"]], df["y"])
Loading