Skip to content

Instantly share code, notes, and snippets.

@quantra-go-algo
Created May 22, 2024 16:32
Show Gist options
  • Save quantra-go-algo/dc6e516f28a19a54ba3b0c6b13beaa1a to your computer and use it in GitHub Desktop.
Save quantra-go-algo/dc6e516f28a19a54ba3b0c6b13beaa1a to your computer and use it in GitHub Desktop.
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