Skip to content

Added Silhouette Score. See skekre98/NBA-Search/issues/33 #151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion modules/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from modules.scraper import get_player_stats
from sklearn.preprocessing import LabelEncoder
from sklearn.cluster import KMeans
from sklearn.metrics import silhouette_score

nlp = spacy.load("en_core_web_sm")

Expand Down Expand Up @@ -130,6 +131,10 @@ def build_stat_clusters(clusters):
cluster_map = pd.DataFrame()
cluster_map['data_index'] = data.index.values
cluster_map['cluster'] = km.labels_

# Check Silhouette Score
silhouette_scr = silhouette_score(data, km.labels_, metric='euclidean')
print('Silhouette Score: %.3f' % silhouette_scr)

# cluster list
player_clusters = []
Expand All @@ -141,4 +146,4 @@ def build_stat_clusters(clusters):
group.append(p_map[cluster['data_index']])
player_clusters.append(group)

return player_clusters
return player_clusters