def test_dump_and_load_before_fitting(tmpdir): model1 = pf.LinearRegression(7) fname = str(tmpdir.join("test_model.pkl")) model1.save(fname) model2 = pf.load(fname) assert isinstance(model2, pf.LinearRegression) assert model1 is not model2 post1 = model1.posterior_mean() post2 = model2.posterior_mean() for k in post1: assert isclose(post1[k], post2[k])
def test_dump_and_load_after_fitting(tmpdir): model1 = pf.LinearRegression(7) x, y = get_test_data(1024, 7) model1.fit(x, y, epochs=2) fname = str(tmpdir.join("test_model.pkl")) model1.save(fname) model2 = pf.load(fname) assert isinstance(model2, pf.LinearRegression) assert model1 is not model2 post1 = model1.posterior_mean() post2 = model2.posterior_mean() for k in post1: assert isclose(post1[k], post2[k])
def load_model(self, filename): self.model = pf.load(filename) return self.model