forked from awslabs/gluonts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_estimator.py
50 lines (41 loc) · 1.71 KB
/
_estimator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
from gluonts.core.component import validated
from gluonts.dataset.common import Dataset
from gluonts.model.estimator import Estimator, Predictor
from ._predictor import TreePredictor
class ThirdPartyEstimator(Estimator):
"""
An `Estimator` that uses an external fitting mechanism, thus eliminating
the need for a Trainer. Differs from DummyEstimator in that DummyEstimator
does not use the training data, but merely trains at prediction time.
Parameters
----------
predictor_cls
`Predictor` class to instantiate.
**kwargs
Keyword arguments to pass to the predictor constructor.
"""
@validated()
def __init__(self, predictor_cls: type, **kwargs) -> None:
self.predictor = predictor_cls(**kwargs)
def train(
self, training_data: Dataset, validation_dataset=None
) -> Predictor:
return self.predictor.train(training_data)
class TreeEstimator(ThirdPartyEstimator):
@validated(
getattr(TreePredictor.__init__, "Model")
) # Reuse the model Predictor model
def __init__(self, **kwargs) -> None:
super().__init__(predictor_cls=TreePredictor, **kwargs)