Skip to content

Instantly share code, notes, and snippets.

@djsegal
Created December 30, 2019 03:09
Show Gist options
  • Save djsegal/54d6047cd1495925517896f51d5dea2d to your computer and use it in GitHub Desktop.
Save djsegal/54d6047cd1495925517896f51d5dea2d to your computer and use it in GitHub Desktop.
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