anchors/limes/lime_base.py
def forward_selection(self, data, labels, weights, num_features, model_regressor=None):
        """Iteratively adds features to the model"""
        if model_regressor is None:
            model_regressor = Ridge(alpha=0, fit_intercept=True, random_state=self.random_state)
        clf = model_regressor
        used_features = []
        for _ in range(min(num_features, data.shape[1])):
            max_ = -100000000
            best = 0
            for feature in range(data.shape[1]):
                if feature in used_features:
                    continue
                clf.fit(data[:, used_features + [feature]], labels, 
                        sample_weight=weights)
                score = clf.score(data[:, used_features + [feature]],
                                  labels,
                                  sample_weight=weights)
                if score > max_:
                    best = feature
                    max_ = score
            used_features.append(best)
        return np.array(used_features)
Iteratively adds features to the model
Iteratively adds features to the model
Iteratively adds features to the model
def forward_selection(self, data, labels, weights, num_features, model_regressor=None):
        if model_regressor is None:
            model_regressor = Ridge(alpha=0, fit_intercept=True, random_state=self.random_state)
        clf = model_regressor
        used_features = []
        for _ in range(min(num_features, data.shape[1])):
            max_ = -100000000
            best = 0
            for feature in range(data.shape[1]):
                if feature in used_features:
                    continue
                clf.fit(data[:, used_features + [feature]], labels, 
                        sample_weight=weights)
                score = clf.score(data[:, used_features + [feature]],
                                  labels,
                                  sample_weight=weights)
                if score > max_:
                    best = feature
                    max_ = score
            used_features.append(best)
        return np.array(used_features)
def forward_selection ( self , data , labels , weights , num_features , model_regressor = None ) : if model_regressor is None : model_regressor = Ridge ( alpha = 0 , fit_intercept = True , random_state = self . random_state ) clf = model_regressor used_features = [ ] for _ in range ( min ( num_features , data . shape [ 1 ] ) ) : max_ = - 100000000 best = 0 for feature in range ( data . shape [ 1 ] ) : if feature in used_features : continue clf . fit ( data [ : , used_features + [ feature ] ] , labels , sample_weight = weights ) score = clf . score ( data [ : , used_features + [ feature ] ] , labels , sample_weight = weights ) if score > max_ : best = feature max_ = score used_features . append ( best ) return np . array ( used_features )
Iteratively adds features to the model
Iteratively adds features to the model
"""Iteratively adds features to the model"""
self
data
labels
weights
num_features
model_regressor