当前位置: 首页>>代码示例>>Python>>正文


Python KNN.getVotes方法代码示例

本文整理汇总了Python中KNN.getVotes方法的典型用法代码示例。如果您正苦于以下问题:Python KNN.getVotes方法的具体用法?Python KNN.getVotes怎么用?Python KNN.getVotes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在KNN的用法示例。


在下文中一共展示了KNN.getVotes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: gameRecommendations

# 需要导入模块: import KNN [as 别名]
# 或者: from KNN import getVotes [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.getVotes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。