Skip to content

[Repo Assist] fix(gcm/ml): add clone() to SklearnRegressionModelWeighted to return correct type - #1723

Draft
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-sklearn-regression-weighted-clone-1731-5918810c3e9fc5b1
Draft

[Repo Assist] fix(gcm/ml): add clone() to SklearnRegressionModelWeighted to return correct type#1723
github-actions[bot] wants to merge 1 commit into
mainfrom
repo-assist/fix-sklearn-regression-weighted-clone-1731-5918810c3e9fc5b1

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

🤖 This is an automated pull request from Repo Assist, an AI assistant.

Problem

SklearnRegressionModelWeighted was missing its own clone() method, so it inherited SklearnRegressionModel.clone(), which returns a SklearnRegressionModel instead of a SklearnRegressionModelWeighted.

This meant that cloning a weighted regression model silently dropped the sample_weight support: the cloned object's fit() would not accept the sample_weight keyword argument (it only supports X and Y), causing a TypeError if the caller tried to use it.

Root cause

The same class-hierarchy bug was present in SklearnClassificationModelWeighted and was fixed in the broader bug-fix commit (PR #1664, commit 6e8a31e):

-        return SklearnClassificationModel(sklearn_mdl=sklearn.clone(self._sklearn_mdl))
+        return SklearnClassificationModelWeighted(sklearn_mdl=sklearn.clone(self._sklearn_mdl))

The regression counterpart was not included in that fix.

Fix

Added a clone() override to SklearnRegressionModelWeighted:

def clone(self):
    return SklearnRegressionModelWeighted(sklearn_mdl=sklearn.clone(self._sklearn_mdl))

This is the exact same pattern used by SklearnClassificationModelWeighted.

When does this matter?

Any code path that:

  1. Uses a causal mechanism backed by SklearnRegressionModelWeighted as the prediction model, and
  2. Calls mechanism.clone() (e.g. causal_model.clone(), model_evaluation.py, confidence_intervals_cms.py, or distribution_change.py)

...would silently produce a wrong-type clone. In the worst case, a subsequent fit(..., sample_weight=...) call raises a TypeError.

Test Status

1 new test added to tests/gcm/ml/test_regression.py:

  • test_given_weighted_regression_model_when_clone_then_clone_type_is_weighted_and_supports_sample_weight — asserts the clone is the correct type and that fit(X, Y, sample_weight=...) succeeds on it (this would TypeError on the old code).

✅ Syntax check passes on both modified files.

Flake8 / black / isort: no hard errors on modified source file (one-liner addition in an already-clean module).


Generated by 🤖 Repo Assist, see workflow run. Learn more.

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@11c9a2c442e519ff2b427bf58679f5a525353f76

…correct type

SklearnRegressionModelWeighted was inheriting clone() from SklearnRegressionModel,
which returned a SklearnRegressionModel instance instead of SklearnRegressionModelWeighted.
This caused the cloned model to lose the sample_weight support in fit().

The same bug was fixed for SklearnClassificationModelWeighted in #1664 (Bug fixes in GCM).
This PR applies the identical fix to the regression counterpart.

Test: add test_given_weighted_regression_model_when_clone_then_clone_type_is_weighted_and_supports_sample_weight
to tests/gcm/ml/test_regression.py, which would fail before this fix (TypeError on
cloned.fit(..., sample_weight=...)) and passes after.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automation bug Something isn't working repo-assist

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants