博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
欧式算法之用户推荐的协同过滤推荐(User-Based)
阅读量:2241 次
发布时间:2019-05-09

本文共 3142 字,大约阅读时间需要 10 分钟。

User-Based 和 Item-Based 区别
http://www.gooseeker.com/cn/node/knowledgebase/colfiltering
https://en.wikipedia.org/wiki/Collaborative_filtering
http://www.gooseeker.com/cn/node/knowledgebase/colfiltering
http://my.oschina.net/BreathL/blog/62519?p=2#comments
http://download.csdn.net/download/icgreen/7484081
欧式算法之用户推荐的协同过滤推荐java版
http://www.cnblogs.com/kunpengit/archive/2013/03/04/2942684.html
-----------------------------------------------------------
package com.wk.xietongguolue;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
public class Data {
static String[] films = { "十面埋伏", "一路向北", "那些年我们一起追过的女孩", "CCAV", "非诚勿扰" };
static String[] users = { "aaa", "bbb", "ccc", "ddd", "葛二蛋" };
static Map score = new HashMap();
static Set userSet = new HashSet();
static Set filmSet = new HashSet();
static {
for (String str : Data.users) {
userSet.add(str);
}
for (String str : Data.films) {
filmSet.add(str);
}
score = getScore();
}
public static void outNearbyUserList(String user) {
Map scores = new HashMap();
for (String tempUser : users) {
if (tempUser.equalsIgnoreCase(user)) {
continue;
}
double score = getOSScore(user, tempUser);
scores.put(tempUser, score);
}
System.out.println(scores.toString());
}
private static Double getOSScore(String user1, String user2) {
HashMap user1Score = (HashMap) score.get(user1);
HashMap user2Score = (HashMap) score.get(user2);
double totalscore = 0.0;
Iterator it = user1Score.keySet().iterator();
while (it.hasNext()) {
String film = (String) it.next();
int a1 = (Integer) user1Score.get(film);
int a2 = (Integer) user1Score.get(film);
int b1 = (Integer) user2Score.get(film);
int b2 = (Integer) user2Score.get(film);
int a = a1 * a2 - b1 * b2;
//System.out.println(Math.abs(a));
totalscore += Math.sqrt(Math.abs(a));
}
return totalscore;
}
private static Map getScore() {
Map score = new HashMap();
// aaa
HashMap tempScore = new HashMap();
tempScore.put(films[0], 9);
tempScore.put(films[1], 1);
tempScore.put(films[2], 9);
tempScore.put(films[3], 7);
tempScore.put(films[4], 1);
score.put(Data.users[0], tempScore);
// bbb
tempScore = new HashMap();
tempScore.put(films[0], 2);
tempScore.put(films[1], 9);
tempScore.put(films[2], 2);
tempScore.put(films[3], 2);
tempScore.put(films[4], 2);
score.put(Data.users[1], tempScore);
// ccc
tempScore = new HashMap();
tempScore.put(films[0], 9);
tempScore.put(films[1], 9);
tempScore.put(films[2], 9);
tempScore.put(films[3], 3);
tempScore.put(films[4], 3);
score.put(Data.users[2], tempScore);
// ddd
tempScore = new HashMap();
tempScore.put(films[0], 4);
tempScore.put(films[1], 9);
tempScore.put(films[2], 9);
tempScore.put(films[3], 4);
tempScore.put(films[4], 4);
score.put(Data.users[3], tempScore);
// 葛二蛋
tempScore = new HashMap();
tempScore.put(films[0], 5);
tempScore.put(films[1], 5);
tempScore.put(films[2], 5);
tempScore.put(films[3], 5);
tempScore.put(films[4], 5);
score.put(Data.users[4], tempScore);
return score;
}
public static void main(String[] args) {
//
System.out.println(Data.users[0] + " 与其他人的相似度(分值越低越相似):");
Data.outNearbyUserList(Data.users[0]);
}
}
你可能感兴趣的文章
Java的三种代理模式
查看>>
java静态代理与动态代理简单分析
查看>>
JTS Geometry关系判断和分析
查看>>
阿里巴巴十年Java架构师分享,会了这个知识点的人都去BAT了
查看>>
Intellij IDEA 使用技巧一
查看>>
IDEA 护眼色设置 背景行颜色取消等设置
查看>>
idea如何显示git远程与本地的更改对比?
查看>>
Git 分支 - 分支的新建与合并
查看>>
git创建与合并分支
查看>>
23种设计模式介绍以及在Java中的实现
查看>>
如何把本地项目上传到Github
查看>>
Git的使用--如何将本地项目上传到Github
查看>>
zookeeper客户端命令行查看dubbo服务的生产者和消费者
查看>>
intellij idea 相关搜索快捷键
查看>>
oracle查看数据库连接池中最大连接数和当前用户连接数等信息
查看>>
oracle中创建同义词(synonyms)表
查看>>
建立DB-LINK和建立视图
查看>>
普通视图和物化视图的区别(转)
查看>>
物化视图加DBLINK实现数据的同步_20170216
查看>>
Redis在京东到家的订单中的使用
查看>>