-
Notifications
You must be signed in to change notification settings - Fork 753
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 Rotbaum to handle short series #3065
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e17f49c
fixed bug for items with short than H history
leica2023 71257a6
added a test case
leica2023 3c06a8e
reformat
leica2023 1903ff2
src test styling
leica2023 e4f2bdb
fixed test func
leica2023 d4a28c3
added import
leica2023 0871ef7
added import
leica2023 d3ad48d
fixed errors
leica2023 08f32c6
reformat
leica2023 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -864,4 +864,4 @@ | |
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,10 +12,12 @@ | |
# permissions and limitations under the License. | ||
|
||
import pytest | ||
import numpy as np | ||
|
||
from gluonts.ext.rotbaum import TreeEstimator | ||
from gluonts.ext.rotbaum import TreeEstimator, TreePredictor | ||
|
||
from gluonts.testutil.dummy_datasets import make_dummy_datasets_with_features | ||
from gluonts.dataset.common import ListDataset | ||
|
||
# TODO: Add support for categorical and dynamic features. | ||
|
||
|
@@ -59,3 +61,69 @@ def test_rotbaum_smoke(datasets): | |
predictor = estimator.train(dataset_train) | ||
forecasts = list(predictor.predict(dataset_test)) | ||
assert len(forecasts) == len(dataset_test) | ||
|
||
|
||
def test_short_history_item_pred(): | ||
|
||
prediction_length = 7 | ||
freq = "D" | ||
|
||
dataset = ListDataset( | ||
data_iter=[ | ||
{ | ||
"start": "2017-10-11", | ||
"item_id": "item_1", | ||
"target": np.array( | ||
[ | ||
1.0, | ||
9.0, | ||
2.0, | ||
0.0, | ||
0.0, | ||
1.0, | ||
5.0, | ||
3.0, | ||
4.0, | ||
2.0, | ||
0.0, | ||
0.0, | ||
1.0, | ||
6.0, | ||
] | ||
), | ||
"feat_static_cat": np.array([0.0, 0.0], dtype=float), | ||
"past_feat_dynamic_real": np.array( | ||
[ | ||
[1.0222e06 for i in range(14)], | ||
[750.0 for i in range(14)], | ||
] | ||
), | ||
}, | ||
{ | ||
"start": "2017-10-11", | ||
"item_id": "item_2", | ||
"target": np.array([7.0, 0.0, 0.0, 23.0, 13.0]), | ||
"feat_static_cat": np.array([0.0, 1.0], dtype=float), | ||
"past_feat_dynamic_real": np.array( | ||
[[0 for i in range(5)], [750.0 for i in range(5)]] | ||
), | ||
}, | ||
], | ||
freq=freq, | ||
) | ||
|
||
predictor = TreePredictor( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TreePredictor also needs importing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this and reverted ipynb styling. |
||
freq=freq, | ||
prediction_length=prediction_length, | ||
quantiles=[0.1, 0.5, 0.9], | ||
max_n_datapts=50000, | ||
method="QuantileRegression", | ||
use_past_feat_dynamic_real=True, | ||
use_feat_dynamic_real=False, | ||
use_feat_dynamic_cat=False, | ||
use_feat_static_real=False, | ||
cardinality="auto", | ||
) | ||
predictor = predictor.train(dataset) | ||
forecasts = list(predictor.predict(dataset)) | ||
assert forecasts[1].quantile(0.5).shape[0] == prediction_length |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@leica2023 would this test fail before the fix contained in the PR? (That is, would it fail if run on the current
dev
branch)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct.