Skip to content

Commit 8a5e59c

Browse files
committed
Simplify code calculations for clusters in SciPy
1 parent b177389 commit 8a5e59c

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

python-scipy-cluster-optimize/cluster_sms_spam.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@
2020
codebook, _ = kmeans(whitened_counts, 3)
2121
codes, _ = vq(whitened_counts, codebook)
2222

23-
possible_codes = {0, 1, 2}
24-
unique_codes, code_indices = np.unique(codes, return_index=True)
25-
ham_code = unique_codes[np.argmin(code_indices)]
26-
spam_code = unique_codes[np.argmax(code_indices)]
27-
unknown_code = list(possible_codes ^ set((ham_code, spam_code)))[0]
23+
ham_code = codes[0]
24+
spam_code = codes[-1]
25+
unknown_code = list(set(range(3)) ^ set((ham_code, spam_code)))[0]
2826

2927
print("definitely ham:", unique_counts[codes == ham_code][-1])
3028
print("definitely spam:", unique_counts[codes == spam_code][-1])

0 commit comments

Comments
 (0)