Skip to content

replace concat by group by target in encoders - #500

Merged
solegalli merged 8 commits into
mainfrom
replace_concat_encoders
Aug 18, 2022
Merged

replace concat by group by target in encoders#500
solegalli merged 8 commits into
mainfrom
replace_concat_encoders

Conversation

@solegalli

@solegalli solegalli commented Aug 17, 2022

Copy link
Copy Markdown
Collaborator

more elegant, simpler and, above all, faster implementation.

closes #427

@solegalli

Copy link
Copy Markdown
Collaborator Author

@glevv

Could you have a look at this PR, it is small, and let me know if you think there is a better or more performant implementation to capture these encodings?

I will greatly appreciate that :)

Comment thread feature_engine/encoding/woe.py Outdated
temp["non_target"] = np.where(temp["target"] == 1, 0, 1)
total_pos = y.sum()
total_neg = len(y) - total_pos
inverse_y = y.map({1: 0, 0:1}).copy()

@glevv glevv Aug 17, 2022

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

total_pos = y.sum()
inverse_y = y.ne(1).copy() or inverse_y = ~y.astype(bool).copy()
total_neg = inverse_y.sum()
should be faster

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @glevv

I also replaced the previous mapping by scaling :)

@solegalli
solegalli merged commit 8035f2d into main Aug 18, 2022
@solegalli
solegalli deleted the replace_concat_encoders branch August 18, 2022 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

replace concat in encoders by y_train.groupby(X_train["variable"]).mean().sort_values()

2 participants