Biểu đồ tần suất (Histogram)

Phân tích dữ liệu kinh doanh bằng SQL

Michel Semaan

Data Scientist

Tổng quan về histogram

Histogram: Hiển thị tần suất của từng giá trị trong dữ liệu

Bảng tần suất

orders  users
------  -----
1       7
2       42
3       65
...     ...

Histogram số đơn theo người dùng

Phân tích dữ liệu kinh doanh bằng SQL

Histogram - truy vấn (I)

WITH user_orders AS (
  SELECT
    user_id,
    COUNT(DISTINCT order_id) AS orders
  FROM meals
  JOIN orders ON meals.meal_id = orders.meal_id
  GROUP BY user_id)

SELECT orders, COUNT(DISTINCT user_id) AS users FROM user_orders GROUP BY orders ORDER BY orders ASC;
Phân tích dữ liệu kinh doanh bằng SQL

Histogram - truy vấn (II)

WITH user_revenues AS (
  SELECT
    user_id,
    SUM(meal_price * order_quantity) AS revenue
  FROM meals
  JOIN orders ON meals.meal_id = orders.meal_id
  GROUP BY user_id)

SELECT ROUND(revenue :: NUMERIC, -2) AS revenue_100, COUNT(DISTINCT user_id) AS users FROM user_revenues GROUP BY revenue_100 ORDER BY revenue_100 ASC;
Phân tích dữ liệu kinh doanh bằng SQL

Vẽ histogram

Microsoft Excel

Google Sheets

matplotlib

ggplot2

Phân tích dữ liệu kinh doanh bằng SQL

Histogram cho biết điều gì?

Histogram hình chữ U

Histogram hình chữ U

  • Nhiều người dùng tạo doanh thu thấp và cao; ít người ở mức trung vị

Histogram chuẩn

Histogram chuẩn

  • Nhiều người dùng ở mức doanh thu trung vị; ít người ở mức thấp hoặc cao
Phân tích dữ liệu kinh doanh bằng SQL

Biểu đồ tần suất (Histogram)

Phân tích dữ liệu kinh doanh bằng SQL

Preparing Video For Download...