Created
September 15, 2015 16:22
-
-
Save toinetoine/ecb4dc0de141291b891d to your computer and use it in GitHub Desktop.
Creates user data for kmeans.py (https://gist.github.com/Antoine-D/eb1f76efdea2d319e30d)
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
import random | |
import json | |
data = {} | |
data['dataset'] = list() | |
# add each user to the dataset | |
for user_i in range(200): | |
new_user = {} | |
new_user["id"] = str(user_i) | |
new_user["data"] = list() | |
liked_sites = [random.randint(1, 10) for i in range(random.randint(1, 5))] | |
for site_i in range(len(liked_sites)): | |
new_user["data"].append(str(liked_sites[site_i]) + ".com") | |
data['dataset'].append(new_user) | |
json_data = json.dumps(data) | |
data_file = open("data.json", "w") | |
data_file.write(json_data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment