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

Select between ._fit() of .fit() depending on the sklearn version used #16

Merged
merged 5 commits into from
Jan 22, 2024
Merged
Changes from 1 commit
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: 8 additions & 1 deletion src/m5py/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from sklearn.tree._tree import DOUBLE
from sklearn.utils import check_array
from sklearn.utils.validation import check_is_fitted
from sklearn import __version__ as sklearn_version

from m5py.linreg_utils import linreg_model_to_text, DeNormalizableMixIn, DeNormalizableLinearRegression

Expand Down Expand Up @@ -210,8 +211,14 @@ def fit(self, X, y: np.ndarray, sample_weight=None, check_input=True, X_idx_sort
if self.use_smoothing not in [False, np.bool_(False), "installed", "on_prediction"]:
raise ValueError("use_smoothing: Unexpected value: %s, please report it as issue." % self.use_smoothing)

# Get the correct fit method name based on the sklearn version used
sklearn_version_tuple = tuple(map(int, sklearn_version.split('.')))
fit_method_name = "fit" if sklearn_version_tuple <= (1, 3) else "_fit"

# (1) Build the initial tree as usual
super(M5Base, self).fit(X, y, sample_weight=sample_weight, check_input=check_input)
fit_method = getattr(super(M5Base, self), fit_method_name)
Copy link
Owner

Choose a reason for hiding this comment

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

Nitpick: readability: please move all new lines after the comment, or all lines before the comment.

fit_method(X, y, sample_weight=sample_weight, check_input=check_input)


if self.debug_prints:
logger.debug("(debug_prints) Initial tree:")
Expand Down
Loading