Skip to content

Commit

Permalink
Merge pull request #143 from perib/main
Browse files Browse the repository at this point in the history
allow genetic feature selection to work with nan values
  • Loading branch information
nickotto authored Aug 22, 2024
2 parents 908eeca + 2e5f90b commit 05d1919
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions tpot2/builtin_modules/feature_set_selector.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ def fit(self, X, y=None):

# def transform(self, X):

def _get_tags(self):
tags = {"allow_nan": True, "requires_y": False}
return tags

def _get_support_mask(self):
"""
Expand Down
16 changes: 15 additions & 1 deletion tpot2/search_spaces/nodes/genetic_feature_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,29 @@
class MaskSelector(BaseEstimator, SelectorMixin):
"""Select predefined feature subsets."""

def __init__(self, mask):
def __init__(self, mask, set_output_transform=None):
self.mask = mask
self.set_output_transform = set_output_transform
if set_output_transform is not None:
self.set_output(transform=set_output_transform)

def fit(self, X, y=None):
self.n_features_in_ = X.shape[1]
if isinstance(X, pd.DataFrame):
self.feature_names_in_ = X.columns
# self.set_output(transform="pandas")
self.is_fitted_ = True #so sklearn knows it's fitted
return self

def _get_tags(self):
tags = {"allow_nan": True, "requires_y": False}
return tags

def _get_support_mask(self):
return np.array(self.mask)

def get_feature_names_out(self, input_features=None):
return self.feature_names_in_[self.get_support()]

class GeneticFeatureSelectorIndividual(SklearnIndividual):
def __init__( self,
Expand Down

0 comments on commit 05d1919

Please sign in to comment.