Exemplo n.º 1
0
    def test_save_and_load(self):
        metric = Metric({"name": "rmse"})
        dt = DecisionTreeRegressorAlgorithm({"ml_task": "regression"})
        dt.fit(self.X, self.y)
        y_predicted = dt.predict(self.X)
        loss = metric(self.y, y_predicted)

        with tempfile.NamedTemporaryFile() as tmp:

            dt.save(tmp.name)
            dt2 = DecisionTreeRegressorAlgorithm({"ml_task": "regression"})
            dt2.load(tmp.name)

            y_predicted = dt2.predict(self.X)
            loss2 = metric(self.y, y_predicted)
            assert_almost_equal(loss, loss2)
Exemplo n.º 2
0
    def test_save_and_load(self):
        metric = Metric({"name": "rmse"})
        dt = DecisionTreeRegressorAlgorithm({"ml_task": "regression"})
        dt.fit(self.X, self.y)
        y_predicted = dt.predict(self.X)
        loss = metric(self.y, y_predicted)

        filename = os.path.join(tempfile.gettempdir(), os.urandom(12).hex())

        dt.save(filename)
        dt2 = DecisionTreeRegressorAlgorithm({"ml_task": "regression"})
        dt2.load(filename)

        y_predicted = dt2.predict(self.X)
        loss2 = metric(self.y, y_predicted)
        assert_almost_equal(loss, loss2)

        # Finished with temp file, delete it
        os.remove(filename)
Exemplo n.º 3
0
 def test_reproduce_fit_regression(self):
     metric = Metric({"name": "rmse"})
     params = {"max_depth": 1, "seed": 1, "ml_task": "regression"}
     prev_loss = None
     for _ in range(3):
         model = DecisionTreeRegressorAlgorithm(params)
         model.fit(self.X, self.y)
         y_predicted = model.predict(self.X)
         loss = metric(self.y, y_predicted)
         if prev_loss is not None:
             assert_almost_equal(prev_loss, loss)
         prev_loss = loss