def test_maui_can_save_to_folder(): maui_model = Maui(n_hidden=[10], n_latent=2, epochs=1) maui_model = maui_model.fit({"d1": df1, "d2": df2}) with tempfile.TemporaryDirectory() as tmpdirname: maui_model.save(tmpdirname) assert os.path.isfile(os.path.join(tmpdirname, 'maui_weights.h5')) assert os.path.isfile(os.path.join(tmpdirname, 'maui_args.json'))
def test_maui_model_saves_feature_names_to_disk(): maui_model = Maui(n_hidden=[10], n_latent=2, epochs=1) maui_model = maui_model.fit({"d1": df1, "d2": df2}) with tempfile.TemporaryDirectory() as tmpdirname: maui_model.save(tmpdirname) maui_model_from_disk = Maui.load(tmpdirname) assert maui_model.feature_names == maui_model_from_disk.feature_names
def test_maui_model_loads_model_without_feature_names_from_disk_and_warns(): maui_model = Maui(n_hidden=[10], n_latent=2, epochs=1) maui_model = maui_model.fit({"d1": df1, "d2": df2}) with tempfile.TemporaryDirectory() as tmpdirname: maui_model.save(tmpdirname) os.remove(os.path.join(tmpdirname, "maui_feature_names.txt")) with pytest.warns(MauiWarning): maui_model_from_disk = Maui.load(tmpdirname) assert maui_model_from_disk.feature_names is None
def test_maui_can_load_from_folder(): maui_model = Maui(n_hidden=[10], n_latent=2, epochs=1) maui_model = maui_model.fit({"d1": df1, "d2": df2}) with tempfile.TemporaryDirectory() as tmpdirname: maui_model.save(tmpdirname) maui_model_from_disk = Maui.load(tmpdirname) assert maui_model_from_disk.n_latent == maui_model.n_latent assert np.allclose(maui_model.vae.get_weights()[0], maui_model_from_disk.vae.get_weights()[0]) assert np.allclose( maui_model.transform({"d1": df1, "d2": df2}), maui_model_from_disk.transform({"d1": df1, "d2": df2}) )