示例#1
0
    def train(self, trainset):
        """
        Trains a random forest using RT-Rank.
        """

        self.n_classes = len(trainset.metadata['targets'])
        self.input_size = trainset.metadata['input_size']
        if self.max_height is None or self.max_height < 1:
            maxdepth = -1
        else:
            maxdepth = self.max_height

        if self.n_features_per_node is None:
            k_random_features = int(np.round(np.sqrt(self.input_size)))
        else:
            k_random_features = self.n_features_per_node

        self.trees = pyrtrank.pyrtrank_interface(self.input_size, maxdepth,
                                                 k_random_features, self.seed)

        # Add examples to RT-Rank training set
        import sys
        print 'Passing training data to RT-Rank library'
        sys.stdout.flush()
        for x, y in trainset:
            self.trees.add_example(float(y), 1, [xi for xi in x])

        print 'Training decision trees'
        sys.stdout.flush()
        for t in range(self.n_trees):
            # Add trees one at a time
            self.trees.train(True, True, True, self.zeros_are_missing, 1)
示例#2
0
    def train(self,trainset):
        """
        Trains an ensemble of trees using gradient boosting and RT-Rank.
        """

        self.input_size = trainset.metadata['input_size']
        if self.max_height is None or self.max_height < 1:
            maxdepth = -1
        else:
            maxdepth = self.max_height

        if self.n_features_per_node is None:
            k_random_features = int(np.round(np.sqrt(self.input_size)))
        else:
            k_random_features = self.n_features_per_node

        self.trees = pyrtrank.pyrtrank_interface(self.input_size,
                                                 maxdepth,
                                                 k_random_features,
                                                 self.seed)

        # Add examples to RT-Rank training set
        import sys
        print 'Passing training data to RT-Rank library'
        sys.stdout.flush()
        for x,y in trainset:
            self.trees.add_example(float(y),1,[xi for xi in x])

        print 'Training decision trees'
        sys.stdout.flush()
        for tree in range(self.n_trees):
            # Add trees one at a time
            self.trees.train(False,False,False,self.zeros_are_missing,self.n_processors)
            self.trees.subtract_predictions_from_targets(tree,self.learning_rate)
示例#3
0
    def train(self,trainset):
        """
        Trains a random forest using RT-Rank.
        """

        self.n_classes = len(trainset.metadata['targets'])
        self.input_size = trainset.metadata['input_size']
        if self.max_height is None or self.max_height < 1:
            maxdepth = -1
        else:
            maxdepth = self.max_height

        if self.n_features_per_node is None:
            k_random_features = int(np.round(np.sqrt(self.input_size)))
        else:
            k_random_features = self.n_features_per_node

        self.trees = pyrtrank.pyrtrank_interface(self.input_size,
                                                 maxdepth,
                                                 k_random_features,
                                                 self.seed)

        # Add examples to RT-Rank training set
        import sys
        print 'Passing training data to RT-Rank library'
        sys.stdout.flush()
        for x,y in trainset:
            self.trees.add_example(float(y),1,[xi for xi in x])

        print 'Training decision trees'
        sys.stdout.flush()
        for t in range(self.n_trees):
            # Add trees one at a time
            self.trees.train(True,True,True,self.zeros_are_missing,1)
示例#4
0
文件: regression.py 项目: pgcool/TMBP
    def train(self, trainset):
        """
        Trains an ensemble of trees using gradient boosting and RT-Rank.
        """

        self.input_size = trainset.metadata['input_size']
        if self.max_height is None or self.max_height < 1:
            maxdepth = -1
        else:
            maxdepth = self.max_height

        if self.n_features_per_node is None:
            k_random_features = int(np.round(np.sqrt(self.input_size)))
        else:
            k_random_features = self.n_features_per_node

        self.trees = pyrtrank.pyrtrank_interface(self.input_size, maxdepth,
                                                 k_random_features, self.seed)

        # Add examples to RT-Rank training set
        import sys
        print 'Passing training data to RT-Rank library'
        sys.stdout.flush()
        for x, y in trainset:
            self.trees.add_example(float(y), 1, [xi for xi in x])

        print 'Training decision trees'
        sys.stdout.flush()
        for tree in range(self.n_trees):
            # Add trees one at a time
            self.trees.train(False, False, False, self.zeros_are_missing,
                             self.n_processors)
            self.trees.subtract_predictions_from_targets(
                tree, self.learning_rate)