예제 #1
0
 def test_fit_predict(self):
     metric = Metric({"name": "logloss"})
     nn = MLPAlgorithm(self.params)
     nn.fit(self.X, self.y)
     y_predicted = nn.predict_proba(self.X)
     loss = metric(self.y, y_predicted)
     self.assertLess(loss, 2)
예제 #2
0
    def test_save_and_load(self):
        metric = Metric({"name": "logloss"})
        nn = MLPAlgorithm(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 = MLPAlgorithm(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)
예제 #3
0
    def test_copy(self):
        # train model #1
        metric = Metric({"name": "logloss"})
        nn = MLPAlgorithm(self.params)
        nn.fit(self.X, self.y)
        y_predicted = nn.predict(self.X)
        loss = metric(self.y, y_predicted)
        # create model #2
        nn2 = MLPAlgorithm(self.params)
        # do a copy and use it for predictions
        nn2 = nn.copy()
        self.assertEqual(type(nn), type(nn2))
        y_predicted = nn2.predict(self.X)
        loss2 = metric(self.y, y_predicted)
        self.assertEqual(loss, loss2)

        # the loss of model #2 should not change
        y_predicted = nn2.predict(self.X)
        loss4 = metric(self.y, y_predicted)
        assert_almost_equal(loss2, loss4)
예제 #4
0
 def test_is_fitted(self):
     model = MLPAlgorithm(self.params)
     self.assertFalse(model.is_fitted())
     model.fit(self.X, self.y)
     self.assertTrue(model.is_fitted())