This Flask-based Anime/Manga recommendation system utilizes an IR similarity algorithm to provide personalized suggestions based on user preferences, including descriptions, ratings, interactions, and viewing history. Built with Flask, it features document search, ranking, spell correction, and user feedback, offering Anime/Manga enthusiasts a comprehensive platform for seamless content discovery.
This web application serves as an information retrieval system for Anime/Manga recommendations, integrating features that enable users to input their preferences and receive personalized suggestions. The system leverages an Information Retrieval (IR) similarity algorithm to match user preferences with Anime/Manga in the dataset. Recommendations are generated based on various factors, including anime/manga descriptions, ratings, user interactions, and the user's viewing history.
Built with Flask, the application also incorporates functionalities such as document search and ranking, spell correction for user queries, and a user feedback system. Users can explore and interact with the system through a web-based interface.
This integration offers a comprehensive platform for Anime/Manga enthusiasts, providing a seamless experience for discovering new content tailored to their tastes. Whether users are seeking recommendations based on descriptions, ratings, or personal viewing history, the system aims to enhance the overall Anime/Manga discovery process.
- Clone the repository :
git clone https://github.com/ReyKan-KP/Anime-Manga-Recommendation-System-Using-IR.git
- Install dependencies :
pip install -r requirements.txt
- Run main.py :
python main.py runserver
- Open index.html:
Click on http://127.0.0.1:5000 (as shown in terminal)
- Execute the script and follow the link to access the Anime/Manga Recommendation page.
- Specify your user status:
- If you're an existing user,Select Yes and provide your User ID (greater than 1).
- If you're a guest,Select No then the User ID is set to 1.
- Based on your input, you can:
- Enter the description of the Anime/Manga you wish to explore.
- Receive recommendations based on the previous user's watched or read list (weighted terms of the user watch or read document are considered, and cosine similarity is calculated based on the resulting weight index).
- Enter the Page Number and click submit.
- Review the ranking determined by the combined score (cosine similarity + normalized evaluation).
- Normalized evaluation is calculated as (evaluation/totalDocs) * 100, where evaluation is the product of feedback and rating.
- In the feedback box, enter relevant document IDs following the provided instructions.
- Upon submitting feedback, the feedback count for the specified document ID will increment by 1, and the normalized evaluation will be updated in the dataset.
- For the Assessment of the IR system, a PR curve and an 11-point interpolated precision graph will be displayed for the top 10 documents based on the relevance document entered by the user in the feedback box.
- For a new query or recommendation, reload the page.
-
-
main.csv
- This CSV file contains a list of 87,316 anime/manga entries.
- Path:
main dataset/main.csv
- Columns:
ID, Title, Description, Rating, Feedback, Evaluation, Normalized Evaluation
-
user_profiles.csv
- This CSV file contains a list of 75,989 user profiles.
- Path:
main dataset/user_profiles.csv
- Columns:
User ID, Profile, Watch or Read
-
-
- Lowercasing:
- Converts all text to lowercase to ensure consistency and avoid case-sensitive discrepancies.
- Tokenization:
- Breaks down sentences or paragraphs into individual words or tokens, essential for text-based analysis.
- Stopwords Removal:
- Removes common words (stopwords) that do not contribute significantly to the meaning of the text, reducing noise in the data.
- Stemming:
- Reduces words to their base or root form, grouping together words derived from the same root, even with different inflections or suffixes.
- Lowercasing:
-
-
Index File Format:
- Path:
index.txt
- The index file is a
.txt
file storing term information in the format:term - (doc_id, term_frequency)
.
- Path:
-
Indexer Function:
- The
makeIndex()
function is crucial for indexing anime/manga descriptions, processing each description and creating entries in the index file.
- The
-
Index Loading:
- At runtime, the program loads the
index.txt
file to access the pre-built index.
- At runtime, the program loads the
-
makeIndexMap() Function:
- The
makeIndexMap()
function generates a dictionary containing term, doc_ID, and frequency without reading the entire document.
- The
-
-
-
Types of Search:
- Query Search:
- Involves searching based on user-provided queries.
- Recommendation Search:
- Provides recommendations based on the user's watch/read history.
- Query Search:
-
Term Frequency Calculation:
- Term frequency is calculated using the formula:
1 + log2(tf)
.
- Term frequency is calculated using the formula:
-
Inverse Document Frequency Calculation:
- Inverse Document Frequency (IDF) is calculated as:
1 + log2(total_Doc/Doc_freq)
.
- Inverse Document Frequency (IDF) is calculated as:
-
Weight Index:
- The weight index for each term is determined by multiplying the term frequency (tf) and inverse document frequency (idf):
tf * idf
.
- The weight index for each term is determined by multiplying the term frequency (tf) and inverse document frequency (idf):
-
Recommendation Search Workflow:
- User Watch/Read History:
- The system gathers the watch/read history of the user.
- Weight Index Calculation:
- Calculates the weight index of each document that the user has watched/read.
- Query Weight Index:
- Obtains the query weight index by summing the weight indices of the user's watch/read history.
- Cosine Similarity:
- Calculates cosine similarity to determine the similarity between each document's weight index and the query weight index.
- User Watch/Read History:
-
Cosine Similarity:
- Measures the cosine of the angle between two vectors, providing a similarity score.
-
Search Optimization:
- Utilizes weighted indices, term frequency, and inverse document frequency for accurate and relevant search results.
- Cosine similarity ensures efficient comparison and ranking of documents based on their relevance.
-
Result Presentation:
- Presents search results in a ranked order, with higher cosine similarity scores indicating higher relevance.
-
-
- The
correct_spelling
function is a spell checker designed to identify and correct misspelled words in a given query. - Library Used: The function utilizes the
enchant
library, specifically the English (U.S.) dictionary, to check word spelling. - Input: Accepts a query (text) string as input.
- Processing:
- Splits the input query into individual words.
- Checks if each word is misspelled using the
enchant
dictionary. - If misspelled, suggests a correction using the first suggestion from the dictionary.
- Assembles corrected words into a new query string.
- Output: Returns the corrected query.
- The
-
- Feedback IDs Extraction:
- The system accepts a list of feedback IDs from the user, obtained from the JSON payload using
request.json.get('feedbackIDs', [])
.
- The system accepts a list of feedback IDs from the user, obtained from the JSON payload using
- Feedback Function:
- The
feedback()
function processes received feedback IDs, updating the dataset by incrementing feedback count, recalculating evaluation based on rating, and computing normalized evaluation. The updated dataset is saved to 'main dataset/main.csv', and feedback IDs are printed for confirmation.
- The
- Normalized Evaluation Map:
- The function retrieves the normalized evaluation map using the
getNormalizedEvaluation
function from the 'preprocessingAndIndexing' module.
- The function retrieves the normalized evaluation map using the
- By incorporating this feedback component, the system allows users to provide feedback on specific IDs, updating the dataset for continuous improvement in recommendations or search results.
- Feedback IDs Extraction:
-
- Precision-Recall Curve Generation:
- The
PRcurve
module generates Precision-Recall curves to evaluate the performance of the Information Retrieval (IR) system.
- The
- PRcurve Function:
- Takes parameters including total_docs, relevant_docs_id, and top_10 to calculate precision and recall at each rank in the top 10. Interpolation is applied, and the resulting curve is plotted using Matplotlib.
- Workflow:
- Relevance Annotation:
- Determines the relevance of each document in the top 10 based on provided relevant document IDs.
- Precision and Recall Calculation:
- Calculates precision and recall at each rank, providing insights into system performance.
- Interpolation:
- Interpolates precision values at 11 recall levels, producing a smooth Precision-Recall curve.
- Curve Plotting:
- Plots the Precision-Recall curve for visualization.
- Relevance Annotation:
- Result Interpretation:
- Precision and recall values breakdown the performance at each rank in the top 10.
- Interpolated precision values offer a comprehensive view of the system's behavior across different recall levels, aiding in evaluation and comparison of retrieval strategies.
- Precision-Recall Curve Generation:
-
The UI component of the Anime/Manga Recommendation System employs Flask, HTML, CSS, and JavaScript for an interactive user experience. Key elements include a spell checker, Flask routes for processing user input and feedback, HTML templates, and JavaScript for user interactions.
-
Components
-
Spell Checker :
- The
correct_spelling
function corrects misspelled words using theenchant
library.
- The
-
Flask Routes :
/
: Renders the main HTML page./process_user_input
: Processes user queries and recommendations./process_feedback_input
: Handles user feedback.
-
HTML Templates :
- The main template (
index.html
) defines the UI structure, including forms, loading indicators, and result containers.
- The main template (
-
JavaScript Interaction:
- JavaScript functions handle user interactions like user type selection, entering IDs, and form submissions.
-
-
User Interaction Workflow
-
User Type Selection:
- Users choose existing or guest status.
-
User ID and Options:
- For existing users, ID entry and dynamic options for query or recommendations are provided.
-
Query and Page Input:
- Users enter queries or page numbers.
-
Search Execution:
- Clicking search triggers Flask to process input and display results.
-
Feedback Submission:
- Users can submit feedback, updating the system dataset.
-
-
Loading and Feedback
- Loading indicators signal ongoing processes.
- Feedback prompts are presented after search results for user contribution.
-
-
Data collection for comprehensive content coverage.
-
Preprocessing for data optimization
-
Indexing for efficient data retrieval.
-
Document search and ranking.
- Search based on user query.
- Recommendation based on user's previous watch or read history.
-
Spell correction for user queries.
-
User feedback handling.
-
Assessment Evaluation with PR Curve.
-
Web-based interface using Flask.
We welcome contributions from the community! If you'd like to contribute to this project, here's how:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature-name
). - Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/your-feature-name
). - Open a Pull Request.
This project is licensed under the MIT License.
- Make sure to have the necessary CSV files ('main dataset\main.csv' and 'main dataset\user_profiles.csv') in the specified directory for data retrieval.
This README provides an overview of the Anime Recommendation System. For more details on the code and functionality, please refer to the code comments and documentation within the script.