Пример #1
0
 def test_exogenous_input(self):
     """Test that no errors are raised when using exogenous features."""
     dtype = dtypes.float64
     times = [1, 2, 3, 4, 5, 6]
     values = [[0.01], [5.10], [5.21], [0.30], [5.41], [0.50]]
     feature_a = [["off"], ["on"], ["on"], ["off"], ["on"], ["off"]]
     sparse_column_a = feature_column.sparse_column_with_keys(
         column_name="feature_a", keys=["on", "off"])
     one_hot_a = layers.one_hot_column(sparse_id_column=sparse_column_a)
     regressor = estimators.StructuralEnsembleRegressor(
         periodicities=[],
         num_features=1,
         moving_average_order=0,
         exogenous_feature_columns=[one_hot_a],
         dtype=dtype)
     features = {
         TrainEvalFeatures.TIMES: times,
         TrainEvalFeatures.VALUES: values,
         "feature_a": feature_a
     }
     train_input_fn = input_pipeline.RandomWindowInputFn(
         input_pipeline.NumpyReader(features), window_size=6, batch_size=1)
     regressor.train(input_fn=train_input_fn, steps=1)
     eval_input_fn = input_pipeline.WholeDatasetInputFn(
         input_pipeline.NumpyReader(features))
     evaluation = regressor.evaluate(input_fn=eval_input_fn, steps=1)
     predict_input_fn = input_pipeline.predict_continuation_input_fn(
         evaluation,
         times=[[7, 8, 9]],
         exogenous_features={"feature_a": [[["on"], ["off"], ["on"]]]})
     regressor.predict(input_fn=predict_input_fn)
Пример #2
0
def _structural_ensemble_regressor(
    model_dir, head_type, exogenous_feature_columns):
  return ts_estimators.StructuralEnsembleRegressor(
      periodicities=None,
      num_features=5,
      exogenous_feature_columns=exogenous_feature_columns,
      head_type=head_type,
      model_dir=model_dir)
Пример #3
0
 def _estimator_fn(model_dir, exogenous_feature_columns):
     return estimators.StructuralEnsembleRegressor(
         num_features=1,
         periodicities=10,
         model_dir=model_dir,
         dtype=dtype,
         config=_SeedRunConfig(),
         exogenous_feature_columns=exogenous_feature_columns)
Пример #4
0
 def test_structural_ensemble_numpy_input(self):
     numpy_data = {
         "times": numpy.arange(50),
         "values": numpy.random.normal(size=[50])
     }
     estimators.StructuralEnsembleRegressor(
         num_features=1,
         periodicities=[],
         model_dir=self.get_temp_dir(),
         config=_SeedRunConfig()).train(input_pipeline.WholeDatasetInputFn(
             input_pipeline.NumpyReader(numpy_data)),
                                        steps=1)
Пример #5
0
 def test_no_periodicity(self):
     """Test that no errors are raised when periodicites is None."""
     dtype = dtypes.float64
     times = [1, 2, 3, 4, 5, 6]
     values = [[0.01], [5.10], [5.21], [0.30], [5.41], [0.50]]
     regressor = estimators.StructuralEnsembleRegressor(
         periodicities=None,
         num_features=1,
         moving_average_order=0,
         dtype=dtype)
     features = {
         TrainEvalFeatures.TIMES: times,
         TrainEvalFeatures.VALUES: values
     }
     train_input_fn = input_pipeline.RandomWindowInputFn(
         input_pipeline.NumpyReader(features), window_size=6, batch_size=1)
     regressor.train(input_fn=train_input_fn, steps=1)
     eval_input_fn = input_pipeline.WholeDatasetInputFn(
         input_pipeline.NumpyReader(features))
     evaluation = regressor.evaluate(input_fn=eval_input_fn, steps=1)
     predict_input_fn = input_pipeline.predict_continuation_input_fn(
         evaluation, times=[[7, 8, 9]])
     regressor.predict(input_fn=predict_input_fn)