コード例 #1
0
class RegularizedGreedyForestEstimator(BaseEstimator):
    def __init__(self, max_leaf_nodes=500, l2=0.01,  loss='LS',
                 test_interval=100, verbose=False):
        self.max_leaf_nodes = max_leaf_nodes
        self.l2 = l2
        self.loss = loss
        self.test_interval = test_interval
        self.verbose = verbose

        self.ensemble = None

    def _fit(self, X, y, sample_weight=None):
        check_weight(sample_weight)
        # need to check X is c-contigous!

        if self.ensemble is None:
            self.ensemble = RGFTreeEnsemble()

        builder = RGFBuilder(self.max_leaf_nodes, self.l2, self.loss,
                             self.test_interval, self.verbose)
        builder.build(self.ensemble, X, y, sample_weight)

    def fit(self, X, y, sample_weight=None):
        self._fit(X, y, sample_weight)

    def _validate_X_predict(self, X):
        if self.ensemble is None or len(self.ensemble) == 0:
            raise NotFittedError("Estimator not fitted, "
                                 "all `fit` before exploiting the model.")
        return X

    def predict(self, X):
        X = self._validate_X_predict(X)
        return self.ensemble.predict(X)
コード例 #2
0
    def _fit(self, X, y, sample_weight=None):
        check_weight(sample_weight)
        # need to check X is c-contigous!

        if self.ensemble is None:
            self.ensemble = RGFTreeEnsemble()

        builder = RGFBuilder(self.max_leaf_nodes, self.l2, self.loss,
                             self.test_interval, self.verbose)
        builder.build(self.ensemble, X, y, sample_weight)