Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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) |
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
lbl_vc = feature_label_df['labels'].value_counts() | |
total = lbl_vc.sum() | |
mu = 3.0 | |
class_weights = {} | |
for i, k in enumerate(lbl_vc.keys()): | |
w = np.log(mu * total / float(lbl_vc[k])) | |
class_weights[i] = w if w > 1 else 1 | |
print(class_weights) |
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
def label_smoothing(y, factor=0.1): | |
y *= 1 - factor | |
y += factor / y.shape[1] | |
return y |