In this project, I created a content-based recommendation engine that suggests similar mobile phones based on technical specifications like camera, memory, processor, etc. It uses:
- 🐍 Python
- ✨ TF-IDF vectorization
- 🧠 K-Nearest Neighbors (KNN)
- 🌐 Flask web app
The system takes a product name and shows 3 similar phones with images.
I wanted to simulate a real-world feature found in eCommerce platforms like Amazon or Daraz:
“When a user views a product, show similar items they might also like.”
However, unlike a traditional eCommerce search engine, this is not just a keyword search.
Here’s how it works:
- You enter a product name (e.g., "Samsung Galaxy S21")
- The app matches that name to the most similar product in the dataset
- Then it finds 3 similar products based on technical specs
- These recommendations are not based on the keyword itself, but on the matched product
So, if you type "Apple", it won't just show all Apple phones. It will try to find the first matched phone containing "Apple" and then recommend phones similar to that one.
The dataset (mobiles.csv) contains:
names: product namesimages_links: image URLsmemory,camara_info,display,battery,processor: product specs
All relevant features were combined into a single string:
df['features'] = df['memory'] + ' ' + df['camara_info'] + ' ' + df['display'] + ' ' + df['battery'] + ' ' + df['processor']from sklearn.feature_extraction.text import TfidfVectorizer
vectorizer = TfidfVectorizer()
X = vectorizer.fit_transform(df['features'])from sklearn.neighbors import NearestNeighbors
knn = NearestNeighbors(n_neighbors=10, metric='cosine')
knn.fit(X)The input name is matched via keywords and then similar items are shown:
matches = df[df['names'].str.lower().apply(lambda name: all(k in name for k in input_name.lower().split()))]A simple HTML form allows you to enter a product name, and then it displays:
-
The selected product (based on keyword match)
-
Top 3 similar phones with names and images
@app.route('/', methods=['GET', 'POST'])
def recommend():
...Below is a sample output from the app:
Run Locally:
git clone https://github.com/your-username/product-recommender.git
cd product_recommender
pip install -r requirements.txt
python item_rec.pyThen open your browser and go to: http://127.0.0.1:5000/
-
Python
-
pandas
-
scikit-learn
-
Flask
-
HTML/CSS
-
How to use TF-IDF for text-based features
-
KNN can work surprisingly well for recommender systems
-
Flask is great for quickly prototyping ML apps
Insiya Fakhruddin – Aspiring AI Engineer
Feel free to ⭐ the repo or connect with me!
