A machine learning system that classifies products into categories based on their names and brands.
Takes a product name and brand, predicts which category it belongs to. Built with scikit-learn, PyTorch, and FastAPI.
Train the models:
pip install -r requirements.txt
python run_pipeline.pyStart the API:
python app.py
# Visit http://localhost:8000/docsMake a prediction:
curl -X POST "http://localhost:8000/classify" \
-H "Content-Type: application/json" \
-d '{"product_id": "123", "name": "Chanel No 5 Eau De Parfum", "brand": "Chanel"}'With Docker:
docker build -t product-classifier .
docker run -p 8000:8000 product-classifierβββ app.py # FastAPI application
βββ run_pipeline.py # Train models
βββ run_tests.py # Run tests
βββ src/ # ML code
βββ tests/ # Test suite
βββ data/ # Dataset
βββ models/ # Trained models
βββ images/ # Plots and visualizations
βββ docs/ # Additional documentation
Three models trained on product names and brands:
- Random Forest: 73% test accuracy (best performer)
- PyTorch Neural Network: 71% test accuracy
- Logistic Regression: 49% test accuracy (baseline)
The Random Forest model is used in the API.
GET /- API infoGET /health- Health checkPOST /classify- Classify a single productPOST /classify/batch- Classify multiple products
Interactive docs at http://localhost:8000/docs
python run_tests.py- scikit-learn, PyTorch
- FastAPI
- pandas, numpy
- Docker
The dataset is small (~180 training samples, 60 categories), which limits model performance. With more data, accuracy would improve significantly.
See docs/ folder for detailed documentation on the ML pipeline, API usage, and Docker deployment.