Compare commits
10 Commits
988a91e995
...
cd21b384d3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd21b384d3 | ||
|
|
514346075d | ||
|
|
923a0ea5ae | ||
|
|
87f96e06f7 | ||
|
|
e648b7823f | ||
|
|
43ee53bc69 | ||
|
|
43c55193c9 | ||
|
|
b4bd7e305a | ||
|
|
2ab736a59e | ||
|
|
7ccd3f9daa |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -23,4 +23,4 @@
|
|||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
|
|
||||||
.idea
|
.idea/
|
||||||
|
|||||||
8
.idea/.gitignore
generated
vendored
8
.idea/.gitignore
generated
vendored
@@ -1,8 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
||||||
30
README.md
30
README.md
@@ -1,10 +1,21 @@
|
|||||||
# JAVA推荐系统-基于用户和物品协同过滤的电影推荐
|
# JAVA推荐系统-基于用户和物品协同过滤的电影推荐
|
||||||
|
|
||||||
|
|
||||||
#### 系统原理
|
#### 系统原理
|
||||||
该系统使用java编写的基于用户的协同过滤算法(UserCF)和基于物品(此应用中指电影)的协同过滤(ItemtemCF)
|
该系统使用java编写的基于用户的协同过滤算法(UserCF)和基于物品(此应用中指电影)的协同过滤(ItemtemCF)
|
||||||
利用统计学的相关系数经常皮尔森(pearson)相关系数计算相关系数来实现千人千面的推荐系统。
|
利用统计学的相关系数经常皮尔森(pearson)相关系数计算相关系数来实现千人千面的推荐系统。
|
||||||
|
|
||||||
|
|
||||||
|
## 我的博客
|
||||||
|
|
||||||
|
1. **JAVA OPC UA专栏**:[https://blog.csdn.net/weixin_40986713/category_12356608.html](https://blog.csdn.net/weixin_40986713/category_12356608.html)
|
||||||
|
2. **AI绘画 | Stable diffusion**:[https://blog.csdn.net/weixin_40986713/category_12481790.html](https://blog.csdn.net/weixin_40986713/category_12481790.html)
|
||||||
|
3. **java高级技术专栏**:[https://blog.csdn.net/weixin_40986713/category_10796066.html](https://blog.csdn.net/weixin_40986713/category_10796066.html)
|
||||||
|
4. **java Selenium自动化爬虫**:[https://blog.csdn.net/weixin_40986713/category_12165790.html](https://blog.csdn.net/weixin_40986713/category_12165790.html)
|
||||||
|
5. **java 推荐算法专栏**:[https://blog.csdn.net/weixin_40986713/category_12268014.html](https://blog.csdn.net/weixin_40986713/category_12268014.html)
|
||||||
|
6. **Java视频图像处理专栏**:[https://blog.csdn.net/weixin_40986713/category_11109931.html](https://blog.csdn.net/weixin_40986713/category_11109931.html)
|
||||||
|
|
||||||
|
|
||||||
#### 协同过滤算法
|
#### 协同过滤算法
|
||||||
协同过滤推荐算法是诞生最早,并且较为著名的推荐算法。主要的功能是预测和推荐。协同过滤(Collaborative Filtering,简写CF)是推荐系统最重要得思想之一,其思想是根据用户之前得喜好以及其他兴趣相近得用户得选择来给用户推荐物品(基于对用户历史行为数据的挖掘发现用户的喜好偏向,并预测用户可能喜好的产品进行推荐),一般仅仅基于用户的行为数据(评价,购买,下载等),而不依赖于物品的任何附加信息(物品自身特征)或者用户的任何附加信息(年龄,性别等)。其思想总的来说就是:人以类聚,物以群分。
|
协同过滤推荐算法是诞生最早,并且较为著名的推荐算法。主要的功能是预测和推荐。协同过滤(Collaborative Filtering,简写CF)是推荐系统最重要得思想之一,其思想是根据用户之前得喜好以及其他兴趣相近得用户得选择来给用户推荐物品(基于对用户历史行为数据的挖掘发现用户的喜好偏向,并预测用户可能喜好的产品进行推荐),一般仅仅基于用户的行为数据(评价,购买,下载等),而不依赖于物品的任何附加信息(物品自身特征)或者用户的任何附加信息(年龄,性别等)。其思想总的来说就是:人以类聚,物以群分。
|
||||||
目前应用比较广泛的协同过滤算法是基于邻域的方法,而这种方法主要有两种算法:
|
目前应用比较广泛的协同过滤算法是基于邻域的方法,而这种方法主要有两种算法:
|
||||||
@@ -162,17 +173,16 @@ Spring boot单项目
|
|||||||
|
|
||||||
3.项目中用到的文件数据集ml-100k 在 src / main / resources目录下
|
3.项目中用到的文件数据集ml-100k 在 src / main / resources目录下
|
||||||
|
|
||||||
#### 技术交流&问题反馈
|
|
||||||
|
|
||||||
刚刚整理的代码还有很多不足之处,如有问题请联系我
|
|
||||||
|
|
||||||
联系QQ:1334512682
|
|
||||||
微信号:vxhqqh
|
|
||||||
|
|
||||||
#### 我的博客
|
|
||||||
|
|
||||||
[洛阳泰山](https://blog.csdn.net/weixin_40986713)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### 推荐阅读
|
||||||
|
|
||||||
|
[推荐算法专栏](https://blog.csdn.net/weixin_40986713/category_12268014.html?spm=1001.2014.3001.5482)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### 常见问题
|
||||||
|
|
||||||
|
[点击查看](https://gitee.com/taisan/recommend_system/issues?assignee_id=&author_id=&branch=&collaborator_ids=&issue_search=&label_ids=&label_text=&milestone_id=&priority=&private_issue=&program_id=&project_id=taisan%2Frecommend_system&project_type=&scope=&single_label_id=&single_label_text=&sort=&state=closed&target_project=)
|
||||||
|
|
||||||
|
|||||||
@@ -6,17 +6,25 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author tarzan
|
||||||
|
*/
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class RecommendSystemApplication {
|
public class RecommendSystemApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
//SpringApplication.run(RecommendSystemApplication.class, args);
|
//SpringApplication.run(RecommendSystemApplication.class, args);
|
||||||
System.out.println("------基于用户协同过滤推荐---------------下列电影");
|
System.out.println("------基于用户协同过滤推荐---------------下列电影");
|
||||||
List<ItemDTO> itemList= Recommend.userCfRecommend(2);
|
List<ItemDTO> itemList= Recommend.userCfRecommend(1);
|
||||||
itemList.forEach(e-> System.out.println(e.getName()));
|
itemList.forEach(e-> System.out.println(e.getName()));
|
||||||
System.out.println("------基于物品协同过滤推荐---------------下列电影");
|
System.out.println("------基于物品协同过滤推荐---------------下列电影");
|
||||||
List<ItemDTO> itemList1= Recommend.itemCfRecommend(2);
|
List<ItemDTO> itemList1= Recommend.itemCfRecommend(1);
|
||||||
itemList1.forEach(e-> System.out.println(e.getName()));
|
itemList1.forEach(e-> System.out.println(e.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,8 +33,8 @@ public class CoreMath {
|
|||||||
//关系系数
|
//关系系数
|
||||||
double coefficient = relateDist(v,userItems,type);
|
double coefficient = relateDist(v,userItems,type);
|
||||||
//关系距离
|
//关系距离
|
||||||
double distance=Math.abs(coefficient);
|
// double distance=Math.abs(coefficient);
|
||||||
distMap.put(k,distance);
|
distMap.put(k,coefficient);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return distMap;
|
return distMap;
|
||||||
@@ -50,8 +50,8 @@ public class CoreMath {
|
|||||||
* @return double
|
* @return double
|
||||||
*/
|
*/
|
||||||
private static double relateDist(List<RelateDTO> xList, List<RelateDTO> yList,int type) {
|
private static double relateDist(List<RelateDTO> xList, List<RelateDTO> yList,int type) {
|
||||||
List<Integer> xs= Lists.newArrayList();
|
List<Double> xs= Lists.newArrayList();
|
||||||
List<Integer> ys= Lists.newArrayList();
|
List<Double> ys= Lists.newArrayList();
|
||||||
xList.forEach(x->{
|
xList.forEach(x->{
|
||||||
yList.forEach(y->{
|
yList.forEach(y->{
|
||||||
if(type==0){
|
if(type==0){
|
||||||
@@ -79,7 +79,7 @@ public class CoreMath {
|
|||||||
* @author tarzan
|
* @author tarzan
|
||||||
* @date 2020年07月31日 17:03:20
|
* @date 2020年07月31日 17:03:20
|
||||||
*/
|
*/
|
||||||
public static double getRelate(List<Integer> xs, List<Integer> ys){
|
public static double getRelate(List<Double> xs, List<Double> ys){
|
||||||
int n=xs.size();
|
int n=xs.size();
|
||||||
//至少有两个元素
|
//至少有两个元素
|
||||||
if (n<2) {
|
if (n<2) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class RelateDTO {
|
|||||||
/** 物品id */
|
/** 物品id */
|
||||||
private Integer itemId;
|
private Integer itemId;
|
||||||
/** 指数 */
|
/** 指数 */
|
||||||
private Integer index;
|
private Double index;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ public class FileDataSource {
|
|||||||
|
|
||||||
|
|
||||||
public static String folderPath;
|
public static String folderPath;
|
||||||
|
static {
|
||||||
|
folderPath= Objects.requireNonNull(FileDataSource.class.getResource("/ml-100k")).getPath();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,7 +34,6 @@ public class FileDataSource {
|
|||||||
* @date 2020年07月31日 16:53:40
|
* @date 2020年07月31日 16:53:40
|
||||||
*/
|
*/
|
||||||
public static List<RelateDTO> getData() {
|
public static List<RelateDTO> getData() {
|
||||||
folderPath= Objects.requireNonNull(FileDataSource.class.getResource("/ml-100k")).getPath();
|
|
||||||
List<RelateDTO> relateList = Lists.newArrayList();
|
List<RelateDTO> relateList = Lists.newArrayList();
|
||||||
try {
|
try {
|
||||||
FileInputStream out = new FileInputStream(folderPath+"\\u.data");
|
FileInputStream out = new FileInputStream(folderPath+"\\u.data");
|
||||||
@@ -43,7 +45,7 @@ public class FileDataSource {
|
|||||||
String[] ht = newline.split(" ");
|
String[] ht = newline.split(" ");
|
||||||
Integer userId = Integer.parseInt(ht[0]);
|
Integer userId = Integer.parseInt(ht[0]);
|
||||||
Integer movieId = Integer.parseInt(ht[1]);
|
Integer movieId = Integer.parseInt(ht[1]);
|
||||||
Integer rating = Integer.parseInt(ht[2]);
|
Double rating = Double.parseDouble(ht[2]);
|
||||||
RelateDTO dto = new RelateDTO(userId, movieId, rating);
|
RelateDTO dto = new RelateDTO(userId, movieId, rating);
|
||||||
relateList.add(dto);
|
relateList.add(dto);
|
||||||
}
|
}
|
||||||
@@ -61,7 +63,6 @@ public class FileDataSource {
|
|||||||
* @date 2020年07月31日 16:54:51
|
* @date 2020年07月31日 16:54:51
|
||||||
*/
|
*/
|
||||||
public static List<UserDTO> getUserData() {
|
public static List<UserDTO> getUserData() {
|
||||||
folderPath= Objects.requireNonNull(FileDataSource.class.getResource("/ml-100k")).getPath();
|
|
||||||
List<UserDTO> userList = Lists.newArrayList();
|
List<UserDTO> userList = Lists.newArrayList();
|
||||||
try {
|
try {
|
||||||
FileInputStream out = new FileInputStream(folderPath+"\\u.user");
|
FileInputStream out = new FileInputStream(folderPath+"\\u.user");
|
||||||
@@ -94,7 +95,6 @@ public class FileDataSource {
|
|||||||
* @date 2020年07月31日 16:54:22
|
* @date 2020年07月31日 16:54:22
|
||||||
*/
|
*/
|
||||||
public static List<ItemDTO> getItemData() {
|
public static List<ItemDTO> getItemData() {
|
||||||
folderPath= Objects.requireNonNull(FileDataSource.class.getResource("/ml-100k")).getPath();
|
|
||||||
List<ItemDTO> itemList = Lists.newArrayList();
|
List<ItemDTO> itemList = Lists.newArrayList();
|
||||||
try {
|
try {
|
||||||
FileInputStream out = new FileInputStream(folderPath+"\\u.item");
|
FileInputStream out = new FileInputStream(folderPath+"\\u.item");
|
||||||
|
|||||||
10
src/main/resources/ml-100k/u.data-test
Normal file
10
src/main/resources/ml-100k/u.data-test
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
1 1 1 847117005
|
||||||
|
1 2 10 847642142
|
||||||
|
1 3 1 847641896
|
||||||
|
2 1 2 847642008
|
||||||
|
2 3 2 847641956
|
||||||
|
3 1 3 847641956
|
||||||
|
3 3 3 847642073
|
||||||
|
4 1 4 847642105
|
||||||
|
4 2 1 847116751
|
||||||
|
4 3 5 847116787
|
||||||
Reference in New Issue
Block a user