def test_save_restore(self):
        self.model.fit_eval((self.x, self.y), [(self.val_x, self.val_y)])

        result_save = self.model.predict(self.val_x)
        model_file = "tmp.pkl"
        self.model.save(model_file)
        assert os.path.isfile(model_file)
        new_model = XGBoost()
        new_model.restore(model_file)
        assert new_model.model
        result_restore = new_model.predict(self.val_x)
        assert_array_almost_equal(result_save, result_restore, decimal=2), \
            "Prediction values are not the same after restore: " \
            "predict before is {}, and predict after is {}".format(result_save, result_restore)
        os.remove(model_file)
Beispiel #2
0
 def build_from_ckpt(self, checkpoint_filename):
     from zoo.orca.automl.xgboost.XGBoost import XGBoost
     model = XGBoost(model_type=self.model_type, config=self.model_config)
     model.restore(checkpoint_filename)
     return model