Data Segmentation Doesn't Hurt: Applying ML Models in Analytics

Mark (mark_mer)21 Jan 2025

Problem

Sravni analysts needed to know which user attributes (gender, age, marital status, job) affect one product metric the most. The classic routes are slow. Checking one variable at a time through queries and dashboards is slow. Grouping by many attributes at once gives many small segments that someone then compresses by hand. Both break down on numeric fields (where to cut age), on granular categories (how to merge cities) and whenever the stakeholder asks for another metric, which restarts the work.

Example from the article: a segmentation of users by age, gender, education and other fields against a target metric (called MTR), with at most 7 segments.

Solution in brief

Sravni built a small Streamlit dashboard that fits a scikit-learn decision tree on the chosen metric. The tree finds age intervals and category groups on its own and ranks features by their contribution. Filters and chart widgets feel like a BI tool, and the dashboard can be shared with colleagues or business stakeholders.

Questions this case answers
  • How to find which customer attributes drive a metric and form a few representative segments when manual grouping across many attributes is too slow
  • How to give analysts a shareable self-service dashboard that runs a supervised model when the BI tool cannot integrate ML algorithms
  • How to find which customer attributes drive a product metric without manual segmentation
  • How to split a numeric field such as age into optimal intervals for a metric

Tools and methods

  • Decision tree (scikit-learn) — supervised segmentation of users in the context of a target metric
  • Streamlit — web UI with filters and selectors, dashboards written as Python code
  • Polars — filtering, grouping and aggregation before the model, lazy reads from parquet
  • Plotly — charts, integrated with Streamlit
  • DuckDB — considered as an alternative to Polars, not used
Continue reading — it's free

Google or a one-time email code. No password.