Пример #1
0
def main():
    args = get_arguments()

    # Data loading
    data_reader = read_split_load_data(3, args.allow_cold_users, args.seed)
    URM_train, URM_test = data_reader.get_holdout_split()

    ICM_categorical = data_reader.get_ICM_from_name("ICM_sub_class")
    ICM_numerical, _ = get_ICM_numerical(data_reader.dataReader_object)
    ICM_all, _ = get_ICM_train_new(data_reader)

    similarity_type_list = None
    if args.recommender_name == "item_cbf_numerical":
        ICM = ICM_numerical
        ICM_name = "ICM_numerical"
    elif args.recommender_name == "item_cbf_categorical":
        ICM = ICM_categorical
        ICM_name = "ICM_categorical"
    else:
        ICM = ICM_all
        ICM_name = "ICM_all"

    # Setting evaluator
    ignore_users = get_ignore_users(
        URM_train,
        data_reader.get_original_user_id_to_index_mapper(),
        lower_threshold=args.lower_threshold,
        upper_threshold=args.upper_threshold,
        ignore_non_target_users=args.exclude_non_target)
    evaluator = EvaluatorHoldout(URM_test,
                                 cutoff_list=[10],
                                 ignore_users=ignore_users)

    # HP tuning
    print("Start tuning...")
    version_path = "../../report/hp_tuning/{}/".format(args.recommender_name)
    now = datetime.now().strftime('%b%d_%H-%M-%S')
    now = now + "_k_out_value_3/"
    version_path = version_path + "/" + now

    run_parameter_search_item_content(
        URM_train=URM_train,
        ICM_object=ICM,
        ICM_name=ICM_name,
        recommender_class=RECOMMENDER_CLASS_DICT[args.recommender_name],
        evaluator_validation=evaluator,
        metric_to_optimize="MAP",
        output_folder_path=version_path,
        similarity_type_list=similarity_type_list,
        parallelizeKNN=True,
        n_cases=args.n_cases,
        n_random_starts=args.n_random_starts)
    print("...tuning ended")
Пример #2
0
    def setUp(self) -> None:
        self.k_out = 3
        self.cutoff = 5
        self.path = "../../data/"

        self.data_reader = read_split_load_data(self.k_out,
                                                allow_cold_users=False,
                                                seed=1000)

        self.URM_train, self.URM_test = self.data_reader.get_holdout_split()
        self.ICM_all, _ = get_ICM_train_new(self.data_reader)
        self.UCM_all = get_UCM_train(self.data_reader)

        self.main_rec = new_best_models.ItemCBF_CF.get_model(
            URM_train=self.URM_train, ICM_train=self.ICM_all)
    return model


if __name__ == '__main__':
    set_env_variables()
    seeds = get_seed_lists(N_FOLDS, get_split_seed())

    # --------- DATA LOADING SECTION --------- #
    URM_train_list = []
    ICM_train_list = []
    UCM_train_list = []
    evaluator_list = []
    model_list = []
    for fold_idx in range(N_FOLDS):
        # Read and split data
        data_reader = read_split_load_data(K_OUT, ALLOW_COLD_USERS,
                                           seeds[fold_idx])
        URM_train, URM_test = data_reader.get_holdout_split()
        ICM_train, item_feature2range = get_ICM_train_new(data_reader)
        UCM_train, user_feature2range = get_UCM_train_new(data_reader)

        # Ignore users and setting evaluator
        ignore_users = get_ignore_users(
            URM_train,
            data_reader.get_original_user_id_to_index_mapper(),
            LOWER_THRESHOLD,
            UPPER_THRESHOLD,
            ignore_non_target_users=IGNORE_NON_TARGET_USERS)

        # Ignore users by age
        # UCM_age = data_reader.get_UCM_from_name("UCM_age")
        # age_feature_to_id_mapper = data_reader.dataReader_object.get_UCM_feature_to_index_mapper_from_name("UCM_age")
    'epochs': 50,
    'confidence_scaling': 'linear',
    'alpha': 0.34370928029631664
}
recommender_class = ImplicitALSRecommender
model_name = "IALS_LT23"

if __name__ == '__main__':
    # Set seed in order to have same splitting of data
    seed_list = get_seed_list()
    num_folds = len(seed_list)

    URM_train_list = []
    evaluator_list = []
    for i in range(num_folds):
        data_reader = read_split_load_data(K_OUT, ALLOW_COLD_USERS,
                                           seed_list[i])
        URM_train, URM_test = data_reader.get_holdout_split()

        ignore_users = get_ignore_users(
            URM_train,
            data_reader.get_original_user_id_to_index_mapper(),
            lower_threshold=LOWER_THRESHOLD,
            upper_threshold=UPPER_THRESHOLD,
            ignore_non_target_users=IGNORE_NON_TARGET_USERS)
        evaluator = EvaluatorHoldout(URM_test,
                                     cutoff_list=[CUTOFF],
                                     ignore_users=ignore_users)

        URM_train_list.append(URM_train)
        evaluator_list.append(evaluator)
Пример #5
0
def main():
    set_env_variables()
    args = get_arguments()
    seeds = get_seed_lists(args.n_folds, get_split_seed())

    # --------- DATA LOADING SECTION --------- #
    URM_train_list = []
    ICM_train_list = []
    UCM_train_list = []
    evaluator_list = []
    for fold_idx in range(args.n_folds):
        # Read and split data
        data_reader = read_split_load_data(K_OUT, args.allow_cold_users, seeds[fold_idx])
        URM_train, URM_test = data_reader.get_holdout_split()
        ICM_train, item_feature2range = get_ICM_train_new(data_reader)
        UCM_train, user_feature2range = get_UCM_train_new(data_reader)

        # Ignore users and setting evaluator
        ignore_users = get_ignore_users(URM_train, data_reader.get_original_user_id_to_index_mapper(),
                                        args.lower_threshold, args.upper_threshold,
                                        ignore_non_target_users=args.exclude_non_target)

        # Ignore users by age
        # UCM_age = data_reader.get_UCM_from_name("UCM_age")
        # age_feature_to_id_mapper = data_reader.dataReader_object.get_UCM_feature_to_index_mapper_from_name("UCM_age")
        # age_demographic = get_user_demographic(UCM_age, age_feature_to_id_mapper, binned=True)
        # ignore_users = np.unique(np.concatenate((ignore_users, get_ignore_users_age(age_demographic, AGE_TO_KEEP))))

        URM_train_list.append(URM_train)
        ICM_train_list.append(ICM_train)
        UCM_train_list.append(UCM_train)

        evaluator = EvaluatorHoldout(URM_test, cutoff_list=[CUTOFF], ignore_users=np.unique(ignore_users))
        evaluator_list.append(evaluator)

    # --------- HYPER PARAMETERS TUNING SECTION --------- #
    print("Start tuning...")

    hp_tuning_path = "../../../report/hp_tuning/" + args.recommender_name + "/"
    date_string = datetime.now().strftime('%b%d_%H-%M-%S_k1_lt_{}/'.format(args.lower_threshold))
    output_folder_path = hp_tuning_path + date_string

    if args.recommender_name in COLLABORATIVE_RECOMMENDER_CLASS_DICT.keys():
        run_cv_parameter_search(URM_train_list=URM_train_list,
                                recommender_class=RECOMMENDER_CLASS_DICT[args.recommender_name],
                                evaluator_validation_list=evaluator_list,
                                metric_to_optimize="MAP", output_folder_path=output_folder_path,
                                parallelize_search=args.parallelize, n_jobs=args.n_jobs,
                                n_cases=args.n_cases, n_random_starts=args.n_random_starts)
    elif args.recommender_name in CONTENT_RECOMMENDER_CLASS_DICT.keys():
        run_cv_parameter_search(URM_train_list=URM_train_list, ICM_train_list=ICM_train_list, ICM_name="ICM_all",
                                recommender_class=RECOMMENDER_CLASS_DICT[args.recommender_name],
                                evaluator_validation_list=evaluator_list,
                                metric_to_optimize="MAP", output_folder_path=output_folder_path,
                                parallelize_search=args.parallelize, n_jobs=args.n_jobs,
                                n_cases=args.n_cases, n_random_starts=args.n_random_starts)
    elif args.recommender_name in DEMOGRAPHIC_RECOMMENDER_CLASS_DICT.keys():
        run_cv_parameter_search(URM_train_list=URM_train_list, UCM_train_list=UCM_train_list, UCM_name="UCM_all",
                                recommender_class=RECOMMENDER_CLASS_DICT[args.recommender_name],
                                evaluator_validation_list=evaluator_list,
                                metric_to_optimize="MAP", output_folder_path=output_folder_path,
                                parallelize_search=args.parallelize, n_jobs=args.n_jobs,
                                n_cases=args.n_cases, n_random_starts=args.n_random_starts)
    elif args.recommender_name in SIDE_INFO_CLASS_DICT:
        temp_list = []
        for i, URM in enumerate(URM_train_list):
            temp = sps.vstack([URM, ICM_train_list[i].T], format="csr")
            #temp = TF_IDF(temp).tocsr()
            temp_list.append(temp)

        run_cv_parameter_search(URM_train_list=temp_list,
                                recommender_class=RECOMMENDER_CLASS_DICT[args.recommender_name],
                                evaluator_validation_list=evaluator_list, metric_to_optimize="MAP",
                                output_folder_path=output_folder_path, parallelize_search=args.parallelize,
                                n_jobs=args.n_jobs, n_cases=args.n_cases, n_random_starts=args.n_random_starts)

    print("...tuning ended")
Пример #6
0
    all_models['RP3BETA_SIDE'] = new_best_models.RP3BetaSideInfo.get_model(
        URM_train, ICM_all)
    all_models['ITEM_CBF_FW'] = new_best_models.ItemCBF_all_FW.get_model(
        URM_train, ICM_all)
    all_models['PURE_SVD_SIDE'] = new_best_models.PureSVDSideInfo.get_model(
        URM_train, ICM_all)
    all_models['IALS_SIDE'] = new_best_models.IALSSideInfo.get_model(
        URM_train, ICM_all)
    #all_models['SSLIM_BPR'] = new_best_models.SSLIM_BPR.get_model(URM_train, ICM_all)

    return all_models


if __name__ == '__main__':
    # Data loading
    data_reader = read_split_load_data(K_OUT, ALLOW_COLD_USERS,
                                       get_split_seed())
    URM_train, URM_test = data_reader.get_holdout_split()

    # Build ICMs
    ICM_all, _ = get_ICM_train_new(data_reader)

    # Build UCMs
    UCM_all = get_UCM_train(data_reader)

    main_recommender = new_best_models.FusionMergeItem_CBF_CF.get_model(
        URM_train, ICM_all)
    model = HybridRerankingRecommender(URM_train, main_recommender)

    all_models = _get_all_models(URM_train=URM_train,
                                 UCM_all=UCM_all,
                                 ICM_all=ICM_all)