Created
January 6, 2021 03:07
-
-
Save MattLowrieDS/f977588f8ef54c903711836918145914 to your computer and use it in GitHub Desktop.
Example using sklearn compute_class_weight()
This file contains 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
from sklearn.utils.class_weight import compute_class_weight | |
pass_results = plays_df.loc[plays_df['passResult'].isin(category_lookup.keys()), 'passResult'] | |
all_labels = pass_results.apply(lambda lbl: category_lookup[lbl]) | |
# Create class weights to counter-balance classification during training | |
y = np.stack(all_labels).argmax(axis=1) | |
classes = np.unique(y) | |
weights = compute_class_weight('balanced', classes=classes, y=y) | |
class_weights = {k: v for k, v in zip(classes, weights)} | |
print('Class weights:', class_weights) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment