SchoolWhool
Quizzes and saved progress, freeSign in freeSign in
Statistics · Module 1Module material

Descriptive statistics cheat sheet

How to describe a dataset and read its plots: what to fix before any statistic, which view answers which question, the formulas, the code and the gotchas. Free to read and share, no account needed.

Before any plot or statistic

  1. Name the unit of analysis: the thing counted once. One trip, one gross invoice (not one invoice line), one person, one client record.
  2. Declare the rows and rules first: filters, bin edges, bands, groups and thresholds are fixed before you read any result.
  3. Keep the count beside every shape: n for each group, and the numerator and denominator beside every rate.
  4. A display sample is for marks only: every count, quantile and coefficient uses all the declared rows.

Which view answers which question

questionuseread it as
How many observations fall in each numeric interval?count histogrambar height = count; state the bin width
What share falls in an interval of any width?density histogrambar area = fraction; height is per unit (per minute)
What smoothed shape do the values have?KDE, with a ruga smoothed estimate; its height is not a fraction
What fraction is at or below a value?empirical CDFread up from the value, across to the fraction
What value first reaches a fraction?ECDF first crossing, quantileread across from the fraction, down to the value
Where is the middle?medianresists one extreme value
What is the arithmetic average?meanuses every value; pulled by a long tail
Which exact value repeats most?mode (stated precision)may describe one repeated amount, not the bulk
How spread out is the whole group?sample SDin the original unit; sensitive to extreme values
How wide is the middle half?IQRresists the tail
How do several groups compare?box plots, violin plots, on one shared axisquartiles and flags from rows; violin outline is estimated
Do two numeric values move together in a straight line?scatter plot, then Pearson rone coefficient, not every pattern
How often does an outcome occur in each category?contingency table, then ratesrate = group events / group total
Where are paired values concentrated?hexbin joint plot with marginalsjoint shows pairs; marginals show one variable each
Which of many pairs deserves a closer look?pair plot and correlation heatmap on training rowsa candidate for a later check, not a proven feature
Who is in the rows at all?row shares beside published control totalsa row share describes rows, not the target population

Formulas, as the videos build them

quantityformulaModule 1 example
density of a bincount / (n × bin width)981 / (3,818 × 5) ≈ 0.0514 per minute; area 0.0514 × 5 ≈ 25.7%
ECDF at x(observations <= x) / nat 20 min: 2,937 / 3,818 = 76.9%
first-crossing rank for fraction qceil(q × n), then read that sorted value0.9 × 3,818 = 3,436.2 → rank 3,437 → 27.1833 min
meansum / ngross invoices: £534.40
medianmiddle sorted value, or mean of the two middle values(£303.83 + £303.84) / 2 → £303.84
deviationvalue − group meanthe signed deviations sum to zero
sample variancesum of squared deviations / (n − 1)UK: 3,174,016.18 pounds squared
sample SD√(sample variance)UK £1,781.58, Germany £608.92
IQRQ3 − Q1 (NumPy linear interpolation)UK £319.56, Germany £430.41
Tukey fencesQ1 − 1.5 × IQR and Q3 + 1.5 × IQRMidtown 09: -8.025 and 35.508 min
whisker endmost extreme recorded value inside the fences0.05 and 35.5 min; 121 flagged
covariancemean product of paired deviationsage and hours: 11.58
Pearson rcovariance / (SD of x × SD of y), between −1 and 1age and hours: 0.069 on 32,561 rows
rateevents in the group / records in the groupgraduate school 2,036 / 10,585 = 19.2%

The calls

edges5 = np.arange(0, 85, 5)                         # declare edges first
sns.histplot(data=trips, x="duration_min", bins=edges5, stat="count")
sns.histplot(data=trips, x="duration_min", bins=edges5, stat="density")
sns.kdeplot(data=trips, x="duration_min", bw_adjust=1)
sns.rugplot(data=rug_sample, x="duration_min")       # display sample only
sns.ecdfplot(data=trips, x="duration_min")
trips["duration_min"].le(20).mean()                  # fraction at or below 20
np.quantile(trips["duration_min"], 0.9)              # value at a fraction

invoices = lines.groupby("InvoiceNo")["line_value"].sum()   # lines -> invoices
invoices.mean(), invoices.median(), invoices.round(2).value_counts()
by_country.var(ddof=1), by_country.std(ddof=1)       # n - 1 denominator
np.quantile(values, [0.25, 0.75])

sns.boxplot(data=groups, x="group", y="duration_min")         # whis=1.5 default
sns.violinplot(data=groups, x="group", y="duration_min", inner="quart")

rows[["age", "hours_per_week"]].corr(method="pearson")
pd.cut(rows["hours_per_week"], [0, 30, 40, 50, 100], include_lowest=True)
pd.crosstab(clients["education"], clients["default"])
sns.countplot(...)              # counts records, not rates
sns.barplot(data=rates, x="education", y="rate", errorbar=None)   # precomputed rates

sns.scatterplot(data=sample, x="trip_distance", y="fare_amount", alpha=0.2)
sns.jointplot(data=sample, x="trip_distance", y="fare_amount", kind="hex")
sns.pairplot(train_sample[columns])                  # display sample of training rows
sns.heatmap(train[columns].corr(), vmin=-1, vmax=1, center=0, annot=True)
pd.read_sas("DEMO_J.xpt", format="xport")

Gotchas

  • [20, 25) includes 20 and excludes 25: 3 trips of exactly 20 minutes sit in that bar, so bars cannot decide a <= 20 rule. Count the rows.
  • A density height is not a percentage; only width × height is.
  • An ECDF's vertical axis is always a fraction, never a duration.
  • Rounding a percentile down can break the target: 27 min covers 89.8%, 28 min covers 91.1%.
  • Average invoice totals, not lines: the mean line value is £20.12.
  • The sample variance's unit is pounds squared; report the SD in pounds.
  • A point beyond a whisker is a flag for inspection, not a proven error; a value inside the fences (a 3 second trip) is not proven valid either.
  • Violin widths are scaled per group: they do not show group size.
  • Correlation is not causation; subgroups can reverse it (-0.052 in HS-grad, 0.203 in Some-college).
  • A high r (0.939) does not mean one rule fits every row: the $70 code-two band.
  • A random train/test split partitions the rows you already have; it does not change who was selected or who responded.
  • The largest count is not the highest rate: university has the most defaults, high school the highest rate.
  • Leave fnlwgt and the income label out of a feature scan, and compute the heatmap on training rows only.