Skip to content

Commit

Permalink
fix corr selector
Browse files Browse the repository at this point in the history
  • Loading branch information
itlubber committed Sep 18, 2024
1 parent 00e0a93 commit a28774c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions scorecardpipeline/feature_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,18 @@ def fit(self, x: pd.DataFrame, y=None):
x = x.drop(columns=self.exclude)

self.n_features_in_ = x.shape[1]

if self.weights is None:
self.weights = pd.Series(np.zeros(self.n_features_in_), index=x.columns)
elif not isinstance(self.weights, pd.Series):
self.weights = pd.Series(self.weights.loc[x.columns], index=x.columns)
x = x[sorted(x.columns, key=self.weights.sort_values())]

_weight = pd.Series(np.zeros(self.n_features_in_), index=x.columns)

if self.weights is not None:
if isinstance(self.weights, pd.Series):
_weight_columns = list(set(self.weights.index) & set(x.columns))
_weight.loc[_weight_columns] = self.weights[_weight_columns]
else:
_weight = pd.Series(self.weights, index=x.columns)

self.weights = _weight
x = x[sorted(x.columns, key=self.weights.sort_values(), reverse=True)]

corr = x.corr(method=self.method, **self.kwargs)
self.scores_ = corr
Expand Down

0 comments on commit a28774c

Please sign in to comment.