Exemplo n.º 1
0
 def test_model_evaluation(self):
     models = [ARIMA((1, 1, 0)), ARIMA((2, 1, 1)), VAR(1), VAR(3)]
     results = model_evaluation(data, models, n_folds=10, forecast_steps=3)
     results = np.array(results, dtype=object)
     self.assertEqual(results.shape, (4 * 2 + 1, 8))
     np.testing.assert_equal(results[1:, 1:].astype(float) > 0, True)
Exemplo n.º 2
0
            if var.is_continuous and var != data.time_variable
        ])

    @Inputs.forecast
    def set_forecast(self, forecast, id):
        if forecast is not None:
            self.forecasts[id] = forecast
        else:
            self.forecasts.pop(id, None)
        # TODO: update currently shown plots


if __name__ == "__main__":
    from AnyQt.QtWidgets import QApplication
    from orangecontrib.timeseries import ARIMA, VAR

    a = QApplication([])
    ow = OWLineChart()

    airpassengers = Timeseries('airpassengers')
    ow.set_data(airpassengers),

    msft = airpassengers.interp()
    model = ARIMA((3, 1, 1)).fit(airpassengers)
    ow.set_forecast(model.predict(10, as_table=True), 0)
    model = VAR(4).fit(msft)
    ow.set_forecast(model.predict(10, as_table=True), 1)

    ow.show()
    a.exec()
Exemplo n.º 3
0
 def test_predict_as_table(self):
     model = VAR(2)
     model.fit(data)
     forecast = model.predict(10, as_table=True)
     self.assertEqual(len(forecast.domain.variables), 2 * (1 + 2))
Exemplo n.º 4
0
 def test_predict(self):
     model = VAR(2)
     model.fit(data)
     forecast, ci95_low, ci95_high = model.predict(10)
     self.assertTrue(
         np.logical_and(forecast > ci95_low, forecast < ci95_high).all())

if __name__ == "__main__":
    from AnyQt.QtWidgets import QApplication
    from Orange.data import Domain
    from orangecontrib.timeseries import ARIMA, VAR

    a = QApplication([])
    ow = OWModelEvaluation()

    data = Timeseries('yahoo_MSFT')
    # Make Adjusted Close a class variable
    attrs = [var.name for var in data.domain.attributes]
    if 'Adj Close' in attrs:
        attrs.remove('Adj Close')
        data = Timeseries(
            Domain(attrs, [data.domain['Adj Close']], None,
                   source=data.domain), data)

    ow.set_data(data)
    ow.set_model(ARIMA((1, 1, 1)), 1)
    ow.set_model(ARIMA((2, 1, 0)), 2)
    # ow.set_model(ARIMA((0, 1, 1)), 3)
    # ow.set_model(ARIMA((4, 1, 0)), 4)
    ow.set_model(VAR(1), 11)
    ow.set_model(VAR(5), 12)
    # ow.set_model(VAR(6), 14)

    ow.show()
    a.exec()
Exemplo n.º 6
0
        super().closeEvent(event)

    def closeContext(self) -> None:
        """
        Gather configs in contextVariables and close context.
        """
        if not self.features:
            # only close in case of when features are not present if they are
            # feature selection is defined by the input and context should
            # not have impact
            attrs, is_logit = [], []
            for config in self.configs:
                attrs.append(config.get_selection())
                is_logit.append(config.is_logarithmic)
            self.attrs = attrs
            self.is_logit = is_logit
            super().closeContext()


if __name__ == "__main__":
    from orangecontrib.timeseries import ARIMA, VAR

    airpassengers = Timeseries.from_file('airpassengers')
    msft = airpassengers.interp()
    model1 = ARIMA((3, 1, 1)).fit(airpassengers)
    model2 = VAR(4).fit(msft)
    ow = WidgetPreview(OWLineChart)
    ow.run(set_data=airpassengers,
           set_forecast=[(model1.predict(10, as_table=True), 0),
                         (model2.predict(10, as_table=True), 1)])
Exemplo n.º 7
0
 def create_learner(self):
     ic = self.IC_LABELS[tuple(self.IC_LABELS.keys())[self.ic]]
     trend = self.TREND_LABELS[tuple(self.TREND_LABELS.keys())[self.trend]]
     return VAR(self.maxlags, ic, trend)