def test_data_none(self):
     w = self.widget
     self.send_signal(w.Inputs.time_series, None)
     # send selection when no data on the input
     self.send_signal(
         w.Inputs.features, AttributeList(self.airpassengers.attributes)
     )
     # send forecast on empty data
     model1 = ARIMA((3, 1, 1)).fit(self.airpassengers)
     prediction = model1.predict(10, as_table=True)
     self.send_signal(w.Inputs.forecast, prediction, 1)
 def test_bad_model(self):
     """
     Do not fail on a bad model.
     GH-37
     """
     w = self.widget
     table = Table("housing")
     time_series = Timeseries(table)
     model = ARIMA((2, 5, 1), 0)
     self.assertFalse(w.Warning.model_not_appropriate.is_shown())
     self.send_signal(w.Inputs.time_series, time_series)
     self.send_signal(w.Inputs.time_series_model, model, 0)
     w.controls.autocommit.click()
     self.assertTrue(w.Warning.model_not_appropriate.is_shown())
     self.send_signal(w.Inputs.time_series_model, None, 0)
     self.assertFalse(w.Warning.model_not_appropriate.is_shown())
Exemplo n.º 3
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.º 4
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.º 5
0
 def test_predict_as_table(self):
     model = ARIMA((2, 1, 0))
     model.fit(data)
     forecast = model.predict(10, as_table=True)
     self.assertEqual(len(forecast.domain.variables), 1 + 2)
Exemplo n.º 6
0
 def test_predict(self):
     model = ARIMA((2, 1, 0))
     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.º 8
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.º 9
0
        self.chart.enable_rangeSelector(
            isinstance(data.time_variable, TimeVariable))

    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 PyQt4.QtGui import QApplication
    from orangecontrib.timeseries import ARIMA, VAR

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

    msft = Timeseries('yahoo_MSFT')
    ow.set_data(msft),
    # ow.set_data(Timeseries('UCI-SML2010-1'))

    msft = msft.interp()
    model = ARIMA((3, 1, 1)).fit(msft)
    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.º 10
0
 def create_learner(self):
     return ARIMA((self.p, self.d, self.q), self.use_exog)
Exemplo n.º 11
0
        self.varmodel.wrap([var for var in data.domain.variables
                            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()