def test_save_and_load(self): metric = Metric({"name": "logloss"}) rf = ExtraTreesAlgorithm({"ml_task": "binary_classification"}) rf.fit(self.X, self.y) y_predicted = rf.predict(self.X) loss = metric(self.y, y_predicted) with tempfile.NamedTemporaryFile() as tmp: rf.save(tmp.name) rf2 = ExtraTreesAlgorithm({"ml_task": "binary_classification"}) rf2.load(tmp.name) y_predicted = rf2.predict(self.X) loss2 = metric(self.y, y_predicted) assert_almost_equal(loss, loss2)
def test_save_and_load(self): metric = Metric({"name": "logloss"}) rf = ExtraTreesAlgorithm({"ml_task": "binary_classification"}) rf.fit(self.X, self.y) y_predicted = rf.predict(self.X) loss = metric(self.y, y_predicted) filename = os.path.join(tempfile.gettempdir(), os.urandom(12).hex()) rf.save(filename) rf2 = ExtraTreesAlgorithm({"ml_task": "binary_classification"}) rf2.load(filename) # Finished with the file, delete it os.remove(filename) y_predicted = rf2.predict(self.X) loss2 = metric(self.y, y_predicted) assert_almost_equal(loss, loss2)