def _evaluate(self, eval_dataset, num_recommendations, metrics, batch_size=1, num_users=None): if self.model is None: raise Exception('Model not initialized') self.model.eval() recommender = InferenceRecommender(self, num_recommendations) evaluator = RecommenderEvaluator(recommender, metrics) results = evaluator.evaluate(eval_dataset, batch_size=batch_size, num_users=num_users) return results
'user_col': 'uid', 'item_col': 'sid', 'inter_col': 'watched', } method = 'inference' model_file = model_dir + 'bce_ns_d_0.0_n_0.5_200_epoch_100.model' index_file = model_dir + 'bce_ns_d_0.0_n_0.5_200_epoch_100.model.index' num_recommendations = 100 if method == 'inference': model = DynamicAutoencoder() recoder = Recoder(model) recoder.init_from_model_file(model_file) recommender = InferenceRecommender(recoder, num_recommendations) elif method == 'similarity': embeddings_index = AnnoyEmbeddingsIndex() embeddings_index.load(index_file=index_file) cache_embeddings_index = MemCacheEmbeddingsIndex(embeddings_index) recommender = SimilarityRecommender(cache_embeddings_index, num_recommendations, scale=1, n=50) train_df = pd.read_csv(data_dir + 'train.csv') val_te_df = pd.read_csv(data_dir + 'test_te.csv') val_tr_df = pd.read_csv(data_dir + 'test_tr.csv') train_matrix, item_id_map, _ = dataframe_to_csr_matrix(train_df, **common_params)