def predict_model_cold_users(self): res = [] for user in self.rg.testColdUserSet_u.keys(): for item in self.rg.testColdUserSet_u[user].keys(): rating = self.rg.testColdUserSet_u[user][item] pred = self.predict(user, item) # pred = sigmoid(pred) # denormalize pred = denormalize(pred, self.config.min_val, self.config.max_val) pred = self.checkRatingBoundary(pred) res.append([user, item, rating, pred]) rmse = Metric.RMSE(res) mae = Metric.MAE(res) return rmse,mae
def valid_model(self): res = [] for ind, entry in enumerate(self.rg.validSet()): user, item, rating = entry # predict prediction = self.predict(user, item) # denormalize prediction = denormalize(prediction, self.config.min_val, self.config.max_val) pred = self.checkRatingBoundary(prediction) # add prediction in order to measure # self.dao.testData[ind].append(pred) res.append([user, item, rating, pred]) rmse = Metric.RMSE(res) mae = Metric.MAE(res) self.iter_rmse.append(rmse) # for plot self.iter_mae.append(mae) return rmse, mae
def predict_model(self): '''为测试集中的用户预测''' res = [] for ind, entry in enumerate(self.rg.testSet()): user, item, rating = entry rating_length = len(self.rg.trainSet_u[user]) #冷启动用户不进行预测评分 if rating_length <= self.config.coldUserRating: continue to = time.time() prediction = self.predict(user, item) ti = time.time() pre_time = to - ti if self.config.verbose: print(user, item, rating, prediction, pre_time) res.append([user, item, rating, prediction]) rmse = Metric.RMSE(res) mae = Metric.MAE(res) return rmse, mae
def predict_model(self): res = [] for ind, entry in enumerate(self.rg.testSet()): user, item, rating = entry rating_length = len(self.rg.trainSet_u[user]) # remove cold start users for test if rating_length <= self.config.coldUserRating: continue prediction = self.predict(user, item) # denormalize prediction = denormalize(prediction, self.config.min_val, self.config.max_val) pred = self.checkRatingBoundary(prediction) # add prediction in order to measure res.append([user, item, rating, pred]) rmse = Metric.RMSE(res) mae = Metric.MAE(res) self.iter_rmse.append(rmse) # for plot self.iter_mae.append(mae) return rmse, mae
def predict_model(self): '''为测试集中的用户预测''' res = [] for ind, entry in enumerate(self.rg.testSet()): user, item, rating = entry rating_length = len(self.rg.trainSet_u[user]) #冷启动用户不进行预测评分 if rating_length <= self.config.coldUserRating: continue to = time.time() prediction = self.predict(user, item) ti = time.time() pre_time = to-ti if self.config.verbose: print(user, item, rating, prediction, pre_time) res.append([user, item, rating, prediction]) ##################################################333 #0304更新推荐结果 userList = list(set([i[0] for i in res])) preDict = {} for i in res: if i[0] not in preDict.keys(): preDict[i[0]] = [] preDict[i[0]].append(i[1:]) finalRes = {} for i in userList: finalRes[i] = [] dic = {} for j in preDict[i]: dic[j[0]] = preDict[i][-1] #z = sorted(dic)[:10] list1= sorted(dic.items(),key=lambda x:x[1]) z = [i[0] for i in list1][:5] finalRes[i] = z ####################################################33 rmse = Metric.RMSE(res) mae = Metric.MAE(res) return rmse, mae, finalRes