예제 #1
0
    def test_save_and_load(self):
        metric = Metric({"name": "logloss"})
        model = LinearAlgorithm({"ml_task": "binary_classification"})
        model.fit(self.X, self.y)
        y_predicted = model.predict(self.X)
        loss = metric(self.y, y_predicted)

        with tempfile.NamedTemporaryFile() as tmp:

            model.save(tmp.name)
            model2 = LinearAlgorithm({"ml_task": "binary_classification"})
            model2.load(tmp.name)

            y_predicted = model2.predict(self.X)
            loss2 = metric(self.y, y_predicted)
            assert_almost_equal(loss, loss2)
예제 #2
0
    def test_save_and_load(self):
        metric = Metric({"name": "logloss"})
        model = LinearAlgorithm({"ml_task": "binary_classification"})
        model.fit(self.X, self.y)
        y_predicted = model.predict(self.X)
        loss = metric(self.y, y_predicted)

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

        model.save(filename)
        model2 = LinearAlgorithm({"ml_task": "binary_classification"})
        model2.load(filename)
        # Finished with the file, delete it
        os.remove(filename)

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