This is a Streamlit web application that provides book recommendations based on genres using machine learning techniques. The app utilizes the CountVectorizer from Scikit-learn to convert genres into numerical vectors and then uses cosine similarity to recommend books that are similar to the selected book.
- Book Recommendations: Select a book, and the app will recommend the top 5 books based on the genre similarity.
- Cosine Similarity: The app uses cosine similarity to find books with the closest genre matches.
- Integrated Dataset: The app comes with a pre-loaded CSV file (
books.csv
) containing book titles and genres.
You can see a working demo of the app below:
- The user selects a book title from the dropdown list.
- The app computes similarity between the selected book and all other books based on their genres.
- It recommends the top 5 books that are most similar to the selected one.
The app uses a CSV file named books.csv
that contains the following columns:
- Title: The title of the book.
- Genre: The genre of the book.
Sample data format:
Title | Genre |
---|---|
Harry Potter and the Sorcerer's Stone | Fantasy |
The Hobbit | Fantasy |
The Da Vinci Code | Mystery |
A Brief History of Time | Science |
- Streamlit: For the web interface.
- Pandas: To handle data loading and manipulation.
- Scikit-learn: To compute cosine similarity using
CountVectorizer
.
Follow these steps to set up the app locally:
-
Clone the repository:
git clone https://github.com/your-repo/book-recommendation-app.git cd book-recommendation-app
-
Install the required packages: Make sure you have Python installed, then run:
pip install -r requirements.txt
-
Run the app:
streamlit run app.py
-
Access the app: Once the app is running, open your browser and go to
http://localhost:8501/
.
The app uses CountVectorizer to convert the 'Genre' column into a vector matrix and calculates the similarity scores using cosine similarity. The top 5 books with the highest similarity scores are then displayed as recommendations.
get_index_from_title(title)
: Finds the index of a book by its title.get_title_from_index(index)
: Returns the title of a book from its index.cosine_similarity
: Computes the similarity between all books based on their genres.
- app.py: The main application code.
- books.csv: The dataset with book titles and genres.
- requirements.txt: The list of required packages.
- README.md: This documentation file.
- Selected Book: Harry Potter and the Sorcerer's Stone
- Recommended Books:
- The Hobbit (Score: 0.89)
- The Fellowship of the Ring (Score: 0.87)
- Eragon (Score: 0.86)
- The Chronicles of Narnia (Score: 0.85)
- The Golden Compass (Score: 0.83)
This project is licensed under the MIT License. See the LICENSE file for details.
Let me know if you'd like to add any additional details!