Application Method and System of Knowledge Graph-Based Hybrid Recommendation Model in Movie Recommendation System
By constructing a knowledge graph in the film domain and combining it with an improved TransH model, the problems of lack of transparent recommendation process and data sparsity in film recommendation systems are solved, achieving higher recommendation accuracy and recall, and improving user experience.
Patent Information
- Application Number
- CN202510285689.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-11
- Publication Date
- 2026-03-06
- Estimated Expiration
- 2045-03-11
AI Technical Summary
Existing movie recommendation systems lack a transparent recommendation process, resulting in a poor user experience and problems such as data sparsity, cold start, and insufficient personalized recommendations.
A knowledge graph for the film domain is constructed, and a hybrid recommendation is performed by combining it with an improved TransH model. Movie data is crawled and stored in the Neo4j database. The semantic relationships of the knowledge graph are used to calculate movie similarity. Collaborative filtering and content recommendation are combined, and the least squares method is used to optimize the model error, ultimately achieving TOP-N recommendation.
It improves the accuracy and recall of recommendation results, enhances the interpretability of the recommendation process, solves the cold start problem, and improves the user experience.
Smart Images

Figure CN120216766B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of knowledge graph technology, and in particular relates to a method and system for applying a knowledge graph-based hybrid recommendation model in a movie recommendation system. Background Technology
[0002] In recent years, with the rapid development of internet technology, the massive amount of fragmented information generated daily has led to information overload and data explosion problems, making it time-consuming for users to retrieve desired content from this vast amount of information. Recommendation systems, as a key technology for solving this problem, provide personalized suggestions to users based on their historical behavior and content characteristics through filtering and intelligent decision-making. Originally proposed by Resnick et al., recommendation systems have been rapidly applied in fields such as film, music, e-commerce, and news. Platforms like Tencent Video, QQ Music, Taobao, Douyin, and Weibo all employ various recommendation algorithms.
[0003] Traditional collaborative filtering primarily uses user ratings and click data to calculate similarity, which suffers from data sparsity and cold start problems; while content-based recommendation relies on item attributes, making it effective only in scenarios with new users. To overcome these shortcomings, hybrid recommendation methods have emerged, combining the advantages of collaborative filtering and content recommendation.
[0004] Knowledge graphs, a technology proposed by Google, construct knowledge networks using entities, attributes, and multilateral semantic relationships, and are widely used in intelligent question answering, search, and recommendation systems. Knowledge graphs not only enhance data association in recommendation systems but also improve the interpretability of recommendation results. However, existing movie recommendation systems often only display the results without providing a transparent recommendation process, impacting user experience. Therefore, how to deeply integrate knowledge graphs with recommendation algorithms to provide users with personalized and interpretable recommendation services has become a current research hotspot.
[0005] Significant progress has been made both domestically and internationally in knowledge graph construction and recommendation algorithm improvement. However, issues such as data sparsity, cold start, and personalized recommendations still persist. Overall, leveraging the rich semantic relationships of knowledge graphs to assist recommendations, combined with hybrid recommendation strategies, offers new ideas and methods for addressing information overload, improving retrieval efficiency, and enhancing user experience. Summary of the Invention
[0006] To address the problems existing in the prior art, this invention provides a method for applying a knowledge graph-based hybrid recommendation model in a movie recommendation system.
[0007] This invention is implemented as follows: A method for applying a knowledge graph-based hybrid recommendation model in a movie recommendation system includes:
[0008] Step 1: Construction of a knowledge graph in the film domain;
[0009] Step 2: Improved knowledge graph-based hybrid recommendation model for the movie domain;
[0010] Step 3: Implementation of the movie recommendation system.
[0011] Furthermore, the knowledge graph for the film domain is constructed as follows:
[0012] The selected ml-latest-small dataset contains movie titles, movie genres, user ratings, and external website links; based on the movie data information in ml-latest-small;
[0013] First, the schema layer of the knowledge graph in the film field was designed. Based on the MovieID of each movie in the dataset, the corresponding semi-structured information of movie type, director, lead actor and screenwriter was crawled from the IMDB website using web crawling technology and stored in the local MongoDB database.
[0014] The crawled data is further processed to filter out a very small number of invalid or duplicate information. For the few missing information, null is used to fill in or manual filling is used. The processed data is stored locally in CSV format, thus obtaining a structured movie dataset. Entities and relationships are extracted from the structured movie dataset and organized into triples. The data is then imported into Neo4j using the load csv command to complete knowledge storage, thus completing the construction of the knowledge graph.
[0015] Furthermore, the improved knowledge graph-based hybrid recommendation model for the movie domain:
[0016] By combining the constructed film domain knowledge graph, which contains multiple features such as film lead actors, directors, and genres, the similarity of film content features can be calculated comprehensively using these features.
[0017] The semantic similarity of movies based on knowledge graphs is calculated and then fused with the results of content-based recommendation technology and collaborative filtering recommendation technology to generate a rating result of a single recommendation model based on knowledge graphs.
[0018] Then, the recommendation results of the two single knowledge graph-based models are fitted to the data by adjusting the weights and eliminating the relative error caused by the fusion of multiple models as much as possible;
[0019] Finally, the least squares method is used to reduce the computational error of the hybrid recommendation model;
[0020] Improved knowledge representation learning:
[0021] In the transE model, for a fact triple (h,r,t), relation r is regarded as the translation distance between the head entity and the tail entity after the vector space mapping. Then, the scoring function shown in the formula is used to continuously adjust the model's quality so that h+r in the fact triple is as equal to t as possible, i.e., h+r≈t.
[0022] Compared to TransE, the TransH model provides a hyperplane Wr for each type of relation r in the triplet, on which a relation vector dr is defined. The original head entity h and tail entity t are then mapped onto the hyperplane, denoted by hr and tr. A correct triplet must satisfy the following formula:
[0023] h r +d r =t r
[0024] In TransH, if for both vectors h1 and h2 there exist triples (h1, r, t) and (h2, r, t), then through the mapping of the hyperplane of relation r in TransH, we have:
[0025] h 1r +d r =t r
[0026] h 2r +d r =t r
[0027] In other words, the mappings of h1 and h2 on the hyperplane are identical or approximate; however, h1 and h2 themselves can be dissimilar, meaning they can be distinguished.
[0028] Compared to TransE, which learns an additional mapping vector Wr for each relation during vector update, the projected head and tail entities can be represented as:
[0029]
[0030] Furthermore, the scoring function and loss function used in learning differ; the scoring function and loss function are shown in the formulas below:
[0031]
[0032] L = Σ (h,r,t)∈△ Σ (h′,r′,t′)∈△′ [γ+f r (h,t)-f r (h′,t′)] + .
[0033] While the TransH model solves complex one-to-many and many-to-many relationship problems, it also... Figure 10 The illustrated process shows that the model may introduce incorrect labels during negative sampling. The original TransH model's negative sampling strategy is to first set a certain probability for replacing head or tail entities. The aim is to increase the probability of replacing head entities when the relationship is one-to-many, and to increase the probability of replacing tail entities when the relationship is many-to-one. This replacement strategy improves the accuracy of negative sample generation compared to TransE's random replacement method.
[0034] Furthermore, the implementation of the movie recommendation system is as follows:
[0035] By analyzing the requirements of the recommendation system, the system architecture and functions are designed, including database design and ER diagram design. Based on the collected requirements and the proposed knowledge graph-based hybrid recommendation model, a movie recommendation system is designed and implemented, which includes movie management, graph display, movie search, movie relationship query, user rating and movie recommendation functions; and a visual recommendation display is implemented.
[0036] Another objective of this invention is to provide a knowledge graph-based hybrid recommendation model applied in a movie recommendation system. The system includes:
[0037] Modules for building knowledge graphs in the film field;
[0038] An improved module for an improved knowledge graph-based hybrid recommendation model for the film domain;
[0039] The implementation module is used to implement the movie recommendation system.
[0040] Another object of the present invention is to provide a computer device including a memory and a processor, the memory storing a computer program, which, when executed by the processor, causes the processor to perform the steps of the method for applying the knowledge graph-based hybrid recommendation model in a movie recommendation system.
[0041] Another object of the present invention is to provide a computer-readable storage medium storing a computer program, which, when executed by a processor, causes the processor to perform the steps of the method for applying the knowledge graph-based hybrid recommendation model in a movie recommendation system.
[0042] Another objective of this invention is to provide an information data processing terminal, which is used to implement the application system of the knowledge graph-based hybrid recommendation model in a movie recommendation system.
[0043] Based on the above technical solutions and the technical problems solved, the advantages and positive effects of the technical solution to be protected by this invention are as follows:
[0044] First, this invention proposes a knowledge graph-based hybrid recommendation model, which, compared to traditional recommendation models, demonstrates better accuracy and recall to a certain extent. The effectiveness of the model is verified through experiments, and finally, a movie recommendation system based on the knowledge graph-based hybrid recommendation model is implemented. The main research results are summarized as follows:
[0045] (1) Constructing a knowledge graph in the film domain. This invention utilizes film link information from the ml-latest-small dataset to construct a knowledge graph. Using Python web scraping technology, film data is crawled from the IMDB website. After data processing, the crawled data is stored in a MySQL database and then converted into CSV format and stored in a MongoDB database. The schema layer of the film knowledge graph is designed, the ontology class is determined, and the data is transformed into the structured data required by the knowledge graph. The data is imported into the Neo4j graph database using the load csv command, which facilitates the persistent storage and visualization of structured film knowledge.
[0046] (2) A hybrid recommendation model based on knowledge graphs is proposed. This model comprehensively considers the shortcomings of traditional recommendation models, combining the semantic relationships contained in knowledge graphs as supplementary information to assist recommendations. Furthermore, the negative sampling process of the TransH model is optimized during the vectorization of entity relationships. The model first calculates the semantic similarity of movies using a constructed movie domain knowledge graph. It then fuses the movie similarity based on the knowledge graph with the user rating similarity obtained from collaborative filtering recommendations and the movie content similarity based on content recommendations. The fusion ratio is determined through experiments. The two sets of recommendation results are then fitted to the data, and the final fitted results are sorted according to the rating size. Finally, TOP-N recommendations are performed. Comparative experiments verify the effectiveness of the model, showing higher precision, recall, and F1 score compared to traditional recommendation algorithms.
[0047] (3) Design and implementation of a movie recommendation system based on knowledge graphs. An improved hybrid recommendation model was applied to the system. The system functional requirements were analyzed, and the system functions and architecture were designed, including ER diagram object analysis and database table design. The functions of each module were implemented, and finally, the functions of each module were tested to ensure that the system could run stably while meeting the functional requirements.
[0048] Secondly, existing movie recommendation systems only display the recommendation results without showing the specific recommendation process and methods, lacking interpretability for users and resulting in a poor personalized recommendation experience for users who are more interested in the recommendation process. Utilizing knowledge graphs can more intuitively demonstrate the relationships between results; an improved TransH model is proposed, and experimental results show that it effectively improves the accuracy of recommendation results; and using public datasets for graph construction can alleviate the cold start problem to some extent. Attached Figure Description
[0049] Figure 1 This is a flowchart illustrating the application method of the knowledge graph-based hybrid recommendation model in a movie recommendation system, as provided in this embodiment of the invention.
[0050] Figure 2 This is a system structure diagram of the application of the knowledge graph-based hybrid recommendation model in a movie recommendation system, as provided in an embodiment of the present invention.
[0051] Figure 3 This is a flowchart of content-based recommendation provided in an embodiment of the present invention.
[0052] Figure 4 This is a flowchart of item-based recommendation provided in an embodiment of the present invention.
[0053] Figure 5 This is a user recommendation flowchart provided in an embodiment of the present invention.
[0054] Figure 6 This is a schematic diagram of a knowledge graph provided in an embodiment of the present invention.
[0055] Figure 7 This is a knowledge graph technology architecture diagram provided in the embodiments of the present invention.
[0056] Figure 8 This is a knowledge extraction task classification diagram provided in an embodiment of the present invention.
[0057] Figure 9 This is the entity relationship space diagram provided in the embodiments of the present invention.
[0058] Figure 10 This is a flowchart of the transE process provided in an embodiment of the present invention.
[0059] Figure 11 This is a movie semantic element diagram provided in an embodiment of the present invention.
[0060] Figure 12 This is a flowchart of the knowledge graph construction process provided in an embodiment of the present invention.
[0061] Figure 13This is an information graph crawled from the movie Mission: Impossible-Fallout, provided in an embodiment of the present invention.
[0062] Figure 14 This is a director information graph stored in MongoDB provided in this embodiment of the invention.
[0063] Figure 15 This is a diagram illustrating the process of importing data into the neo4j database, as provided in an embodiment of the present invention.
[0064] Figure 16 This is a command diagram for storing data in Neo4j, provided in an embodiment of the present invention.
[0065] Figure 17 This is a partial movie knowledge graph data diagram stored in Neo4j provided in this embodiment of the invention.
[0066] Figure 18 This is a knowledge graph data diagram of the movie Mission: Impossible-Fallout provided in an embodiment of the present invention.
[0067] Figure 19 This is a comparison diagram of the TransE and TransH models provided in the embodiments of the present invention.
[0068] Figure 20 This is a schematic diagram of vector mapping to a hyperplane provided in an embodiment of the present invention.
[0069] Figure 21 This is an improved TransH flowchart provided in an embodiment of the present invention.
[0070] Figure 22 This is a framework diagram of a hybrid recommendation model based on knowledge graphs provided in an embodiment of the present invention.
[0071] Figure 23 This is a partial data diagram of the dataset provided in this embodiment of the invention.
[0072] Figure 24 These are Hit@10 diagrams under different embedding dimensions provided in embodiments of the present invention.
[0073] Figure 25 These are Meanrank diagrams under different embedding dimensions provided in embodiments of the present invention.
[0074] Figure 26 This is a graph showing the precision, recall, and F1 score corresponding to different fusion ratios provided in the embodiments of the present invention.
[0075] Figure 27 This is a graph showing the precision, recall, and F1 score corresponding to different fusion ratios provided in the embodiments of the present invention.
[0076] Figure 28 This is an accuracy graph corresponding to different K values when α1=0.8 and α2=0.5, provided in an embodiment of the present invention.
[0077] Figure 29 This is a recall graph corresponding to different K values when α1=0.8 and α2=0.5, provided in an embodiment of the present invention.
[0078] Figure 30 This is a graph showing the F1 values corresponding to different K values when α1 = 0.8 and α2 = 0.5, provided in an embodiment of the present invention.
[0079] Figure 31 This is the MAE diagram corresponding to different K values when α1=0.8 and α2=0.5, provided in the embodiments of the present invention.
[0080] Figure 32 This is a user use case diagram provided in an embodiment of the present invention.
[0081] Figure 33 This is an administrator use case diagram provided in an embodiment of the present invention.
[0082] Figure 34 This is a system architecture diagram provided in an embodiment of the present invention.
[0083] Figure 35 This is a system function diagram provided in an embodiment of the present invention.
[0084] Figure 36 This is an ER diagram provided in an embodiment of the present invention.
[0085] Figure 37 This is a user login page diagram provided in an embodiment of the present invention.
[0086] Figure 38 This is the homepage image provided in an embodiment of the present invention.
[0087] Figure 39 This is a screenshot of the historical movie viewing record page provided in an embodiment of the present invention.
[0088] Figure 40 This is a user's historical movie viewing graph provided in an embodiment of the present invention.
[0089] Figure 41 This is a screenshot of a movie review page provided in an embodiment of the present invention.
[0090] Figure 42 This is a diagram of the movie search interface provided in an embodiment of the present invention.
[0091] Figure 43 This is a screenshot of the movie relationship query interface provided in an embodiment of the present invention.
[0092] Figure 44 This is a screenshot of the movie recommendation interface provided in an embodiment of the present invention.
[0093] Figure 45 This is the movie atlas relationship viewing interface provided in this embodiment of the invention.
[0094] Figure 46 This is a user information addition diagram provided in an embodiment of the present invention.
[0095] Figure 47 This is a user information maintenance interface diagram provided in an embodiment of the present invention.
[0096] Figure 48 This is a diagram of the movie information maintenance interface provided in an embodiment of the present invention.
[0097] Figure 49 This is a user login page diagram provided in an embodiment of the present invention. Detailed Implementation
[0098] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0099] like Figure 1 As shown, the method for applying a knowledge graph-based hybrid recommendation model in a movie recommendation system according to an embodiment of the present invention includes the following steps:
[0100] S101, Construction of a knowledge graph in the film field;
[0101] S102, an improved knowledge graph-based hybrid recommendation model for the film domain;
[0102] S103, Implementation of the movie recommendation system.
[0103] like Figure 2 As shown in the figure, the application system of a knowledge graph-based hybrid recommendation model in a movie recommendation system provided by this invention includes:
[0104] Modules for building knowledge graphs in the film field;
[0105] An improved module for an improved knowledge graph-based hybrid recommendation model for the film domain;
[0106] The implementation module is used to implement the movie recommendation system.
[0107] Specific implementation of the present invention:
[0108] 1. For movie recommendations, the main steps can be divided into the following four steps:
[0109] 1) Extract the features and attributes of the movies in the dataset, and represent the extracted movie feature information or attribute labels in vector form;
[0110] 2) Perform representation learning on the feature vectors of each movie to obtain a similarity calculation model that can represent user interests;
[0111] 3) Based on the similarity calculation model in step 2, calculate the similarity between the movie to be recommended and the movies that the user is interested in, and obtain the recommendation list;
[0112] 4) Recommend the N most similar movies to the user using the TOP-N recommendation method; the main flowchart is as follows: Figure 3 Show:
[0113] Table 2.1 User Viewing Schedule
[0114]
[0115] Taking Table 2.1 as an example, User 1 watched movies A, B, and C; User 2 watched movie B; User 3 watched movies A and C. Based on the idea of item-based collaborative filtering, it is assumed that User 1 and User 3 have the same interests and preferences, so the system will recommend movie B, which User 3 has not watched, to User 3.
[0116] The algorithm first constructs a user-movie rating matrix based on users' historical rating data by calculating movie similarity. Then, it calculates the predicted ratings of other similar movies for the user and makes recommendations, suggesting other similar movies that the user likes but hasn't yet watched. The algorithm's implementation steps can be divided into the following:
[0117] Construct a user-movie rating matrix based on users' historical rating data;
[0118] Calculate the similarity between movies in the matrix (the specific calculation method will be introduced later) to obtain an n×n movie similarity matrix;
[0119] The top k movies to be recommended are identified using a movie similarity matrix and then formed into a set.
[0120] The sets are sorted according to their similarity to obtain the final recommendation list. The algorithm flowchart is as follows: Figure 4 As shown:
[0121] The algorithm is based on the premise that two users have similar ratings for the same item, suggesting they share similar interests. Under this premise, it uses a rating prediction formula to predict the target user's rating for that type of item, based on historical rating data from similar users. Table 2.2 illustrates this using movie viewing as an example.
[0122] Table 2.2 User Viewing Schedule
[0123]
[0124]
[0125] User 1 watched movies A and B; User 2 watched movies B and D; User 3 watched movies A, B, and C; User 1 and User 3 both watched movies A and B; however, User 1 did not watch movie C. Based on the user-based collaborative filtering algorithm, User 1 and User 3 have very similar interests, so movie C is recommended to User 1.
[0126] For movie recommendations, user-based collaborative filtering first calculates a set of other users similar to the user, then uses the historical rating data of these similar users to calculate the rating of the movies to be recommended using a rating prediction formula, and finally sorts the predicted ratings from high to low to obtain a list of movies to be recommended. Taking user-based collaborative filtering as an example, its basic implementation steps are as follows:
[0127] 1) Establish a user rating matrix for movies;
[0128] 2) Establish a similarity calculation model between movies based on user ratings;
[0129] 3) Calculate the similarity between each pair of movies based on the obtained calculation model, then calculate the calculated ratings of all unwatched movies and sort them to obtain a recommendation list;
[0130] 4) Recommend the top N movies with the highest predicted ratings from the recommendation list to the target user. The flowchart is as follows: Figure 5 As shown:
[0131] Collaborative filtering essentially leverages 'collective intelligence' by constructing a similarity model between user or item sets and then using historical user ratings to calculate user ratings for unwatched movies for nearest-neighbor recommendations. Here, nearest neighbors refer to user or item sets, as collaborative filtering assumes that similar users might be interested in the same items, or similar items might be liked by the same users. Collaborative filtering combines collective intelligence, effectively utilizing explicit data like user ratings to recommend content that isn't entirely similar, thus effectively uncovering latent user interests compared to content-based recommendations. However, this algorithm also has the following drawbacks: 1) Data sparsity: When the recommendation system or dataset has limited user ratings for movies, the rating matrix becomes sparse, leading to unrepresentative recommendations; 2) Cold start problem: New movies lack user ratings, and new users lack historical data, making similarity calculation impossible and recommendations impossible; 3) Scalability problem: As the amount of data in the dataset increases, the effectiveness and accuracy of recommendations deteriorate.
[0132] like Figure 6 The shown film 1 and science fiction, and the relationship between them, constitute the (Film 1, Genre, Science Fiction) triad.
[0133] The technical architecture of knowledge graphs, such as Figure 7 As shown, this section mainly introduces knowledge extraction, knowledge representation, and knowledge storage.
[0134] Knowledge extraction task classification techniques such as Figure 8 As shown:
[0135] (1) Entity extraction
[0136] Entity extraction automatically identifies "labeled" entities from text data. It is crucial for building knowledge graphs, as the quality of extracted entities directly impacts the accuracy of subsequent knowledge bases and recommendation systems. Entity extraction methods mainly include: 1) rule-based and dictionary-based methods; 2) deep learning-based methods; 3) machine learning-based methods; and 4) extraction based on website sites. This invention primarily employs the method of extraction through vertical websites.
[0137] (2) Relation extraction
[0138] Relation extraction generally involves extracting semantic relationships between entities from textual information. There are three main methods for relation extraction: 1) template-based relation extraction; 2) supervised learning relation extraction; and 3) semi-supervised learning relation extraction.
[0139] (3) Attribute extraction
[0140] Attribute extraction is the process of extracting entity attribute information from data such as text. In the film industry, director, lead actor, and film genre are all attributes. For example, the director attribute value for the film "Film 1" is "Director 1", the actor attribute values are "Actor 3" and "Actor 1", and the film genre attribute values are "Science Fiction", "Romance", and "Comedy". The data used to construct the film domain knowledge graph in this invention comes from the film website IMDb and is semi-structured data.
[0141] 2.2.2 Knowledge Representation
[0142] Knowledge representation is essentially the process of transforming things in our real world into a language that machines can understand. By using computer calculations to simulate human cognition and reasoning about these things, complex computational tasks in the field of artificial intelligence can be solved in this way.
[0143] The TransE model, proposed by Antoine et al. in 2013, represents the entities and relations in a triple (h, r, t) in the same vector space using vector form. The relation vector r is then viewed as a translation between the head entity vector h and the tail entity vector t, i.e., h + r ≈ t. For example, actor 3 + lead actor ≈ movie 1. This model is also known as a translation model. Figure 9 As shown.
[0144] The scoring function for the model is:
[0145]
[0146] If the fact (h, r, t) exists, the score is higher; conversely, if the fact does not exist or its reasonableness is low, the score is lower. The model has advantages such as fast training and ease of implementation. At the same time, it performs well even with large-scale sparse knowledge bases. However, its performance is not very good when dealing with complex relationships (one-to-many, many-to-one, many-to-many). For example, given two facts "Actor 3 - Leading Actor - King of Comedy" and "Actor 3 - Leading Actor - Movie 1", the model's idea would make: Actor 3 + Leading Actor ≈ King of Comedy, Actor 3 + Leading Actor ≈ Movie 1. This would make King of Comedy ≈ Movie 1, but these two movies are different entities and should be represented by different vectors. The main workflow of the transE model is as follows: Figure 10 As shown.
[0147] Its loss function is shown in Equation 2-6. Later researchers improved transE.
[0148]
[0149] The quality of the schema layer design directly affects the quality of the constructed knowledge graph. How to incorporate "high-quality" knowledge into the ontology is the main problem it needs to solve. The semantic elements of the film domain knowledge graph constructed in this invention are as follows: Figure 11 As shown:
[0150] The pattern layer design mainly consists of the following steps:
[0151] 1) Determine the abstract classes; abstract the entities in the movie knowledge graph into classes. For example, abstract the movie name into the movie class (MOVIE), the movie's lead actors, director, and screenwriter into the character class (PERSON), the movie genre into the movie genre class (GENRES), and the movie ID into "MovieID", resulting in a total of 4 entity classes.
[0152] The domain and range of classes in the ontology are determined; the ontology classes, class attributes, domains, and ranges defined in this invention are shown in Tables 3.1 and 3.2, respectively:
[0153] Table 3.1 Ontology Class Design
[0154]
[0155] Table 3.2 Class attributes and constraints in the ontology
[0156]
[0157] 3) Instantiate the ontology: After the schema layer design is completed, the ontology needs to be instantiated. The schema layer is populated at the data level by using the obtained movie domain knowledge graph data.
[0158] The main purpose of constructing the movie knowledge graph in this invention is for personalized recommendations, as described below. The construction of the movie knowledge graph is as follows: Figure 12 As shown.
[0159] 3.2.1 Movie Data Crawling
[0160] Movie data was acquired using Python web scraping, utilizing the `requests` and `Beautiful Soup` libraries and regular expressions. The `requests` library is primarily used to send requests to URLs and receive responses. The `Beautiful Soup` library parses the retrieved HTML pages to extract the necessary content for building the data graph. Since the URL of each movie in the `ml-latest-small` dataset is the IMDB website link "https: / / www.imdb.com / ", followed by "title / tt" and the corresponding `imdbId`, the `imdbId` in the `links.csv` file can be read sequentially to scrape relevant information for each movie. For example, for the movie "Movie 3" with MovieId 189333, the link "https: / / www.imdb.com / title / tt4912910 / " can be created to access the movie's information. Information such as the movie title, director, and cast can then be scraped. Figure 12 As shown
[0161] The crawled movie titles, directors, lead actors, and genres are saved to a local, categorized MongoDB database. For example, regarding movie directors... Figure 13 As shown, the database storing directors is divided into two columns, one containing the movie title and the other the corresponding director, facilitating subsequent structured export. The processing of movie genres and lead actors is the same as for the director, and will not be elaborated upon here. At this point, all the required movie information has been crawled. Figure 14 The crawled director information is stored in MongoDB.
[0162] This invention primarily uses `load csv` to import data and the Cypher language to query the data. The specific method is as follows:
[0163] Place the four files—movie lead actor, director, movie genre, and MovieID—in the import folder of the neo4j installation directory as .csv files.
[0164] 2) In the bin directory, open a command line window and execute the command "neo4j.bat console" to start the neo4j database service.
[0165] 3) In the database management visual interface, enter the command `LOAD csv WITH HEADERS FRON / filename.csv" AS csv` to import the data into Neo4j for storage. This invention uses a Python program to import four sets of data simultaneously. A screenshot of the program is shown below. Figure 15 , 16 As shown.
[0166] Once the data storage is complete, the knowledge graph for the film domain is constructed, such as... Figure 17 As shown in the image. You can enter Cypher statements in the visual management interface to search for and retrieve knowledge. Taking the movie "Movie 3" as an example, by entering the command "Match(m:Movie{title:Movie3'})--(n)return m,n" in the Neo4j command bar, you can retrieve all relations and tail entities corresponding to the movie as the head entity, such as... Figure 18 As shown in Table 3.4, the entity types and number of entities in the film domain knowledge graph constructed in this invention represent the total number of entities (35,172) and relations (72,508). The specific number of each type of entity and relation can be viewed in Tables 3.4 and 3.5. The film domain knowledge graph implemented in this invention was obtained by crawling film information from the IMDB website within the ml-latest-small dataset and implemented according to the model requirements of this invention.
[0167] Table 3.4 Entity Information of the Knowledge Graph in the Film Domain
[0168]
[0169]
[0170] Table 3.5 Relationship Information of the Knowledge Graph in the Film Domain
[0171]
[0172] Using MovieID from the ml-latest-small dataset, movie data (directors, lead actors, editors, movie genres, etc.) was crawled from the movie website IMDB. Through the design of a knowledge graph pattern layer for the movie domain, the crawled semi-structured data was transformed into structured data through knowledge extraction and stored persistently in the database. Thus, the knowledge graph for the movie domain was completed, providing data and technical support for the subsequent implementation of a movie recommendation system.
[0173] In the transE model, for the fact triple (h,r,t), relation r is regarded as the translation distance between the head entity and the tail entity after the vector space mapping. Then, the scoring function shown in formula (2-5) is used to continuously adjust the model's quality so that h+r in the fact triple is as equal to t as possible, i.e., h+r≈t.
[0174] While the transE model has advantages such as fast training and ease of implementation, it also has limitations in handling complex one-to-many and many-to-many relationships. The transH model, proposed by subsequent researchers, effectively addresses this issue. A comparison of the transE and transH models is shown in the figure below. Figure 19 As shown:
[0175] Compared to TransE, the TransH model provides a hyperplane Wr for each type of relation r in the triplet. A relation vector dr is defined on the Wr hyperplane, and the original head entity h and tail entity t are mapped onto the hyperplane, denoted by hr and tr. A correct triplet must satisfy the following formula:
[0176] h r +d r =t r (4-2)
[0177] In TransH, if for both vectors h1 and h2 there exist triples (h1, r, t) and (h2, r, t), then through the mapping of the hyperplane of relation r in TransH, we have:
[0178] h 1r +d t =t r (4-3)
[0179] h 2r +d r =t r (4-4)
[0180] In other words, the mappings of h1 and h2 on the hyperplane are identical or approximately the same. However, h1 and h2 themselves can be dissimilar, meaning they can be distinguished. For example... Figure 20 As shown:
[0181] Although TransH adds the step of transforming each relation vector to a hyperplane space compared to TransE, the overall learning parameters only increase by one term (Wr) compared to TransE, so its algorithm efficiency remains high. Its main process is the same as TransE, except that when updating the vector representation, TransH learns an additional mapping vector Wr for each relation. The projected head and tail entities can be represented as:
[0182]
[0183] Furthermore, the scoring function and loss function used in learning differ, and the scoring function and loss function are shown in formulas (4-7) and (4-8):
[0184]
[0185] L = Σ (h,r,t)∈△ Σ (h′,r′,t′)∈△′ [γ+f r (h,t)-f r (h′,t′)] + (4-8)
[0186] While the TransH model solves complex one-to-many and many-to-many relationship problems, it also... Figure 10 The illustrated process shows that the model may introduce incorrect labels during negative sampling. The original TransH model's negative sampling strategy is to first set a certain probability for replacing head or tail entities. The aim is to increase the probability of replacing head entities when the relationship is one-to-many, and to increase the probability of replacing tail entities when the relationship is many-to-one. This replacement strategy improves the accuracy of negative sample generation compared to TransE's random replacement method.
[0187] Figure 21 The improved TransH model flowchart is shown, which fully demonstrates how the combination of virtual damped phase-locked loop strategy and negative sample replacement mechanism can optimize each stage of data preprocessing and model training, thereby improving the robustness and performance of the overall system.
[0188] The main idea of the model is as follows: (1) The movie entities in the knowledge graph constructed by this invention are vectorized using the translation distance model, and the semantic similarity between movies is calculated; (2) For content-based recommendation, a content similarity matrix is constructed, and for collaborative filtering recommendation, a movie rating similarity matrix is constructed. The two similarity matrices are then fused with the semantic similarity of the knowledge graph; (3) The results of the two single models are mixed using a weighted method, and the fusion weight factor is adjusted; (4) The least squares method is used to reduce the relative error of the model, and TOP-N recommendation is performed. The flowchart is as follows. Figure 22 As shown.
[0189] Similarity calculation involves using a distance formula to determine the distance between two feature vectors (the greater the distance, the lower the similarity; the closer the distance, the higher the similarity). For example, M and N are both K-dimensional feature vectors, represented as M = (m1, m2, ..., mk) and N = (n1, n2, ..., nk). Common methods for calculating the distance between two entities M and N include Euclidean distance, cosine distance, and Pearson correlation coefficient. The cosine distance formula is often used to calculate sparse matrices, while Euclidean distance is often used to calculate dense matrices.
[0190] (1) Calculate the semantic similarity of movies
[0191] Using the improved TransH model, the vectorized representation of film entities and film relationships in the film domain knowledge graph constructed in this invention is obtained as equation (4-9):
[0192] mi=[mi1,mi2,…,mik]T(4-9)
[0193] Where i represents the i-th movie, k represents the embedding dimension, and mik represents the value of movie mi in the k-th dimension. Since the matrix formed by the movies is dense, Euclidean distance is used to calculate the semantic similarity between movies. The expression for Euclidean distance is shown in (4-10):
[0194]
[0195] When the difference d(ma, mb) between two entities is large, it indicates that the Euclidean distance is large and the similarity is small; when it is small, it indicates that the Euclidean distance is small and the similarity is large. The similarity expression is shown in (4-11):
[0196]
[0197] As shown in the formula, the similarity value ranges from [0, 1]. A similarity value approaching 1 indicates a high degree of correlation, while a similarity value approaching 0 indicates a low degree of correlation. By calculating the similarity between each pair of movies, a movie semantic similarity matrix can be obtained. The movie semantic similarity matrix is shown in Table 4.1:
[0198] Table 4.1 Movie Semantic Similarity Matrix
[0199]
[0200] (2) Similarity of movie content
[0201] First, define the set of all movies in the movie dataset as M = {m1, m2, ..., mn}; the set of all users as U = {u1, u2, ..., uk}; and the set of all movie types as T = {t1, t2, ..., tr}, where tr represents the movie type; tr = 1 if a movie contains that type, and tr = 0 if it does not. Representing each movie with a type vector allows us to calculate the similarity between two movies, thus obtaining the similarity between them.
[0202] Based on the above definitions, the movie type vector of movie ma can be represented as Ta = {Ta1, Ta2, ..., Tar}, and movie mb can be represented as Tb = {Tb1, Tb2, ..., Tbr}. After obtaining the type vectors of the two movies, this invention uses the cosine similarity formula to calculate the similarity between movies ma and mb. The calculation formula is shown in equation (4-12):
[0203]
[0204] If we use r (rating) to represent a user's rating of a movie, then user u's rating of movie ma can be represented by rua. If the user has not watched movie mb, we can use the rating of ma, based on the previously calculated movie similarity, to predict the user's predicted rating of movie mb. Therefore, the formula for calculating rua's rating can be expressed as formula (4-13):
[0205]
[0206] Here, simCB(Ta,Tb) is the movie similarity between movie ma and movie mb calculated using the cosine similarity formula, rua represents user u's historical rating of movie ma, and N(b,k) represents the set of the top k movies with the highest similarity to movie mb. After obtaining the user's predicted rating for each movie, a recommendation list is obtained by ranking by rating size. Then, the top N movies in the recommendation list are selected for TOP-N recommendations based on the rating ranking.
[0207] (3) Movie rating similarity
[0208] Define the set of all movies in the movie dataset as M = {m1, m2, ..., mn}; the set of all users as U = {u1, u2, ..., uk}; and let ria represent the rating of user ui for movie ma. To obtain the rating data of all users for movies, it is necessary to calculate the similarity between each movie pairwise. The set of ratings for a particular movie by all users in the dataset is denoted as a rating vector. Assuming there are k users in the dataset, the rating vector for movie ma can be represented as ra = {r1a, r2a, ..., rka}; similarly, the rating vector for movie mb is rb = {r1b, r2b, ..., rkb}. After representing all movies with rating vectors, the similarity between movies can be calculated. This invention uses a cosine similarity calculation formula based on the Pearson correlation coefficient. The calculation formula is shown in equation (4-14):
[0209]
[0210] Where Ua and Ub represent the sets of users who have watched movies ma and mb respectively, Ua,b represents the set of users who have watched both movies ma and mb, and rua and rub represent the rating data of users in the user sets for movies ma and mb respectively. This represents the average rating of all movies by all users in the dataset. The purpose of including the average in the formula is to reduce the error caused by different users having different evaluation standards. User u's rating of movie ma can be represented as rua. From this, the predicted rating rub for user u's rating of movie mb can be calculated, as shown in equation (4-15):
[0211]
[0212] After obtaining the movie semantic similarity matrix, movie content similarity matrix, and movie rating similarity matrix, when fusing the movie semantic similarity matrix with the movie content similarity matrix and the movie rating similarity matrix respectively, it is first necessary to determine the fusion ratio. The movie semantic similarity formula is shown in (4-11), the movie content similarity formula is shown in (4-12), and the movie rating similarity formula is shown in (4-14). Assuming that the fusion ratios of the knowledge graph-based semantic similarity and the similarity of the two traditional recommendation algorithms are a1 and a2 respectively, the similarity expressions of the traditional recommendation model fused with the knowledge graph-based movie semantic similarity are as follows:
[0213] sim CKG (m a ,m b )=α1sin KG (m a ,m b)+(1-α1)sin CB (m a ,m b (4-16)
[0214] sim CFKG (m a ,m b )=α2sin KG (m a ,m b )+(1-α2)sin CF (m a ,m b (4-17)
[0215] Given that user u rated movie ma, the rating formula for movie mb can be expressed as:
[0216]
[0217] Where R ub It is user u's predicted rating for the movie MB. Let be the average rating of all users for movie ma in the dataset. Then, the rating calculation formulas for content-based recommendation after incorporating semantic similarity from the knowledge graph and collaborative filtering recommendation after incorporating semantic similarity from the knowledge graph are shown in equations (4-19) and (4-20), respectively:
[0218]
[0219]
[0220] 4.2.3 Data Fitting
[0221] The recommendation result of the hybrid recommendation model is obtained by fusing the individual models according to a certain weight ratio w. Since the error brought by each individual model is unpredictable, it is necessary to adjust the weight w to reduce the relative error J brought by the fusion of individual models.
[0222] Suppose there are n individual recommendation models, and the result obtained by these n individual recommendation models is y(xi)j (j=1,2,…,n), where xi (i=1,2,…,k) represents the i-th user rating data, k represents the total number of user ratings in the dataset, and ω=(ω1,ω2,…,ωn) represents the weight of each individual recommendation model. Then the formula for the rating prediction result obtained by each individual model after data fitting is as follows:
[0223] Φ(x i )=ω1y(x i )1+ω2y(x i )2+…+ωn y(x i ) n (4-4)
[0224] in, In determining the weights ω = (ω1, ω2, ..., ωn) of the hybrid recommendation model, the relative error method can be used to solve for the weights. This is beneficial to the output stability of the hybrid recommendation model. After obtaining the rating data Φ(xi) of the hybrid recommendation model, assuming the true rating data is Y(xi) and the relative error is J, the relative error calculation formula is as follows:
[0225]
[0226] The weight ω = (ω1, ω2, ..., ωp) can be obtained by solving for the minimum value of the relative error J in equation (4-5). Let R be an n-row, 1-column matrix with all elements equal to 1. Then the formula for calculating the weight ω is shown in equation (3-7):
[0227]
[0228] Wherein, U is the inverse matrix of the diagonal matrix composed of the true scores Y(xi) (i=1,2,…,n), as shown in Equation (4-7); Φ is the matrix composed of the actual calculated scores obtained by each single recommendation model y(xi)j (j=1,2,…,p), as shown in Equation (4-8).
[0229]
[0230] Φ=[y(x i )1,y(x i )2,…,y(x i ) p ] m×n (i = 1, 2, ..., n) (4-8)
[0231] After fitting the model to the data, this invention fits collaborative filtering recommendation based on knowledge graphs and content recommendation based on knowledge graphs to obtain fusion factors α1 and α2. To make the predicted scores more accurate and the obtained model more stable, this invention also uses the least squares method to make the predicted scores closer to the actual scores. The least squares fitting formula is shown in Figure 4-9:
[0232] y = ax + b (4-9)
[0233] The least squares method can be used to reduce the mean square error of the model, and its formula can be expressed as:
[0234] y(x i )=αΦ(xi)+b (4-10)
[0235] Where y(x) i ) represents the final predicted score, x i Let y(x) represent the rating data of the i-th user in the dataset, and Φ(xi) represent the predicted rating data after fitting the data to obtain the weights α1 and α2 of the two models. To make y(x) = ... i The equation that is closer to Y(xi) (the actual rating data) is actually transformed into a problem of solving for α and b.
[0236]
[0237]
[0238] Taking the partial derivatives of α and b in (4-12) respectively, we can obtain the optimal solutions for parameters α and b as shown in (4-13) and (4-14):
[0239]
[0240] a * b * From equation (4-10), we can obtain the final prediction score formula (4-15) for the model:
[0241]
[0242] Using equation (4-15), the predicted rating of the movie by the end user can be obtained. The rating data is sorted from high to low, and the top n are recommended to the user.
[0243] The dataset in this invention is divided into two parts:
[0244] The first part is the publicly available movie dataset ml-latest-small. Detailed data information for this dataset is shown in Table 4.2.
[0245] Table 4.2 ml-latest-small contents table
[0246]
[0247] Part of the data in the dataset, such as Figure 23 As shown (from left to right: movie title and genre information, user rating information, movie link information):
[0248] The second part is the film domain knowledge graph dataset constructed in Chapter 3. This dataset mainly consists of information such as the lead actors, director, and genre of each movie crawled from the IMDB website using web crawlers, based on the imdbId corresponding to the movies in the ml-latest-small dataset. To avoid the dataset becoming too large, the crawling process was limited to crawling only 3 lead actors, 1 director, and all movie genre information for each movie. This dataset is primarily used to calculate semantic similarity based on the knowledge graph for auxiliary recommendations.
[0249] 4.3.2 Evaluation Indicators
[0250] Common evaluation metrics for measuring the performance of knowledge representation learning models include hit rate (Hit) and mean rank (Meanrank). Hit refers to the probability of a predicted rank matching the actual data; common values are Hit@10, Hit@50, and Hit@100. Hit@10 indicates the number of times a predicted value matches an actual value in the dataset. For example, if a predicted movie is among the top ten movies a user actually likes, the value is incremented by one; a higher value indicates better prediction performance. The same logic applies to Hit@50 and Hit@100. Mean rank is the average of the predicted rank among the actual results; a lower value indicates a better model performance.
[0251] Precision, recall, and F1 score are the three most commonly used metrics for evaluating the performance of recommendation systems. Their calculation formulas are shown in equations (4-9), (4-10), and (4-11), respectively. The meaning of each term in the formula is shown in Table 4.3.
[0252]
[0253] Table 4.3 Confusion Matrix
[0254]
[0255] As shown in formula (4-9), precision refers to the percentage of movies recommended to a user that they like out of all recommended movies; recall refers to the percentage of movies recommended to a user that they like out of all movies the user likes; the F1 score is the harmonic mean of precision and recall, aiming to find a balance point where precision and recall are both optimal. Higher values for these three metrics indicate better model performance. In this invention, a rating greater than 3.5 is considered "liked" by the user, and less than 3.5 is considered "disliked."
[0256] To verify the stability of the model, this invention also uses the mean absolute error (MAE) as an indicator to evaluate the model's stability, and its calculation formula is shown in equation (4-12):
[0257]
[0258] Where n represents the number of ratings, y(xi) represents the model's predicted rating, and Y(xi) represents the actual rating. The smaller the MAE value, the smaller the difference between the model's predicted value and the actual value, and the better and more stable the model performance.
[0259] The improved TransH model was compared with the TransE model to determine its effectiveness across different dimensions. Key parameters used in the experiments included the learning rate *l*, the embedding dimension *embed_dim*, the margin, the number of triples processed per iteration (BatchSize), and the number of iterations *n*. The learning rate was set to l = 0.01, the margin to 1, and the embedding dimension to *n*. (100, 200, 300, 400, 500, 600), BatchSize = 100, iterate 400 times, calculate the hit rate under different dimensions, and use the mean rank to verify the effectiveness of the model.
[0260] Depend on Figure 24 and Figure 25 As shown, the improved TransH model exhibits a hit rate that first increases and then decreases with the increase of embedding dimension, reaching a peak hit@10 = 0.57 when embedding_dim = 300. The TransH and TransE models show roughly the same trend. However, in terms of Meanrank, the improved TransH model shows a trend of first decreasing and then increasing with the increase of embedding dimension. Furthermore, the improved TransH model consistently performs worse than the TransH and TransE models in terms of Meanrank. Compared to the traditional Trans model, the improved model can make effective recommendations for user behavior with a higher hit rate and average ranking, demonstrating the effectiveness of the model.
[0261] In addition to validating the improved TransH model, this invention also conducted experimental analysis on hybrid recommendation models. The proposed knowledge graph-based hybrid recommendation model was compared with content-based, item-based collaborative filtering, and user-based collaborative filtering models. For ease of description and experimental comparison, the recommendation models used are listed in Table 4.4 using their English abbreviations.
[0262] Table 4.4 Algorithm Abbreviations
[0263]
[0264] The comparison and verification are mainly conducted from the following aspects: (1) Determine the fusion ratios α1 and α2 between the semantic similarity of the movie domain obtained based on the movie domain knowledge graph and the similarity of content-based recommendation and item-based collaborative filtering recommendation. (2) Verify the effectiveness of the hybrid recommendation model. (3) Compare the mean absolute error of several models and some performance data of several traditional recommendation algorithms.
[0265] The specific experimental results are as follows:
[0266] (1) Determine the fusion ratios α1 and α2;
[0267] With a fixed number of recommended movies K=10, to determine the fusion ratio α1 of movie semantic similarity and CB similarity based on knowledge graph, experiments were conducted with α1 incremented from 0 to 1 in increments of 0.1. When α1=0, it represents content-based recommendation; when α1=1, it represents movie semantic similarity, and content-based similarity is not used for recommendation. The experimental results of CB with different fusion ratios are as follows: Figure 26 As shown
[0268] Figure 26 The horizontal axis represents the fusion ratio α1, and the vertical axis represents the precision, recall, and F1 score of CB at different fusion ratios. Figure 26 It can be seen that in the ml-latest-small dataset, when the number of recommended movies K remains constant, as the fusion ratio α1 gradually increases, the precision of the fused algorithm first increases and then decreases, reaching its maximum at α1 = 0.8. The recall and F1 score of the fused algorithm both show a trend of first increasing and then gradually stabilizing. A larger F1 score indicates a more robust model. When the F1 scores are not significantly different, the precision reaches its maximum at α1 = 0.8, indicating the highest accuracy of the recommendations. Therefore, based on the experimental results, the fusion ratio α1 can be set to 0.8.
[0269] With a fixed number of recommended movies K=10, to determine the fusion ratio α2 of movie semantic similarity based on knowledge graph and ItemCF, experiments were conducted by incrementing α2 from 0 to 1 in increments of 0.1. When α2=0, it represents item-based collaborative filtering recommendation without fusing movie semantic similarity; when α2=1, it indicates full fusion of movie semantic similarity, without using ItemCF similarity for recommendation. Experimental results for ItemCF with different fusion ratios are shown below. Figure 26 As shown.
[0270] Figure 27 The horizontal axis represents the value of the fusion ratio α2, and the vertical axis represents the precision, recall, and F1 score of ItemCF for different fusion ratios. Figure 27It can be seen that in the ml-latest-small dataset, when the number of recommended movies K remains constant, as the fusion ratio α2 gradually increases, the precision of the fused algorithm shows a trend of first increasing and then decreasing, reaching its maximum at α2 = 0.5. The recall and F1 score of the fused algorithm also show a trend of first increasing and then decreasing. A larger F1 score indicates a more robust model. Since the F1 score reaches its maximum at α2 = 0.5, and the precision is also highest at this point, based on the experimental results, the fusion ratio α2 can be set to 0.5.
[0271] Verify the effectiveness of the Mix-KG model.
[0272] Based on the fusion ratios α1 and α2 determined in experiment (1), with the fusion ratios α1 = 0.8 and α2 = 0.5 fixed, and the recommended number of movies K set to 10, 20, 30, 40, 50, 60, and 70 respectively, experiments were conducted on the ml-latest-small dataset to compare CB, Item-CF, User-CF, and CFCKG algorithms. The accuracy of the four algorithms is as follows: Figure 28 As shown, the recall rate is as follows: Figure 29 As shown, the F1 value is as follows Figure 30 As shown.
[0273] In the ml-latest-small dataset, when the fusion ratios α1 and α2 are fixed, the precision of all four algorithms decreases while the recall increases as the number of recommended movies K increases. The F1 scores of all four algorithms gradually increase with increasing number of recommended movies K. When the K value is the same, the Mix-KG model has the highest precision, recall, and F1 score, followed by the User-CF and Item-CF models, while the CB model performs the worst. The F1 scores of Mix-KG and CB reach their maximum at K=60, while the F1 scores of User-CF and Item-CF reach their maximum at K=50. A higher F1 score indicates a more robust model. The Mix-KG model proposed in this invention demonstrates excellent experimental results in terms of precision, recall, and F1 score.
[0274] (3) Error verification
[0275] Based on the fusion ratios α1 and α2 determined in experiment (1), with the fusion ratios α1 = 0.8 and α2 = 0.5 fixed, and the recommended number of movies K set to 10, 20, 30, 40, 50, 60, and 70 respectively, error experiments were conducted on CB, Item-CF, User-CF, and Mix-KG in the ml-latest-small dataset for comparison. The mean absolute error (MAE) of the four algorithms is as follows: Figure 31 As shown.
[0276] from Figure 31 It can be seen that in the ml-latest-small dataset, when the fusion ratios α1 and α2 are fixed, and with the same K value, the Mix-KG model proposed in this invention has the smallest mean absolute error (MAE). The MAE value of User-CF is slightly smaller than that of Item-CF but larger than that of Mix-KG. The three algorithms generally reach their minimum MAE value when K=20. CB has the largest MAE value, reaching its minimum value when K=30, but it is still larger than the MAE values of the other three algorithms. A smaller MAE value indicates a smaller error in the calculation of the obtained score by the recommendation model, and a better performance in TOP-N recommendation. The Mix-KG model proposed in this invention has a smaller MAE than the other three algorithms, demonstrating the superiority of the Mix-KG model.
[0277] First, the main principles of the TransH model are introduced, and an improved negative sampling optimization strategy for the TransH model is proposed. Through the improved TransH model, movie semantic similarity matrix, movie content similarity matrix and movie rating similarity matrix are obtained respectively. The optimal fusion ratio between the models is determined through experiments. Through comparative experiments, the advantages of the hybrid model over the single model are demonstrated, and better results are achieved in the evaluation index, proving the effectiveness of the model.
[0278] 5. Design and Implementation of a Movie Recommendation System
[0279] 5.1 System Functional Requirements Analysis
[0280] Functional requirements analysis is a crucial step in system development. Its purpose is to define the modules and functions involved in the system development process. Functional requirements analysis generally starts from the specific users of the system, analyzing the functional requirements of different user roles from the user's perspective. For this system, the main roles are administrators and users.
[0281] For user roles, the first step is to log in to the system using a username and password. New users need to register before logging in. After registration, users can modify their personal information, search for movies, view watched movies (displayed in a knowledge graph format), view relationships between movies and related movies, rate and review movies, and receive real-time recommendations. (Example user diagram follows.) Figure 32 As shown:
[0282] For the administrator role, administrator privileges require granting by a super account, with initial super accounts directly writing data to the database. Administrators can view user account information, reset user passwords, edit user information, and add or delete users. Administrators can also manage movie information, including editing, adding, and deleting movie entries.
[0283] The administrator use case diagram is shown in Figure 33:
[0284] 5.2 System Design
[0285] 5.2.1 System Architecture Design
[0286] The movie recommendation system designed in this invention adopts a B / S architecture, with the front end using the Vue framework and the back end using Node.js. The system architecture and the functions implemented in each layer are as follows: Figure 34 As shown.
[0287] The application layer's primary function is to collect user requests and return the results, forming a crucial component of system-user interaction. The business layer, situated below the application layer and above the data layer, primarily processes user requests, handles data returned from the data layer, and then returns the processed data to the business layer for display. The system's main logic is implemented in the business layer, and its design directly impacts the user experience. The data layer's main functions include connecting to the database, reading and writing data, and data caching. The underlying database primarily handles persistent storage.
[0288] This invention divides the system functions into the following three parts: user management, movie management, and administrator. Detailed functions of each module are as follows: Figure 35 As shown. The system modules designed in this invention are independent of each other, which facilitates the addition of functions and system maintenance in the later stage, and at the same time improves system stability, ensuring that a problem in one module will not affect the use of other modules.
[0289] (1) User Management Module
[0290] User management primarily includes user login functionality. New users need to contact the administrator to register an account and fill in their personal information. After successful registration, they can log in to the system. The user rating function allows users to rate and comment on their past viewing history. The viewing history mainly stores the viewing records and ratings of 610 users in the dataset. New users do not have a viewing history.
[0291] (2) Movie Management Module
[0292] The movie management module mainly includes movie search, movie recommendation, and movie relationship query functions. The movie search function allows users to search for movies by name and displays key information in a graph format, including lead actors, cast, genre, and director. Entering the movie IDs of two movies also allows searching for relationships between them. The movie recommendation function uses the hybrid recommendation model proposed in Chapter 4 to determine user interests and preferences based on their viewing history, selecting ten movies that the user might be interested in from the pool of movies to be recommended.
[0293] The administrator module primarily implements user and movie information maintenance functions. User management functions include new user registration, user information modification, and password reset, ensuring that users can log in smoothly and manage their personal information; movie information maintenance functions support administrators to add, modify, and delete movie records, ensuring the accuracy and integrity of movie data in the database in real time.
[0294] In terms of database design, an ER diagram was used to identify entities such as users, movie types, movies, administrators, and user ratings within the system, and the attributes of each entity and their relationships were defined in detail. Based on the ER diagram design, the system established tables for user information, movie information, administrator information, user ratings, movie types, and movie reviews. Each table has clearly defined primary keys, data types, and field constraints to ensure data consistency and efficient querying.
[0295] The system's functional design encompasses three modules: user management, movie management, and administrator. The user management module enables login, querying viewing history, and user reviews; the movie management module supports movie searching, movie relationship queries, and personalized movie recommendations, displaying movie-related information in a graph format; the administrator module is responsible for creating and maintaining user and movie information, ensuring continuous data updates. Each functional module is presented through intuitive interface diagrams, such as the user login page, homepage, viewing history graph, and movie recommendation interface.
[0296] System development and testing were conducted in a rigorous development environment, including a testing environment with key components such as Windows 10, 16GB of RAM, Neo4j, MongoDB, MySQL, Python, Node.js, and Vue. After environment configuration and multi-module testing (such as user login, movie search, recommendation results, and administrator information maintenance), the system ran stably and successfully implemented a movie recommendation system based on a knowledge graph hybrid recommendation model. It achieved the expected results in personalized recommendations, data storage, and information display.
[0297] Open VS Code, and in the frontend directory, enter the command `npm run server` to start the frontend service. In the backend directory, enter `node server.js` to open the MongoDB client and establish a database connection. Open Neo4j to start the graph database. All relevant system services are now running. Next, enter `localhost:8080 / ` in your browser to access the system's login page. Since the system's original data uses the dataset `ml-latest-small`, which contains 100,000 rating records for different movies from 610 users, we will use user 3 as an example for testing.
[0298] The user management module implements core functions such as user login, display of viewing history, and user ratings. Users can successfully access the system homepage after entering their username and password on the login page; if the information is incorrect, a login failure message will be displayed. The system can display the user's historical rating records and visually represent the relationships between movies, directors, actors, genres, etc., in a graphical format. It also allows users to rate the movies they watch.
[0299] The movie management module provides movie search, movie recommendation, and movie relationship query functions. Users can quickly obtain detailed movie information by entering the movie name in the online search function; after clicking "Start Recommendation", the system uses the results of an offline-generated knowledge graph-based hybrid recommendation model to generate a personalized recommendation list for the user and display it in tabular form; in addition, users can also query the relationship between two movies by entering the movie ID, and the system presents the relevant connections in a graph format.
[0300] The administrator module is primarily used for maintaining user and movie information. Administrators can register new users, modify user information, reset passwords, and add, edit, and delete movie information, ensuring the timely updating and accuracy of system data. All functional interfaces have been tested, demonstrating that the system is stable and efficient in information management.
[0301] Overall, the knowledge graph-based hybrid recommendation model for movie recommendations achieves personalized and visual movie recommendations by constructing a knowledge graph in the movie domain, improving the hybrid recommendation algorithm (integrating content-based, collaborative filtering, and semantic similarity), and designing a robust system architecture. The system outperforms traditional algorithms in precision, recall, and F1 score, and provides directions for improvement in areas such as cloud-based online recommendation, knowledge graph expansion, and the introduction of time factors.
[0302] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any modifications, equivalent substitutions, and improvements made by those skilled in the art within the scope of the technology disclosed in the present invention, and within the spirit and principles of the present invention, should be covered within the scope of protection of the present invention.
Claims
1. A method for applying a hybrid recommendation model based on a knowledge graph in a movie recommendation system, characterized in that, The method comprises the following steps: S101, constructing a movie field knowledge graph; S102, constructing an improved hybrid recommendation model based on the movie field knowledge graph; S103, implementing a movie recommendation system and applying the hybrid recommendation model obtained in step S102 to the movie recommendation; Step S102 comprises: (a) using the constructed movie field knowledge graph, representing the movie entities and relationships in a vector form through a translation distance model, and calculating the movie semantic similarity; (b) using the movie content features and user rating data to construct a content-based recommendation similarity matrix and a collaborative filtering-based similarity matrix, respectively; (c) weighting and fusing the movie semantic similarity obtained in step (a) and the similarity matrix obtained in step (b) according to predetermined fusion proportions α1 and α2 to obtain a single recommendation model score result based on the knowledge graph; (d) adjusting the weight of each single model result and using the least squares method to fit to reduce the relative error in the fusion process to obtain the predicted score of the final hybrid recommendation model; Step S102 further comprises using the obtained movie entity vector to calculate the semantic similarity between movies using the Euclidean distance formula, and calculating the movie content similarity and movie rating similarity using the cosine similarity or the Pearson correlation coefficient-based method, and then fusing according to the following formula: ; ; where, α1 and α2 are fusion ratio parameters determined by experiments respectively; then and are respectively brought into formula , two single recommendation model scores are calculated, wherein R ub is the predicted score of the user u to the movie m b , is the average score of all users in the data set to the movie m a .
2. The method of claim 1, wherein, Step S101 further comprises: (a) selecting a public data set containing movie name, movie type, user rating and external link information, collecting the director, leading actor, screenwriter and semi-structured movie type information of each movie from the IMDB website using web crawler technology according to the MovieID of each movie; (b) removing duplicates, filling in missing values and converting formats for the collected data to generate a structured movie data set and store it in CSV format; (c) extracting entities and their relationships in the structured data into triples, and using the LOAD CSV command to import the data into the Neo4j graph database to complete the construction of the knowledge graph.
3. The method of claim 2, wherein, The mode layer design of the movie field knowledge graph in step S101 comprises: (a) abstracting the movie knowledge into movie (MOVIE), person (PERSON), movie type (GENRES) and movie identification (ID) entity categories; (b) determining the attributes and relationships between each entity category, and defining the value range and constraint conditions of each attribute; (c) using the designed ontology rules to guide the instantiation of entities and relationships in the subsequent data layer.
4. The method of claim 1, wherein, The translation distance model is implemented using an improved TransH model. In the training process of the improved TransH model, the negative sample generation strategy is optimized by using the following steps: (a) According to the four types of relationships existing in the graph, the entities in the movie field are clustered by the k-means clustering method according to the relationship type, and the clustering number is fixed at 4; (b) When generating negative triplets, select entities of different categories from the current positive relationship as replacement objects for the head entity or tail entity to improve the accuracy of negative sample generation and reduce the risk of introducing false labels.
5. The method of claim 1, wherein, Step S103 comprises: (a) Designing the system architecture according to the requirements of the movie recommendation system, which is divided into construction module, improvement module and implementation module; (b) Designing and implementing the movie management, graph display, movie search, movie relationship query, user evaluation and movie recommendation function modules, and realizing the visual recommendation result display in the system.
6. The method of claim 1, wherein, The method further comprises evaluating the recommendation performance of the mixed recommendation model, and the evaluation step comprises: (a) Quantifying the model recommendation effect by using hit rate (Hit@N), mean rank (Meanrank), precision, recall and F1 value indicators; (b) Evaluating the error between the model predicted score and the true score by using mean absolute error (MAE), and determining the best fusion parameter and the stability of the mixed model through comparative experiments.
Citation Information
Patent Citations
Personalized intelligent clothes matching recommendation method combined with knowledge graph
CN112612973A