JAVA Recommender System

The source code address of the project is attached at the end of the article

System principle

The system uses the user-based collaborative filtering algorithm (UserCF) written in Java to calculate the correlation coefficient by using Pearson correlation coefficient of statistics to realize the recommendation system of thousands of people.

Collaborative filtering recommendation algorithm is the earliest and more famous recommendation algorithm. The main functions are prediction and recommendation. The algorithm discovers users’ preferences through mining historical behavior data, divides users into groups based on different preferences and recommends products with similar tastes. CollaboratIve filtering recommendation algorithms can be divided into two categories, namely user-based collaboratIve filtering and item-based collaboratIve filtering. To put it simply: people gather by the same kind, and things by the same group.

Pearson correlation coefficient formula

The Pearson correlation coefficient (Px, Y) of two continuous variables (X,Y) is defined as the covariance between them (cov(X,Y)) divided by the product of their standard deviations (σX,σY). Coefficients are always between -1.0 and 1.0, variables close to 0 are said to be uncorrelated, and variables close to 1 or -1 are said to be strongly correlated. Generally, the correlation strength of variables is judged by the following value range: correlation coefficient 0.8-1.0 strong correlation 0.6-0.8 strong correlation 0.4-0.6 Moderate correlation 0.2-0.4 weak correlation 0.0-0.2 extremely weak correlation or no correlation

Java code implementation

/** * Pearson correlation coefficient calculation * * @param XS * @Param ys * @return {@link Double} * @throws * @author Tarzan * @date 2020 July 31 17:03:20 */ public static Double getRelate(List<Integer> xs, List<Integer> ys){ int n=xs.size(); double Ex= xs.stream().mapToDouble(x->x).sum(); double Ey=ys.stream().mapToDouble(y->y).sum(); double Ex2=xs.stream().mapToDouble(x->Math.pow(x,2)).sum(); double Ey2=ys.stream().mapToDouble(y->Math.pow(y,2)).sum(); double Exy= IntStream.range(0,n).mapToDouble(i->xs.get(i)*ys.get(i)).sum(); double numerator=Exy-Ex*Ey/n; double denominator=Math.sqrt((Ex2-Math.pow(Ex,2)/n)*(Ey2-Math.pow(Ey,2)/n)); If (denominator = = 0) return 0.0; return numerator/denominator; }Copy the code

Software architecture Spring Boot single project

Maven build depends on idea-Java run instructions 1. Find the SRC/main/Java/com/Tarzan arrived/how many/RecommendSystemApplication. Java Java running right

2. Enter different user ids to obtain different recommendation data

3. The file data set mL-100K used in the project is in the SRC/main/resources directory

Source code address: gitee.com/taisan/reco…