def test_remodel_sample_data(self): """ Data sampled from a given model should result in a similar model if fit again. """ model = ARIMAModel(2, 1, 2, [8.2, 0.2, 0.5, 0.3, 0.1], sc=self.sc) sampled = model.sample(1000) newModel = fit_model(2, 1, 2, sampled, sc=self.sc) (c, ar1, ar2, ma1, ma2) = model.coefficients (cTest, ar1Test, ar2Test, ma1Test, ma2Test) = newModel.coefficients self.assertAlmostEqual(c, cTest, delta=1) self.assertAlmostEqual(ar1, ar1Test, delta=0.1) self.assertAlmostEqual(ar2, ar2Test, delta=0.1) self.assertAlmostEqual(ma1, ma1Test, delta=0.1) self.assertAlmostEqual(ma2, ma2Test, delta=0.1)
def test_stationarity_and_invertability(self): model1 = ARIMAModel(1, 0, 0, [0.2, 1.5], hasIntercept = True, sc=self.sc) self.assertFalse(model1.is_stationary()) self.assertTrue(model1.is_invertible()) model2 = ARIMAModel(0, 0, 1, [0.13, 1.8], hasIntercept = True, sc=self.sc) self.assertTrue(model2.is_stationary()) self.assertFalse(model2.is_invertible()) model3 = ARIMAModel(2, 0, 0, [0.003359, 1.545, -0.5646], hasIntercept = True, sc=self.sc) self.assertTrue(model3.is_stationary()) self.assertTrue(model3.is_invertible()) model4 = ARIMAModel(1, 0, 1, [-0.09341, 0.857361, -0.300821], hasIntercept = True, sc=self.sc) self.assertTrue(model4.is_stationary()) self.assertTrue(model4.is_invertible())