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 horizon check #72

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Contributors
* Attila Juhasz <[email protected]>
* Christoph Deil <[email protected]>
* Krisitna Kokoskova <[email protected]>
* Grigorii Smirnov-Pinchukov <[email protected]>
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
Changelog
=========

Version 0.1.13
=============
- Fix throwing error when the FinerTimeSplit is used with a large number of overlapping splits

Version 0.1.12
=============
- Update failing param grid for exponential smoothing models
Expand Down
2 changes: 1 addition & 1 deletion src/hcrystalball/metrics/_scorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def _save_prediction(self, y_pred, estimator_label, y_true):
new_split_df = pd.DataFrame({"y_true": y_true}, index=y_pred.index).assign(
split=self._split_index[estimator_label]
)
self._cv_data = self._cv_data.append(new_split_df, sort=False)
self._cv_data = pd.concat(self._cv_data, new_split_df)

# Add the new predictions to the cv data container
self._cv_data.loc[
Expand Down
16 changes: 10 additions & 6 deletions src/hcrystalball/model_selection/_split.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,20 @@ def _split(self, data):
f"`horizon`({self.horizon}) have to be greater than 1'"
)

max_obs = (
self.horizon if self.between_split_lag is None else max(self.horizon, self.between_split_lag)
)
if n_samples < self.n_splits * max_obs:
if (self.between_split_lag is not None) and (
n_samples < self.horizon + (self.n_splits - 1) * self.between_split_lag):
raise ValueError(
f"Cannot have number of samples({n_samples}) lower than the number "
f"of `n_splits`({self.n_splits}) * `horizon`({self.horizon}),"
f"or `n_splits`({self.n_splits}) * `between_split_lag`({self.between_split_lag}) "
f"of (`n_splits` ({self.n_splits}) - 1) * `between_split_lag`({self.between_split_lag}) "
f"+ `horizon`({self.horizon}),"
f"if you provided `between_split_lag`"
)
elif (self.between_split_lag is None) and (n_samples < self.n_splits * self.horizon):
raise ValueError(
f"Cannot have number of samples({n_samples}) lower than the number "
f"of `n_splits`({self.n_splits}) * `horizon`({self.horizon}),"
f"if you have not provided `between_split_lag`"
)

indices = np.arange(n_samples)
if self.between_split_lag is not None:
Expand Down