本文整理匯總了Python中KNN.findClosest方法的典型用法代碼示例。如果您正苦於以下問題:Python KNN.findClosest方法的具體用法?Python KNN.findClosest怎麽用?Python KNN.findClosest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類KNN
的用法示例。
在下文中一共展示了KNN.findClosest方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: gameRecommendations
# 需要導入模塊: import KNN [as 別名]
# 或者: from KNN import findClosest [as 別名]
def gameRecommendations(u_name):
# Get API key
all_api_keys1 = get_keys("./num1.txt")
all_api_keys2 = get_keys("./num2.txt")
api_key = str(all_api_keys1[0]) + str(all_api_keys2[0])
if len(api_key) != 32:
print("Uh-oh, don't forget to enter your API key!")
return
# Set up a requests session to allow retries when a request fails
session = reqGet.Session()
session.mount("http://", reqGet.adapters.HTTPAdapter(max_retries=10))
games_response_json = getUserGames(u_name, api_key)
all_games = loadGameIDs("./data/id_header.csv")
# Get all of the game names and IDs from steam and save them in a dictionary for easy usage
game_list = json.loads(session.get(url="http://api.steampowered.com/ISteamApps/GetAppList/v2").text)['applist']['apps']
game_dict = {}
for game in game_list:
game_dict[game['appid']] = game
user_game_array = ["0"] * len(all_games)
if not games_response_json:
return
for game in games_response_json:
if game['appid'] in all_games:
game_index = all_games.index(game['appid'])
user_game_array[game_index] = "1"
all_games = [game_dict[x]['name'] for x in all_games]
game_bit_string = int(''.join(user_game_array), 2)
dataset = KNN.loadDataset("./data/games_by_username_all.csv")
closest = KNN.findClosest(dataset, game_bit_string, 100)
return KNN.getTopGames(KNN.getVotes(all_games, closest, game_bit_string), 5)