Skip to content

πŸ“š A collaborative filtering-based book recommendation system using KNN algorithm. Built with Python, Streamlit, and scikit-learn. Discover your next favorite book! πŸš€

License

Notifications You must be signed in to change notification settings

vineet416/Books_Recommender_System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š Books Recommender System

A collaborative filtering-based book recommendation system built with Python and Streamlit. This application uses K-Nearest Neighbors (KNN) algorithm to suggest books similar to a user's selection based on user ratings data.

πŸ”— Live Demo: https://books-recommender-system-vineet416.streamlit.app/

Python Streamlit scikit-learn

🎯 Features

  • Collaborative Filtering: Recommendations based on user rating patterns
  • Interactive UI: Clean and intuitive Streamlit interface
  • Visual Recommendations: Displays book covers for recommended titles
  • Real-time Suggestions: Get 5 book recommendations instantly
  • Large Dataset: Trained on Book-Crossing dataset with thousands of books and ratings

πŸ› οΈ Technologies Used

  • Python 3.8+
  • Streamlit - Web application framework
  • NumPy - Numerical computing
  • Pandas - Data manipulation and analysis
  • Scikit-learn - Machine learning (KNN algorithm)
  • Pickle - Model serialization

πŸ“ Project Structure

Books Recommender Project/
β”‚
β”œβ”€β”€ app.py                      # Main Streamlit application
β”œβ”€β”€ research.ipynb              # Jupyter notebook for EDA and model training
β”œβ”€β”€ requirements.txt            # Project dependencies
β”‚
β”œβ”€β”€ artifacts/                  # Serialized models and data
β”‚   β”œβ”€β”€ model.pkl              # Trained KNN model
β”‚   β”œβ”€β”€ book_names.pkl         # List of book titles
β”‚   β”œβ”€β”€ book_pivot.pkl         # Pivot table of user-book ratings
β”‚   └── final_rating.pkl       # Processed ratings with metadata
β”‚
β”œβ”€β”€ Datasets/                   # Raw datasets (Book-Crossing)
β”‚   β”œβ”€β”€ BX-Books.csv           # Book information
β”‚   β”œβ”€β”€ BX-Users.csv           # User information
β”‚   └── BX-Book-Ratings.csv    # User ratings
β”‚
└── env/                        # Virtual environment (not tracked in git)

πŸš€ Getting Started

Prerequisites

  • Python 3.8 or higher
  • pip package manager

Installation

  1. Clone the repository

    git clone https://github.com/vineet416/Books_Recommender_System.git
    cd "Books Recommender Project"
  2. Create a virtual environment (recommended)

    conda create -n env python=3.11
    conda activate env/
  3. Install dependencies

    pip install -r requirements.txt
  4. Ensure artifacts folder exists Make sure the artifacts/ folder contains all the required pickle files:

    • model.pkl
    • book_names.pkl
    • book_pivot.pkl
    • final_rating.pkl

Running the Application

  1. Start the Streamlit app

    streamlit run app.py
  2. Open your browser The application will automatically open in your default browser at http://localhost:8501

  3. Use the application

    • Select a book from the dropdown menu
    • Click "Show Recommendation"
    • View 5 similar book recommendations with cover images

πŸ“Š How It Works

Collaborative Filtering Approach

  1. Data Preprocessing:

    • Loads Book-Crossing dataset containing books, users, and ratings
    • Filters users with significant rating history
    • Filters popular books with sufficient ratings
    • Creates a user-book rating matrix
  2. Model Training:

    • Uses K-Nearest Neighbors (KNN) algorithm
    • Calculates similarity between books based on user rating patterns
    • Books rated similarly by the same users are considered similar
  3. Recommendation Generation:

    • Takes a selected book as input
    • Finds the 6 nearest neighbors (including the input book)
    • Returns 5 most similar books with cover images

Algorithm Details

  • Algorithm: K-Nearest Neighbors (KNN)
  • Similarity Metric: Cosine similarity / Euclidean distance
  • Number of Neighbors: 6 (returns 5 recommendations)
  • Approach: User-Item Collaborative Filtering

πŸ“ˆ Dataset

The project uses the Book-Crossing Dataset, which contains:

  • Books: 271,360 books with metadata (ISBN, title, author, publisher, etc.)
  • Users: 278,858 users (anonymized)
  • Ratings: 1,149,780 ratings (scale 0-10)

Dataset Source: Book Recommendation Dataset on Kaggle

Original Source: Book-Crossing dataset collected by Cai-Nicolas Ziegler

πŸ”§ Model Training

To retrain the model or explore the data analysis process:

  1. Open research.ipynb in Jupyter Notebook or VS Code
  2. Run all cells sequentially
  3. The notebook will:
    • Load and explore the datasets
    • Perform data cleaning and preprocessing
    • Create the user-item matrix
    • Train the KNN model
    • Save artifacts to the artifacts/ folder

πŸ“ Key Functions

recommend_book(book_name)

  • Input: Book title (string)
  • Output: List of recommended books and their poster URLs
  • Process: Finds nearest neighbors using KNN model

fetch_poster(suggestion)

  • Input: Book indices from KNN suggestions
  • Output: List of poster/cover image URLs
  • Process: Maps book indices to image URLs from dataset

🎨 User Interface

The Streamlit interface includes:

  • Clean header with emoji icon
  • Descriptive subtitle and methodology info
  • Searchable dropdown for book selection
  • Recommendation button
  • 5-column grid layout for displaying results
  • Book titles and cover images for each recommendation
  • Error handling with user-friendly messages

🀝 Contributing

Contributions are welcome! Here are some ways you can contribute:

  • Report bugs and issues
  • Suggest new features or improvements
  • Improve documentation
  • Add new recommendation algorithms
  • Enhance the UI/UX

πŸ“„ License

This project is open-source and available for educational purposes.

πŸ™ Acknowledgments

  • Book-Crossing Dataset - For providing the comprehensive books and ratings data
  • Streamlit - For the excellent web framework
  • Scikit-learn - For machine learning tools

οΏ½ Author

Vineet Patel

πŸ“§ Contact

For questions or feedback, please open an issue in the repository or reach out via email.


Note: Make sure to have all pickle files generated before running the app. Run the research.ipynb notebook first to generate these files if they don't exist.


⭐ If you found this project helpful, please give it a star!

About

πŸ“š A collaborative filtering-based book recommendation system using KNN algorithm. Built with Python, Streamlit, and scikit-learn. Discover your next favorite book! πŸš€

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published