Product Recommender is a Python-based recommendation system that suggests products to users based on their onchain data. It uses TF-IDF vectorization and cosine similarity to calculate the similarity between user profiles and product descriptions.
- Machine Learning
- Recommendation Systems
- Natural Language Processing
- Load and preprocess product data from a CSV file.
- Clean and combine product text data for analysis.
- Infer activity categories from product descriptions.
- Define user profiles based on their onchain data.
- Compute cosine similarity between user profiles and product descriptions.
- Recommend products to users based on a minimum similarity threshold.
- Python 3.x
- gdown
- pandas
- numpy
- scikit-learn
- psycopg2-binary
- re
- Clone the repository:
git clone https://github.com/gonzalomelov/product-recommender.git
- Navigate to the project directory:
cd product-recommender
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
- Install the required Python packages:
pip install -r requirements.txt
- Download the product data file from Google Drive using
gdown
and load it into a pandas DataFrame. - Clean and preprocess the product data.
- Define user profiles with details from their onchain data.
- Compute cosine similarity between user profiles and product descriptions.
- Recommend products based on a specified similarity threshold.
Here is a sample code snippet demonstrating how to use the Product Recommender:
# Jupyter Notebook: Product Recommendation System
# Importing necessary libraries
# Install gdown if not already installed
!pip install gdown
import pandas as pd
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
import re
# Step 1: Load and inspect data
import gdown
# Download the product data file from Google Drive
product_file_id = 'your_file_id' # Replace with your actual file ID
product_url = f'https://drive.google.com/uc?id={product_file_id}'
product_output = 'products_export_1.csv'
gdown.download(product_url, product_output, quiet=False)
# Load the data from CSV
product_df = pd.read_csv('products_export_1.csv')
# Step 2: Prepare data for analysis
# ... (rest of the code from the provided notebook) ...
# Step 6: Recommend products
# Set a threshold for similarity
similarity_threshold = 0.25 # Adjust this value as needed
# Recommend products based on highest similarity
for i, user in enumerate(users):
print(f"Recommendations for User {i+1}:")
user_similarities = similarities[i]
# Sort product indices by similarity score (descending order)
sorted_indices = np.argsort(user_similarities)[::-1]
for idx in sorted_indices:
similarity_score = user_similarities[idx]
if similarity_score >= similarity_threshold: # Only recommend if above threshold
product = product_data.iloc[idx]
print(f"- {product['Title']} (Similarity Score: {similarity_score:.2f})")
print()
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.
For questions or feedback, please contact [email protected].