def choose_language_specific_prior_based_on_hidden_gems( game_feature_dict, all_languages, verbose=False): # For each language, compute the prior to be used for the inference of a Bayesian rating language_specific_prior = dict() for language in all_languages: # Construct observation structure used to compute a prior for the inference of a Bayesian rating observations = dict() for appid in game_feature_dict.keys(): try: num_positive_reviews = game_feature_dict[appid][language][ 'voted_up'] num_negative_reviews = game_feature_dict[appid][language][ 'voted_down'] except KeyError: num_positive_reviews = 0 num_negative_reviews = 0 num_votes = num_positive_reviews + num_negative_reviews if num_votes > 0: observations[appid] = dict() observations[appid]['num_votes'] = num_votes observations[appid]['score'] = num_positive_reviews / num_votes language_specific_prior[language] = choose_prior(observations) if verbose: print_prior(language_specific_prior, all_languages) return language_specific_prior
def choose_language_independent_prior_based_on_whole_steam_catalog( steam_spy_dict, all_languages, verbose=False): # Construct observation structure used to compute a prior for the inference of a Bayesian rating observations = dict() for appid in steam_spy_dict.keys(): num_positive_reviews = steam_spy_dict[appid]['positive'] num_negative_reviews = steam_spy_dict[appid]['negative'] num_votes = num_positive_reviews + num_negative_reviews if num_votes > 0: observations[appid] = dict() observations[appid]['num_votes'] = num_votes observations[appid]['score'] = num_positive_reviews / num_votes common_prior = choose_prior(observations) if verbose: print_prior(common_prior) # For each language, compute the prior to be used for the inference of a Bayesian rating language_independent_prior = dict() for language in all_languages: language_independent_prior[language] = common_prior return language_independent_prior
def main(): filename = 'data/steam_resetera_2017_goty.txt' data = load_input(filename) observations = parse_data(data) verbose = False prior = choose_prior(observations, verbose) ranking = compute_ranking(observations, prior) print_ranking(ranking, observations, prior) return True
def test_choose_prior(self): observations = { 'Blockbuster': { 'score': 0.85, 'num_votes': 1000 }, 'Average game': { 'score': 0.75, 'num_votes': 100 }, 'Hidden gem': { 'score': 0.95, 'num_votes': 10 } } bayes_prior = compute_bayesian_rating.choose_prior(observations, verbose=True) self.assertDictEqual(bayes_prior, {'score': 0.85, 'num_votes': 100})
def create_local_dictionary(data, output_filename, appid_reference_set=None, quantile_for_our_wilson_score=0.95): # Objective: compute a score for one Steam game. # # Input: - data: SteamSpy's data. # - output_filename: filename to which the local dictionary will be written to. # - appid_reference_set: a set of appID of games which are examples of "hidden gems". # By default, the appID of the game called "Contradiction". # - quantile_for_our_wilson_score: this allows to specify a different confidence for the Wilson score. # Output: none (the local dictionary is written to output_filename) if appid_reference_set is None: appid_reference_set = {appidContradiction} from compute_wilson_score import compute_wilson_score from compute_bayesian_rating import choose_prior, compute_bayesian_score # noinspection PyPep8Naming D = dict() # Construct observation structure used to compute a prior for the inference of a Bayesian rating observations = dict() for appid in data.keys(): num_positive_reviews = data[appid]["positive"] num_negative_reviews = data[appid]["negative"] num_votes = num_positive_reviews + num_negative_reviews if num_votes > 0: observations[appid] = dict() observations[appid]['score'] = num_positive_reviews / num_votes observations[appid]['num_votes'] = num_votes prior = choose_prior(observations) print(prior) for appid in data.keys(): name = data[appid]['name'] num_owners = data[appid]['owners'] try: num_owners = float(num_owners) except ValueError: num_owners = get_mid_of_interval(num_owners) try: num_players = data[appid]['players_forever'] except KeyError: num_players = None median_time = data[appid]['median_forever'] average_time = data[appid]['average_forever'] num_positive_reviews = data[appid]["positive"] num_negative_reviews = data[appid]["negative"] wilson_score = compute_wilson_score(num_positive_reviews, num_negative_reviews, quantile_for_our_wilson_score) num_votes = num_positive_reviews + num_negative_reviews if num_votes > 0: # Construct game structure used to compute Bayesian rating game = dict() game['score'] = num_positive_reviews / num_votes game['num_votes'] = num_votes bayesian_rating = compute_bayesian_score(game, prior) else: bayesian_rating = None # Make sure the output dictionary includes the game which will be chosen as a reference of a "hidden gem" if appid in appid_reference_set: if (wilson_score is None): raise AssertionError() if (bayesian_rating is None): raise AssertionError() print("Game used as a reference:\t" + name + "\t(appID=" + appid + ")") if wilson_score is None or bayesian_rating is None: print("Game with no review:\t" + name + "\t(appID=" + appid + ")") else: stats_save = [ name, wilson_score, bayesian_rating, num_owners, num_players, median_time, average_time, num_positive_reviews, num_negative_reviews ] bool_game_should_appear_in_ranking = True stats_save.append(bool_game_should_appear_in_ranking) D[appid] = stats_save # Save the dictionary to a text file with open(output_filename, 'w', encoding="utf8") as outfile: print(get_leading_comment(), file=outfile) print(D, file=outfile)