def test_predict_with_uncertainty(self, ): x_train_2, y_train_2 = self.feat._roll_train( self.train_data, past_seq_len=self.past_seq_len, future_seq_len=self.future_seq_len_2) x_test_2 = self.feat._roll_test(self.test_data, past_seq_len=self.past_seq_len) self.model_2.fit_eval(x_train_2, y_train_2, mc=True, **self.config) prediction, uncertainty = self.model_2.predict_with_uncertainty( x_test_2, n_iter=2) assert prediction.shape == (x_test_2.shape[0], self.future_seq_len_2) assert uncertainty.shape == (x_test_2.shape[0], self.future_seq_len_2) assert np.any(uncertainty) new_model_2 = LSTMSeq2Seq(check_optional_config=False) dirname = tempfile.mkdtemp(prefix="automl_test_feature") try: save(dirname, model=self.model_2) restore(dirname, model=new_model_2, config=self.config) prediction, uncertainty = new_model_2.predict_with_uncertainty( x_test_2, n_iter=2) assert prediction.shape == (x_test_2.shape[0], self.future_seq_len_2) assert uncertainty.shape == (x_test_2.shape[0], self.future_seq_len_2) assert np.any(uncertainty) finally: shutil.rmtree(dirname)
def test_save_restore_2(self): x_train_2, y_train_2 = self.feat._roll_train( self.train_data, past_seq_len=self.past_seq_len, future_seq_len=self.future_seq_len_2) x_test_2 = self.feat._roll_test(self.test_data, past_seq_len=self.past_seq_len) self.model_2.fit_eval(x_train_2, y_train_2, **self.config) predict_2_before = self.model_2.predict(x_test_2) new_model_2 = LSTMSeq2Seq(check_optional_config=False) dirname = tempfile.mkdtemp(prefix="automl_test_feature") try: save(dirname, model=self.model_2) restore(dirname, model=new_model_2, config=self.config) predict_2_after = new_model_2.predict(x_test_2) assert_array_almost_equal(predict_2_before, predict_2_after, decimal=2), \ "Prediction values are not the same after restore: " \ "predict before is {}, and predict after is {}".format(predict_2_before, predict_2_after) new_config = {'epochs': 2} new_model_2.fit_eval(x_train_2, y_train_2, **new_config) finally: shutil.rmtree(dirname)
def test_save_restore(self): new_model = VanillaLSTM(check_optional_config=False) self.model.fit_eval(self.x_train, self.y_train, **self.config) predict_before = self.model.predict(self.x_test) dirname = tempfile.mkdtemp(prefix="automl_test_vanilla") try: save(dirname, model=self.model) restore(dirname, model=new_model, config=self.config) predict_after = new_model.predict(self.x_test) assert_array_almost_equal(predict_before, predict_after, decimal=2) new_config = {'epochs': 2} new_model.fit_eval(self.x_train, self.y_train, **new_config) finally: shutil.rmtree(dirname)
def test_save_restore(self): self.model.fit_eval(data=(self.x_train, self.y_train), validation_data=(self.x_val, self.y_val), **self.config) y_pred = self.model.predict(self.x_test) assert y_pred.shape == (self.x_test.shape[0], self.y_train.shape[1]) dirname = "tmp" restored_model = MTNetKeras() try: save(dirname, model=self.model) restore(dirname, model=restored_model, config=self.config) predict_after = restored_model.predict(self.x_test) assert_array_almost_equal(y_pred, predict_after, decimal=2), \ "Prediction values are not the same after restore: " \ "predict before is {}, and predict after is {}".format(y_pred, predict_after) restored_model.fit_eval((self.x_train, self.y_train), epochs=1) restored_model.evaluate(self.x_val, self.y_val) finally: shutil.rmtree("tmp")
def test_predict_with_uncertainty(self, ): self.model.fit_eval(self.x_train, self.y_train, mc=True, **self.config) prediction, uncertainty = self.model.predict_with_uncertainty( self.x_test, n_iter=10) assert prediction.shape == (self.x_test.shape[0], 1) assert uncertainty.shape == (self.x_test.shape[0], 1) assert np.any(uncertainty) new_model = VanillaLSTM(check_optional_config=False) dirname = tempfile.mkdtemp(prefix="automl_test_feature") try: save(dirname, model=self.model) restore(dirname, model=new_model, config=self.config) prediction, uncertainty = new_model.predict_with_uncertainty( self.x_test, n_iter=2) assert prediction.shape == (self.x_test.shape[0], 1) assert uncertainty.shape == (self.x_test.shape[0], 1) assert np.any(uncertainty) finally: shutil.rmtree(dirname)