Skip to content

InsiyaFakhruddin/product_recommender

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📱 How I Built a Mobile Recommendation System using Python, scikit-learn, and Flask

🚀 Overview

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.


🔍 Problem Statement

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.


🗃️ Dataset

The dataset (mobiles.csv) contains:

  • names: product names
  • images_links: image URLs
  • memory, camara_info, display, battery, processor: product specs

🧠 Approach

1. Feature Engineering

All relevant features were combined into a single string:

df['features'] = df['memory'] + ' ' + df['camara_info'] + ' ' + df['display'] + ' ' + df['battery'] + ' ' + df['processor']

2. Vectorization with TF-IDF

from sklearn.feature_extraction.text import TfidfVectorizer

vectorizer = TfidfVectorizer()
X = vectorizer.fit_transform(df['features'])

3. Similarity with KNN

from sklearn.neighbors import NearestNeighbors

knn = NearestNeighbors(n_neighbors=10, metric='cosine')
knn.fit(X)

4. Query Handling

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()))]

💻 Flask App

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():
    ...

🖼️ System Output

Below is a sample output from the app:

Recommendation System Output

🔗 Try it Yourself

Run Locally:

git clone https://github.com/your-username/product-recommender.git
cd product_recommender
pip install -r requirements.txt
python item_rec.py

Then open your browser and go to: http://127.0.0.1:5000/

📚 Tech Stack

  • Python

  • pandas

  • scikit-learn

  • Flask

  • HTML/CSS

🧠 Lessons Learned

  • 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

👨‍💻 Author

Insiya Fakhruddin – Aspiring AI Engineer

Feel free to ⭐ the repo or connect with me!

Releases

No releases published

Packages

 
 
 

Contributors