def fit(self, topK=50, shrink=100, similarity='cosine', normalize=True, feature_weighting="none", **similarity_args): self.topK = topK self.shrink = shrink if feature_weighting not in self.FEATURE_WEIGHTING_VALUES: raise ValueError( "Value for 'feature_weighting' not recognized. Acceptable values are {}, provided was '{}'" .format(self.FEATURE_WEIGHTING_VALUES, feature_weighting)) if feature_weighting == "BM25": self.URM_train = self.URM_train.astype(np.float32) self.URM_train = okapi_BM_25(self.URM_train.T).T self.URM_train = check_matrix(self.URM_train, 'csr') elif feature_weighting == "TF-IDF": self.URM_train = self.URM_train.astype(np.float32) self.URM_train = TF_IDF(self.URM_train.T).T self.URM_train = check_matrix(self.URM_train, 'csr') similarity = Compute_Similarity(self.URM_train.T, shrink=shrink, topK=topK, normalize=normalize, similarity=similarity, **similarity_args) self.W_sparse = similarity.compute_similarity() self.W_sparse = check_matrix(self.W_sparse, format='csr')
def __init__(self, urm_train, icm, urm_per_region_list, urm_per_age_list, weights, add_pure_svd=False, add_slim_bpr=False): self.urm_train = urm_train self.urm_per_region_list = urm_per_region_list self.urm_per_age_list = urm_per_age_list self.icm = icm self.add_pure_svd = add_pure_svd self.add_slim_bpr = add_slim_bpr self.weights = weights self.icfknn_list = [] self.ucfknn_list = [] self.icbfknn_list = [] self.icm_bm25 = self.icm.copy().astype(np.float32) self.icm_bm25 = okapi_BM_25(self.icm_bm25) self.icm_bm25 = self.icm_bm25.tocsr() self.ratings = None self.extractor = Extractor() # Creation of the list of algortms that have to be used if self.urm_per_region_list is not None: for urm in self.urm_per_region_list: sps.csr_matrix(urm) self.icfknn_list.append(ItemCFKNNRecommender(urm.copy())) self.ucfknn_list.append(UserCFKNNRecommender(urm.copy())) self.icbfknn_list.append( ItemCBFKNNRecommender(urm.copy(), self.icm_bm25.copy())) if self.urm_per_age_list is not None: for urm in self.urm_per_age_list: sps.csr_matrix(urm) self.icfknn_list.append(ItemCFKNNRecommender(urm.copy())) self.ucfknn_list.append(UserCFKNNRecommender(urm.copy())) self.icbfknn_list.append( ItemCBFKNNRecommender(urm.copy(), self.icm_bm25.copy())) # self.icfknn_list.append(ItemCFKNNRecommender(self.urm_train.copy())) # self.ucfknn_list.append(UserCFKNNRecommender(self.urm_train.copy())) # self.icbfknn_list.append(ItemCBFKNNRecommender(self.urm_train.copy(), self.icm_bm25.copy())) if self.add_pure_svd: self.pure_SVD = PureSVDRecommender(self.urm_train.copy()) if self.add_slim_bpr: self.slim_bpr = SLIM_BPR_Cython(self.urm_train.copy())
def __init__(self, urm, icm, p_icfknn, p_ucfknn, p_cbfknn, p_slimbpr, p_puresvd, p_als, p_cfw, weights): # Parameter saving self.p_icfknn = p_icfknn self.p_ucfknn = p_ucfknn self.p_cbfknn = p_cbfknn self.p_slimbpr = p_slimbpr self.p_puresvd = p_puresvd self.p_als = p_als self.p_cfw = p_cfw self.weights = weights # Getting matrices self.urm = urm self.icm = icm self.icm_bm25 = self.icm.copy().astype(np.float32) self.icm_bm25 = okapi_BM_25(self.icm_bm25) self.icm_bm25 = self.icm_bm25.tocsr() # Creating recommenders if self.p_icfknn is not None: self.recommender_itemCFKNN = ItemCFKNNRecommender(self.urm.copy()) if self.p_ucfknn is not None: self.recommender_userCFKNN = UserCFKNNRecommender(self.urm.copy()) if self.p_cbfknn is not None: self.recommender_itemCBFKNN = ItemCBFKNNRecommender(self.urm.copy(), self.icm_bm25) if self.p_slimbpr is not None: self.recommender_slim_bpr = SLIM_BPR_Cython(self.urm.copy()) if self.p_puresvd is not None: self.recommender_puresvd = PureSVDRecommender(self.urm.copy()) if self.p_als is not None: self.recommender_als = AlternatingLeastSquare(self.urm.copy()) _, n_items = urm.shape self.hybrid_ratings = np.zeros(n_items)