Example #1
0
 def test_non_seasonal_arima1(self):
     ts_data = self.getData4()
     f_name='non_seasonal_arima1.pmml'
     model = ARIMA(ts_data,order=(9, 2, 0))
     result = model.fit(trend = 'c', method = 'css-mle')
     StatsmodelsToPmml(result, f_name, model_name="arima_920")
     self.assertEqual(os.path.isfile(f_name),True)
Example #2
0
 def test_non_seasonal_arima3(self):
     ts_data = self.getData4()
     f_name='non_seasonal_arima3.pmml'
     model = ARIMA(ts_data,order=(1, 0, 1))
     result = model.fit(trend = 'c', method = 'css-mle')
     StatsmodelsToPmml(result, f_name, description="A test model")
     self.assertEqual(os.path.isfile(f_name),True)
 def test_non_seasonal_arima2(self):
     ts_data = self.getData4()
     f_name = 'non_seasonal_arima2.pmml'
     model = ARIMA(ts_data, order=(9, 2, 3))
     result = model.fit(trend='nc', method='css-mle')
     ArimaToPMML(result, f_name, description="A test model")
     self.assertEqual(os.path.isfile(f_name), True)
Example #4
0
 def test_non_seasonal_arima8(self):
     ts_data = self.statsmodels_data_helper.get_non_seasonal_data()
     f_name = 'non_seasonal_arima8.pmml'
     model = ARIMA(ts_data, order=(5, 1, 2))
     result = model.fit(trend='c', method='mle')
     ArimaToPMML(result, f_name, conf_int=[80, 95])
     self.assertEqual(self.schema.is_valid(f_name), True)
Example #5
0
 def test_non_seasonal_arima1(self):
     ts_data = self.statsmodels_data_helper.get_non_seasonal_data()
     f_name = 'non_seasonal_arima1.pmml'
     model = ARIMA(ts_data, order=(9, 2, 0))
     result = model.fit(trend='c', method='css-mle')
     ArimaToPMML(result, f_name)
     self.assertEqual(self.schema.is_valid(f_name), True)
Example #6
0
 def test_non_seasonal_arima7(self):
     ts_data = self.statsmodels_data_helper.get_non_seasonal_data()
     f_name = 'non_seasonal_arima7.pmml'
     model = ARIMA(ts_data, order=(5, 1, 2))
     result = model.fit(trend='nc', method='mle')
     StatsmodelsToPmml(result, f_name)
     self.assertEqual(self.schema.is_valid(f_name), True)
Example #7
0
    def train(self, array_X, array_Y):
        self.train_X = array_X
        self.train_Y = array_Y
        array = numpy.concatenate((numpy.array([array_Y]).T, array_X), axis=1)
        idx = pd.date_range('20130101', periods=48000)
        #xxx= pd.DataFrame(data=numpy.array([array_Y]),index=idx)
        xxx = pd.DataFrame(data=array, index=idx)

        model = ARIMA(endog=xxx, order=(0, 1, 1))
        fit = model.fit()
        res = fit.fittedvalues.values[:, 0]
        res = numpy.hstack((res[0], res))
        return res
Example #8
0
    def predict(self, test_X, test_Y):
        predictions = numpy.empty(0)

        array_train = numpy.concatenate(
            (numpy.array([self.train_Y]).T, self.train_X), axis=1)
        array_test = numpy.concatenate((numpy.array([test_Y]).T, test_X),
                                       axis=1)

        for t in range(0, test_Y.shape[0]):
            array = numpy.vstack((array_train, array_test[:t]))
            model = ARIMA(endog=pd.DataFrame(data=array))
            fit = model.fit()
            lag = fit.k_ar
            pred = fit.forecast(array[-lag:], 1)[0]
            predictions = numpy.append(predictions, pred[0])

        return predictions