Beispiel #1
0
    def test_save_and_load(self):
        metric = Metric({"name": "logloss"})
        nn = NeuralNetworkAlgorithm(self.params)
        nn.fit(self.X, self.y)
        y_predicted = nn.predict(self.X)
        loss = metric(self.y, y_predicted)

        with tempfile.NamedTemporaryFile() as tmp:

            nn.save(tmp.name)
            json_desc = nn.get_params()
            nn2 = NeuralNetworkAlgorithm(json_desc["params"])
            nn2.load(tmp.name)

            y_predicted = nn2.predict(self.X)
            loss2 = metric(self.y, y_predicted)
            assert_almost_equal(loss, loss2)
Beispiel #2
0
    def test_save_and_load(self):
        metric = Metric({"name": "logloss"})
        nn = NeuralNetworkAlgorithm(self.params)
        nn.fit(self.X, self.y)
        y_predicted = nn.predict(self.X)
        loss = metric(self.y, y_predicted)

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

        nn.save(filename)
        json_desc = nn.get_params()
        nn2 = NeuralNetworkAlgorithm(json_desc["params"])
        nn2.load(filename)
        #Finished with the file, delete it
        os.remove(filename)

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