推荐算法修改
This commit is contained in:
5
pom.xml
5
pom.xml
@@ -13,17 +13,14 @@
|
|||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<name>recommend_system</name>
|
<name>recommend_system</name>
|
||||||
<description>Demo project for Spring Boot</description>
|
<description>Demo project for Spring Boot</description>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter</artifactId>
|
<artifactId>spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
@@ -47,7 +44,6 @@
|
|||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
@@ -56,5 +52,4 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,13 +1,20 @@
|
|||||||
package com.tarzan.recommend;
|
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.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@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);
|
||||||
|
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 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
|
* @date 2020年07月31日 16:53:40
|
||||||
*/
|
*/
|
||||||
public static List<RelateDTO> getData() {
|
public static List<RelateDTO> getData() {
|
||||||
|
folderPath=new FileDataSource().getClass().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");
|
||||||
|
|||||||
@@ -18,27 +18,22 @@ import java.util.stream.Collectors;
|
|||||||
*/
|
*/
|
||||||
public class Recommend{
|
public class Recommend{
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 方法描述: 猜你喜欢
|
* 方法描述: 猜你喜欢
|
||||||
*
|
*
|
||||||
* @param
|
* @param
|
||||||
* @Return {@link List< ItemDTO>}
|
* @Return {@link List<ItemDTO>}
|
||||||
* @throws
|
* @throws
|
||||||
* @author tarzan
|
* @author tarzan
|
||||||
* @date 2020年07月31日 17:28:06
|
* @date 2020年07月31日 17:28:06
|
||||||
*/
|
*/
|
||||||
public static List<ItemDTO> guessYouLike(){
|
public static List<ItemDTO> guessUserLike(int userId){
|
||||||
CoreMath coreMath = new CoreMath();
|
CoreMath coreMath = new CoreMath();
|
||||||
List<RelateDTO> data= FileDataSource.getData();
|
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());
|
List<ItemDTO> itemList= FileDataSource.getItemData().stream().filter(e->recommendations.contains(e.getId())).collect(Collectors.toList());
|
||||||
return itemList;
|
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