Skip to content

Instantly share code, notes, and snippets.

@makispl
Last active Aug 31, 2021
Embed
What would you like to do?
# allocate weights
wts = []
for col in features:
if col in group_1:
wts.append(0.5)
elif col in group_2:
wts.append(0.3)
elif col in group_3:
wts.append(0.2)
elif col in group_4:
wts.append(0)
else:
wts.append(-0.3)
# make a dictionary of key:value feature: weight
weights_dict = dict(zip(features, wts))
# segment the eligible for score original dataset
scores_df = plays_df.loc[:, features].copy()
clustered_scores_df = clustered_plays_df.loc[:, features].copy()
# the calculations to be executed
plays_df['NET_SCORE'] = scores_df.dot(pd.Series(weights_dict))
clustered_plays_df['NET_SCORE'] = clustered_scores_df.dot(pd.Series(weights_dict))
# score clusters
clustered_plays_df.groupby(['gm_cluster'])[group_1 + ['NET_SCORE']].agg(np.mean)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment