Product Performance Analysis System

Flask-based product performance analyzer that evaluates sales data using KMeans clustering and weighted scoring (revenue, stock efficiency, sales velocity) to classify products into High/Medium/Low tiers. Features: Automated feature engineering, MinMax normalization, model persistence, and comprehensive performance insights.

Product Performance Analysis System

1. Introduction

1.1 System Overview

This Flask-based product analysis API evaluates product performance using clustering and scoring algorithms. It processes sales data to:

  • Calculate key performance metrics (revenue, stock efficiency, sales velocity)
  • Assign performance scores (0-100 scale)
  • Classify products into performance tiers (Low/Medium/High)

1.2 Key Features

  • Automated feature engineering
  • MinMax normalization for fair comparison
  • KMeans clustering for performance tiering
  • Weighted scoring system
  • Model persistence with Joblib

2. Technical Implementation

2.1 Data Flow

graph TD
    A[Raw Product Data] --> B[Feature Engineering]
    B --> C[Normalization]
    C --> D[Scoring]
    D --> E[Clustering]
    E --> F[API Response]

2.2 Core Algorithms

Component Technology Purpose
Feature Engineering Pandas Calculate revenue, stock ratio, sales velocity
Normalization MinMaxScaler Scale features to [0,1] range
Clustering KMeans (k=3) Performance tier classification

3. API Documentation

3.1 Endpoint

POST /product-analysis

3.2 Request Format

[
  {
    "product_id": 101,
    "name": "Premium Headphones",
    "price": 199.99,
    "units_sold": 150,
    "stock": 50
  },
  ...
]

3.3 Response Format

{
  "status": "success",
  "data": [
    {
      "product_id": 101,
      "name": "Premium Headphones",
      "performance_score": 85.2,
      "performance_tier": "High",
      "revenue": 29998.50,
      ...
    }
  ],
  "summary": {
    "avg_score": 72.4,
    "top_product": "Premium Headphones",
    "total_revenue": 125499.00
  }
}

4. Scoring Methodology

4.1 Feature Weights

  • Revenue (50%): price × units_sold
  • Stock Ratio (30%): units_sold / (stock + units_sold)
  • Sales Velocity (20%): units_sold / price

4.2 Performance Tiers

  • High: Top 20% of products
  • Medium: Middle 60%
  • Low: Bottom 20%

5. Business Applications

  • Inventory optimization decisions
  • Product portfolio analysis
  • Marketing campaign targeting
  • Supplier performance evaluation

6. Deployment

# Sample Dockerfile
FROM python:3.9
RUN pip install flask pandas scikit-learn
COPY . /app
WORKDIR /app
CMD ["flask", "run", "--host=0.0.0.0"]

7. Future Enhancements

  • Time-series analysis for trend detection
  • Integration with visualization dashboards
  • Automated report generation

GitHub Repository

đź”— https://github.com/skarnov/flask-bi

Author

Shaik Obydullah

Published on July 5, 2024