Exemple #1
0
    def test_boosting_tree(self):
        proto = tree_pb2.BoostingTreeEnsambleProto(
            params=tree_pb2.BoostingParamsProto(
                num_rounds=2,
                max_depth=3,
                lam=1.0,
                sketch_eps=0.2))
        booster = BoostingTreeEnsamble(proto)

        data = load_iris()
        labels = data.target
        labels = np.minimum(labels, 1)
        features = {str(i): data.data[:, i] for i in range(data.data.shape[1])}
        booster.fit(None, [i for i in range(len(data.target))], features, labels)
Exemple #2
0
 def load_saved_model(self, path):
     fin = tf.io.gfile.GFile(path, 'r')
     model = tree_pb2.BoostingTreeEnsambleProto()
     text_format.Parse(fin.read(), model)
     self._trees = list(model.trees)
Exemple #3
0
 def save_model(self, path):
     fout = tf.io.gfile.GFile(path, 'w')
     model = tree_pb2.BoostingTreeEnsambleProto()
     model.trees.extend(self._trees)
     fout.write(text_format.MessageToString(model))
Exemple #4
0
 def load_saved_model(self, path):
     with open(path, 'r') as fin:
         model = tree_pb2.BoostingTreeEnsambleProto()
         text_format.Parse(fin.read(), model)
         self._trees = list(model.trees)
Exemple #5
0
 def save_model(self, path):
     with open(path, 'w') as fout:
         model = tree_pb2.BoostingTreeEnsambleProto()
         model.trees.extend(self._trees)
         fout.write(text_format.MessageToString(model))