推荐算法修改
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -13,17 +13,14 @@
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>recommend_system</name>
|
||||
<description>Demo project for Spring Boot</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
@@ -47,7 +44,6 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@@ -56,5 +52,4 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
package com.tarzan.recommend;
|
||||
|
||||
import com.tarzan.recommend.Service.Recommend;
|
||||
import com.tarzan.recommend.dto.ItemDTO;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootApplication
|
||||
public class RecommendSystemApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RecommendSystemApplication.class, args);
|
||||
//SpringApplication.run(RecommendSystemApplication.class, args);
|
||||
List<ItemDTO> itemList= Recommend.guessUserLike(2);
|
||||
System.out.println("------猜你可能喜欢---------------下列电影");
|
||||
itemList.forEach(e-> System.out.println(e.getName()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import java.util.List;
|
||||
public class FileDataSource {
|
||||
|
||||
|
||||
public final static String folderPath="F:\\ml-100k";
|
||||
public static String folderPath;
|
||||
|
||||
|
||||
/**
|
||||
@@ -30,6 +30,7 @@ public class FileDataSource {
|
||||
* @date 2020年07月31日 16:53:40
|
||||
*/
|
||||
public static List<RelateDTO> getData() {
|
||||
folderPath=new FileDataSource().getClass().getResource("/ml-100k").getPath();
|
||||
List<RelateDTO> relateList = Lists.newArrayList();
|
||||
try {
|
||||
FileInputStream out = new FileInputStream(folderPath+"\\u.data");
|
||||
|
||||
@@ -18,27 +18,22 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class Recommend{
|
||||
|
||||
|
||||
/**
|
||||
* 方法描述: 猜你喜欢
|
||||
*
|
||||
* @param
|
||||
* @Return {@link List< ItemDTO>}
|
||||
* @Return {@link List<ItemDTO>}
|
||||
* @throws
|
||||
* @author tarzan
|
||||
* @date 2020年07月31日 17:28:06
|
||||
*/
|
||||
public static List<ItemDTO> guessYouLike(){
|
||||
public static List<ItemDTO> guessUserLike(int userId){
|
||||
CoreMath coreMath = new CoreMath();
|
||||
List<RelateDTO> data= FileDataSource.getData();
|
||||
List<Integer> recommendations = coreMath.recommend(2, data);
|
||||
List<Integer> recommendations = coreMath.recommend(userId, data);
|
||||
List<ItemDTO> itemList= FileDataSource.getItemData().stream().filter(e->recommendations.contains(e.getId())).collect(Collectors.toList());
|
||||
return itemList;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<ItemDTO> itemList= Recommend.guessYouLike();
|
||||
System.out.println("------猜你可能喜欢---------------下列电影="+itemList.stream().map(e->e.getName()).collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user