Created
December 30, 2019 03:09
-
-
Save djsegal/54d6047cd1495925517896f51d5dea2d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from sklearn.base import BaseEstimator | |
from sklearn.feature_selection.base import SelectorMixin | |
class CleanFeatures(BaseEstimator, SelectorMixin): | |
def __init__(self): | |
self.sieve = [] | |
def _get_support_mask(self): | |
assert len(self.sieve) > 0 | |
return self.sieve | |
def fit(self, X, y=None): | |
cur_sieve = [True] * X.shape[-1] | |
for cur_index, this_col in enumerate(X.T): | |
for that_col in X.T[:cur_index,:]: | |
if np.sum(np.abs(this_col*that_col-1)) > 1e-8 : continue | |
cur_sieve[cur_index] = False | |
break | |
self.sieve = np.array(cur_sieve) | |
self.sieve[0] = True | |
return self |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment