A sophisticated product recommendation system that combines multiple AI approaches for personalized recommendations, including real Neural Collaborative Filtering (NCF) training.
- Neural Collaborative Filtering (NCF): Deep learning-based collaborative filtering using PyTorch, trained on your user interactions.
- Content-based Recommendations: Uses BERT for text and CNN for image features.
- Graph-based Recommendations: Knowledge graph with user-product interactions.
- Time-aware Recommendations: Considers temporal patterns in user behavior.
- Hybrid Recommendation Approach: Combines all the above for robust, explainable recommendations.
- REST API: Easily integrate with any frontend or tool (e.g., Postman).
- Robust Data Handling: Works with or without timestamps in your interaction data.
prodo/
├── advanced_models.py # Core AI models (NCF, content, graph, time-aware, hybrid)
├── app.py # Flask API endpoints
├── requirements.txt # Project dependencies
├── data/ # Data directory
│ ├── products.csv # Product information
│ ├── users.csv # User information
│ └── user_interactions.csv # User interaction data
├── models/ # Directory for trained models (optional)
├── utils.py # Utility functions
├── test_utils.py # Test scripts
├── test_recommendation_model.py
├── test_data_preprocessing.py
├── data_preprocessing.py
└── README.md
-
Clone the repository:
git clone <your-repo-url> cd prodo
-
Install dependencies:
pip install -r requirements.txt
-
Download spaCy model:
python -m spacy download en_core_web_sm
-
(Optional) Download BERT weights and ResNet weights:
These will be automatically downloaded the first time you run the app. -
Prepare your data:
Place your CSV files in thedata/directory. See below for format. -
Run the application:
python app.py
The API will be available at
http://127.0.0.1:5000/
| product_id | name | description | category | price | image_url |
|---|---|---|---|---|---|
| 101 | Smart Watch Pro | Advanced fitness tracking smartwatch | Electronics | 199.99 | https://example.com/watch.jpg |
| user_id | name | age | preferences | location |
|---|---|---|---|---|
| 1 | John Doe | 28 | Electronics,Gaming | New York |
| user_id | product_id | clicks | rating | (timestamp, optional) |
|---|---|---|---|---|
| 1 | 101 | 5 | 4 | 1718246400 |
timestampis optional. If present, enables time-aware recommendations.
Get personalized recommendations for a user.
-
Request:
- Headers:
Content-Type: application/json - Body:
{ "user_id": 1, "context": {}, "top_n": 5 }user_id: The user to recommend for.context: (optional) Dictionary with context (e.g., time, location).top_n: (optional) Number of recommendations (default: 5).
- Headers:
-
Response:
{ "user_id": 1, "recommendations": [ { "product_id": 101, "score": 0.92, "explanation": "Recommended based on your preferences and behavior patterns (confidence: 0.92)" } ], "context_used": { ... } }
- Set method to
POSTand URL tohttp://127.0.0.1:5000/recommend - In the Headers tab, add:
- Key:
Content-Type - Value:
application/json
- Key:
- In the Body tab, select
rawand chooseJSONfrom the dropdown. - Paste the example JSON above and click Send.
Retrain all models (including NCF) on the latest data.
- Request: No body required.
- Response:
{ "message": "Models retrained successfully" }
- The NCF model is trained automatically on startup and whenever you POST to
/train. - Training progress and loss will be shown in the terminal.
- The system is robust to missing columns (e.g.,
timestamp).
- For best results, use real user interaction data with ratings.
- The project is for educational/demo purposes. For production, use a WSGI server and secure your endpoints.
- You can extend the system with more advanced models or data as needed.
MIT (or your chosen license)
For questions or contributions, open an issue or pull request on GitHub.