A data science project that builds and compares multiple recommendation algorithms to predict product ratings and recommend electronics to customers based on historical rating data from Amazon.
This project implements and evaluates multiple recommendation system approaches on the Amazon Electronics dataset:
- Rank-Based Recommendations - Simple popularity-based approach
- Collaborative Filtering (Similarity-Based)
- User-User Similarity
- Item-Item Similarity
- Matrix Factorization (SVD) - Model-based approach
The goal is to identify the most effective recommendation algorithm for predicting which products users will rate highly.
- Source: Amazon Electronics reviews dataset
- Original Size: 7,824,482 ratings
- Processed Size: 65,290 ratings
- Features:
user_id: Unique identifier for each userprod_id: Unique identifier for each productrating: User rating (1-5 scale)timestamp: When the rating was given (not used in modeling)
Data Filtering Criteria:
- Users with at least 50 ratings
- Products with at least 5 ratings
- Final dataset: 1,540 unique users and 5,689 unique products
| Model | RMSE | Precision | Recall | F1-Score |
|---|---|---|---|---|
| Rank-Based | N/A | N/A | N/A | N/A |
| User-User Similarity (Baseline) | 1.0260 | 0.844 | 0.862 | 0.853 |
| User-User Similarity (Tuned) | 0.9760 | 0.834 | 0.897 | 0.864 |
| Item-Item Similarity (Baseline) | 1.0147 | 0.826 | 0.853 | 0.839 |
| Item-Item Similarity (Tuned) | 0.9751 | 0.829 | 0.892 | 0.859 |
| SVD (Baseline) | 0.9104 | 0.837 | 0.880 | 0.858 |
| SVD (Tuned) | 0.9014 | 0.841 | 0.880 | 0.860 |
The tuned SVD (Singular Value Decomposition) model achieved the best results:
- Lowest RMSE: 0.9014
- Strong balance between precision (84.1%) and recall (88.0%)
- Best F1-score: 0.860
Optimal Hyperparameters:
- n_epochs: 20
- lr_all: 0.01
- reg_all: 0.2
- Analyzed rating distribution (heavily skewed toward 5-star ratings)
- Applied filtering to ensure sufficient data density
- Identified data quality (no missing values after filtering)
- Calculated average ratings and review counts per product
- Recommended top products by popularity with minimum interaction threshold
- Baseline approach for comparison
- User-User: Finds similar users using cosine/MSD similarity
- Item-Item: Finds similar products
- Used KNNBasic algorithm with hyperparameter tuning
- Best parameters: k=30, min_k=6
- Decomposes user-item rating matrix into latent features
- Model-based approach more scalable than similarity-based
- Tuned through grid search over learning rates, epochs, and regularization
- Metrics: RMSE, Precision@10, Recall@10, F1-Score
- Rating threshold: 3.5 (ratings ≥ 3.5 considered relevant)
- Top-k recommendations: 10 products per user
-
Rating Bias: Dataset has significant imbalance with many 5-star ratings, which influences model predictions
-
Model Comparison:
- Matrix factorization (SVD) outperforms similarity-based approaches
- Item-item similarity performs better than user-user for known ratings
- Tuning hyperparameters improves recall significantly
-
Prediction Accuracy:
- Models tend to underestimate actual ratings for known user-product pairs
- For new user-product combinations, predictions are more conservative
Amazon_Electronics_Recommendation_Systems.ipynb- Main Jupyter notebook with all analyses and modelsAmazonProductRecommendation.html- HTML report/output from notebookREADME.md- This file
- Python 3.7+
- pandas
- numpy
- scikit-learn
- surprise (scikit-surprise)
- matplotlib
- seaborn
pip install pandas numpy scikit-learn scikit-surprise matplotlib seabornNote: For best results with the surprise library, use Google Colab or ensure numpy version compatibility:
pip uninstall numpy -y
pip install "numpy<2" --force-reinstall- Mount Google Drive (for Colab):
from google.colab import drive
drive.mount('/content/drive')- Load the notebook and run cells sequentially
- Modify user IDs and product IDs to generate custom recommendations
# Get top 5 product recommendations for a user
recommendations = get_recommendations(df_final, 'A3LDPF5FMB782Z', 5, svd_optimized)
print(recommendations) # Returns list of (product_id, predicted_rating) tuples- Hybrid Approach: Combine SVD with content-based filtering using product features
- Cold-Start Problem: Implement strategies for new users/products with limited data
- Deep Learning: Explore neural network-based approaches (autoencoders, RNNs)
- Class Imbalance: Address the skew toward 5-star ratings using techniques like SMOTE
- Time-Based Features: Incorporate temporal patterns in rating behavior
- A/B Testing: Validate models in production with real user engagement metrics
Dereck Duran
This project is for educational purposes.