當前位置: 首頁>>代碼示例>>Python>>正文


Python KNN.getTopGames方法代碼示例

本文整理匯總了Python中KNN.getTopGames方法的典型用法代碼示例。如果您正苦於以下問題:Python KNN.getTopGames方法的具體用法?Python KNN.getTopGames怎麽用?Python KNN.getTopGames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在KNN的用法示例。


在下文中一共展示了KNN.getTopGames方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: gameRecommendations

# 需要導入模塊: import KNN [as 別名]
# 或者: from KNN import getTopGames [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)
開發者ID:aaronkarp123,項目名稱:steam-game-recommender,代碼行數:42,代碼來源:runKnn.py


注:本文中的KNN.getTopGames方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。