Created
May 22, 2024 16:32
-
-
Save quantra-go-algo/dc6e516f28a19a54ba3b0c6b13beaa1a 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
def dropLabels(events,minPct=.05): | |
# apply weights, drop labels with insufficient examples | |
while True: | |
# Count the number of observations the prediction feature has for each label | |
df0=events['y'].value_counts(normalize=True) | |
# If the label with minimum number of observations is lower than the minPct threshold | |
# or the number of labels in the prediction features is 2, then break the while loop | |
if (df0.min()>minPct) or (df0.shape[0]<3):break | |
# Drop the label with minimum number of observations | |
events = events[events['y']!=df0.index[df0.argmin()]] | |
return events |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment