def objective(params):
    print('###########################################')
    params["topK"] = int(params["topK"])
    print("Current parameters:")
    print(params)
    loss = - RunRecommender.evaluate_on_validation_set(ItemCollaborativeFilter, params, Kfold=N_K_FOLD, parallel_fit=False, parallelize_evaluation=True)
    return loss
def objective(params):
    params["topK"] = int(params["topK"])
    print("############ Current parameters ############")
    print(params)
    loss = -RunRecommender.evaluate_on_validation_set(
        RP3betaRecommender,
        params,
        Kfold=N_KFOLD,
        parallelize_evaluation=True,
        user_group="warm")
    return loss
Exemple #3
0
def objective(params):
    print('###########################################')
    params["n_factors"] = int(params["n_factors"])
    print("Current parameters:")
    print(params)
    loss = -RunRecommender.evaluate_on_validation_set(
        AlternatingLeastSquare,
        params,
        Kfold=N_K_FOLD,
        parallel_fit=False,
        parallelize_evaluation=True,
        user_group="warm")
    return loss
def objective(params):
    params["topK"] = int(params["topK"])
    params["batch_size"] = int(params["batch_size"])
    params["random_seed"] = 1234
    params["epochs"] = 30
    print("############ Current parameters ############")
    print(params)
    loss = -RunRecommender.evaluate_on_validation_set(
        SLIM_BPR_Cython,
        params,
        Kfold=N_KFOLD,
        parallelize_evaluation=False,
        user_group="warm")
    return loss
Exemple #5
0
def objective(params):
    print('###########################################')
    print(params)
    params["topK"] = int(params["topK"])
    # if type(params["similarity"]) == tuple:
    #     params["asymmetric_alpha"] = params["similarity"][1]
    #     params["similarity"] = params["similarity"][0]
    loss = -RunRecommender.evaluate_on_validation_set(
        HybridUserCBFRegionalTopPop,
        params,
        Kfold=10,
        user_group="cold",
        parallel_fit=False,
        parallelize_evaluation=True)
    return loss
def objective(params):
    print('###########################################')
    print(params)
    loss = - RunRecommender.evaluate_on_validation_set(UserCBF, params, Kfold=N_FOLD, parallel_fit=False, parallelize_evaluation=True, user_group="warm")
    return loss
def objective(params):
    print('###########################################')
    print(params)
    loss = - RunRecommender.evaluate_on_validation_set(UserCBF, params, Kfold=4, user_group="cold")
    return loss
Exemple #8
0
def objective(params):
    print('###########################################')
    print(params)
    loss = -RunRecommender.evaluate_on_validation_set(
        ItemCBF, params, Kfold=4, parallel_fit=True)
    return loss
            rows.extend(rows_)
            cols.extend(cols_)

        # generate the sparse weight matrix
        print("Now generating W matrix...")
        self.W_sparse = sps.csr_matrix((values, (rows, cols)),
                                       shape=(n_items, n_items),
                                       dtype=np.float32)
        print("Done!")


if __name__ == '__main__':

    from utils.helper import Helper
    helper = Helper()

    slim = MultiThreadSSLIM_ElasticNet

    best = {
        'alpha': 0.0024081648139725204,
        'l1_ratio': 0.0007553368138338653,
        'positive_only': False,
        'side_alpha': 3.86358712510434,
        'topK': 65,
        'random_state': 1234
    }

    map_10 = RunRecommender.evaluate_on_validation_set(slim, best)

    print(map_10)
            scores = self.filter_seen(user_id, scores)
        recommended_items = np.argsort(scores)
        recommended_items = np.flip(recommended_items, axis=0)
        return recommended_items[:at]

    def filter_seen(self, user_id, scores):
        start_pos = self.URM_train.indptr[user_id]
        end_pos = self.URM_train.indptr[user_id + 1]

        user_profile = self.URM_train.indices[start_pos:end_pos]

        scores[user_profile] = -np.inf

        return scores


if __name__ == "__main__":

    cbf_recommender = ItemCBF

    params = {
        'normalize': True,
        'shrink': 18,
        'similarity': 'asymmetric',
        'topK': 15
    }

    RunRecommender.evaluate_on_validation_set(cbf_recommender, params)
    RunRecommender.evaluate_on_validation_set(cbf_recommender, params)
    # RunRecommender.run(cbf_recommender)
Exemple #11
0
            self.filter_seen(user_id, scores)
        recommended_items = np.argsort(scores)
        recommended_items = np.flip(recommended_items, axis=0)
        return recommended_items[0: at]

    def filter_seen(self, user_id, scores):
        """Remove items that are in the user profile from recommendations

        :param user_id: array of user ids for which to compute recommendations
        :param scores: array containing the scores for each object"""

        start_pos = self.URM_train.indptr[user_id]
        end_pos = self.URM_train.indptr[user_id + 1]

        user_profile = self.URM_train.indices[start_pos:end_pos]

        scores[user_profile] = -np.inf

        return scores
if __name__ == "__main__":
    # Train and test data are now loaded by the helper

    hybrid_ucficf = AlternatingLeastSquare

    als_parameters = {'n_factors': 480, 'regularization': 0.003946413694592164, "iterations": 30}



    # Evaluation is performed by RunRecommender
    RunRecommender.evaluate_on_validation_set(hybrid_ucficf, als_parameters)
Exemple #12
0
    def filter_seen(self, user_id, scores):
        """Remove items that are in the user profile from recommendations

        :param user_id: array of user ids for which to compute recommendations
        :param scores: array containing the scores for each object"""

        start_pos = self.URM_train.indptr[user_id]
        end_pos = self.URM_train.indptr[user_id + 1]

        user_profile = self.URM_train.indices[start_pos:end_pos]

        scores[user_profile] = -np.inf

        return scores


if __name__ == "__main__":
    # Train and test data are now loaded by the helper

    weights = {
        'SLIM_weight': 0.6719606935709935,
        'item_cf_weight': 0.08340610330630326,
        'user_cf_weight': 0.006456181309865703
    }
    hybrid_ucficf = HybridElasticNetICFUCF

    # Evaluation is performed by RunRecommender
    RunRecommender.evaluate_on_validation_set(hybrid_ucficf, weights)

    # RunRecommender.run(hybrid_ucficf, weights)
def objective(params):
    print("Current parameters:")
    print(params)
    loss = -RunRecommender.evaluate_on_validation_set(P3alphaRecommender,
                                                      params)
    return loss
Exemple #14
0
def objective(params):
    print("Current parameters:")
    print(params)
    loss = -RunRecommender.evaluate_on_validation_set(
        MultiThreadSLIM_ElasticNet, params, Kfold=4)
    return loss
Exemple #15
0
def objective(params):
    print('###########################################')
    print(params)
    loss = - RunRecommender.evaluate_on_validation_set(ItemCBF, params)
    return loss
Exemple #16
0
from AssetCBF import AssetCBF
from utils.run import RunRecommender
from ItemBasedCBF import ItemCBF
import numpy as np


### Step 1 : defining the objective function
def objective(params):
    print('###########################################')
    print(params)
    loss = - RunRecommender.evaluate_on_validation_set(ItemCBF, params)
    return loss

price_cbf_space = {
    "topK": hp.hp.choice('topK', np.arange(0, 500, 10)),
    "shrink": hp.hp.choice('shrink', np.arange(0, 100, 2))}


if __name__ == '__main__':
    ### step 3 : storing the results of every iteration
    bayes_trials = Trials()
    MAX_EVALS = 100
    opt = {'topK': 200, 'shrink': 5}
    RunRecommender.evaluate_on_validation_set(ItemCBF, opt)
    # Optimize
    best = fmin(fn=objective, space=price_cbf_space, algo=hp.tpe.suggest,
                max_evals=MAX_EVALS, trials=bayes_trials, verbose=True)

    ### best will the return the the best hyperparameter set

    print(best)