Created
August 20, 2021 04:30
-
-
Save Gclabbe/ea7ffa34e19a3f03b53f0b79fd14efbe to your computer and use it in GitHub Desktop.
Cluster breakdown in Week 3 live HW
This file contains hidden or 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
clusters = {} | |
n = len(column_values) | |
for i in range(n): | |
if column_values[i] not in clusters: | |
clusters[column_values[i]] = {'count': 0, 'purch': 0} | |
clusters[column_values[i]]['count'] += 1 | |
if y[i] == 1: | |
clusters[column_values[i]]['purch'] += 1 | |
def make_strings(c, n): | |
for i in range(len(c)): | |
count = c[i]['count'] | |
purch = c[i]['purch'] | |
c[i]['r_str'] = f"{i}: {100 * count / n :0.2f}%" | |
c[i]['p_str'] = f"{purch :5d} out of {count} -- {100 * purch / count :0.2f}%" | |
return c | |
def print_string(clusters, string_type): | |
for i in range(len(clusters)): | |
print(f"\t{clusters[i][string_type]}") | |
clusters = make_strings(clusters, n) | |
print("\nRatios\n") | |
print_string(clusters, 'r_str') | |
print("\nPurchases\n") | |
print_string(clusters, 'p_str') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment