def test_preprocess_data_scaling_mean(self): """Test that the input features have been correctly scaled to zero mean.""" model = BPLModel(TEST_DATA, X=TEST_FEATS) stan_data = model._pre_process_data() self.assertTrue( np.allclose(stan_data["X"].mean(axis=0), np.zeros(stan_data["X"].shape[1])) )
def test_preprocess_data_scaling_std(self): """Test that the input features have been correctly scaled to 0.5 standard deviation.""" model = BPLModel(TEST_DATA, X=TEST_FEATS) stan_data = model._pre_process_data() self.assertTrue( np.allclose(stan_data["X"].std(axis=0), 0.5 * np.ones(stan_data["X"].shape[1])))
def test_preprocess_data_nofeats(self): """Test that stan data dictionary has the correct keys when no features are passed.""" model = BPLModel(TEST_DATA, X=None) stan_data = model._pre_process_data() self.assertTrue( set(stan_data.keys()) == {"nteam", "nmatch", "home_team", "away_team", "home_goals", "away_goals"} )
def test_preprocess_data_date(self): """Test that the correct date constraint is applied in preprocessing.""" model = BPLModel(TEST_DATA, X=TEST_FEATS) stan_data = model._pre_process_data(max_date="2018-03-01") df = TEST_DATA.copy() df.loc[:, "date"] = pd.to_datetime(df["date"]) df = df[df["date"] <= "2018-03-01"] n = len(df) self.assertEqual(stan_data["nmatch"], n)