Skip to content

Getting to Know Your Data

Data Objects and Attribute Types

Basic Terminology

  • Data set: a collection of data objects (records, points, examples, instances).
  • Data object: described by a set of attributes (features, variables, dimensions, fields).
  • Attribute (feature, variable): a data field representing a characteristic of an object. A value of an attribute can be numerical or symbolic.

Attribute Types by Scale

ScaleMeaningOperationsExamples
Nominalcategories/names, no order=,, modecolor, gender, zip code
Binary (nominal with 2 states)symmetric (both equally important) or asymmetric (one state rarer/more important)=,gender (symmetric), medical test +/− (asymmetric)
Ordinalmeaningful order but unknown spacing$<, >, $ median, percentilerank, grade, size (S/M/L)
Numeric
  — Intervalequal-spaced, no true zero$+, -, $ mean, stdtemperature (°C), calendar
  — Ratiotrue zero, ratios meaningful$\times, \div, $ geometric meanweight, length, counts
  • Discrete vs continuous: discrete attributes have finite/countable domains; continuous (numeric) take real values (often represented as floating-point).
  • Many attributes can be of mixed type; type determines which similarity/distance and statistics apply.

Describing Data: Central Tendency

  • Mean (average): x¯=1ni=1nxi. Sensitive to outliers.
  • Trimmed mean: drop highest/lowest k% then average — robust to outliers.
  • Weighted mean: x¯w=wixiwi.
  • Median: the middle value when sorted. Robust to outliers. For n ordered values, position (n+1)/2. More robust than mean for skewed data.
  • Mode: the most frequent value. A data set can be unimodal, bimodal, or multimodal.
  • Midrange: (max+min)/2.
  • Skewness measures asymmetry:
    • Negative skew (left): tail to the left, mean < median.
    • Positive skew (right): tail to the right, mean > median.

Describing Data: Dispersion

  • Range: maxmin.
  • Interquartile range (IQR): IQR=Q3Q1 (spread of middle 50%). Outlier rule: <Q11.5IQR or >Q3+1.5IQR.
  • Variance (population): σ2=1ni=1n(xix¯)2.
  • Variance (sample): s2=1n1i=1n(xix¯)2.
  • Standard deviation: σ=σ2. Same units as data.
  • Mean absolute deviation (MAD): 1n|xix¯|.
  • Five-number summary: min, Q1, median, Q3, max; visualized by a boxplot.
  • Data visualization: histograms, boxplots, scatter plots, quantile plots, q-q plots, Lorenz curve (for unequal distribution / Gini).

Graphic Displays

  • Histogram: bar chart of value frequencies; bin width matters.
  • Boxplot: compactly shows median, IQR, whiskers, and outliers.
  • Scatter plot: shows correlation/relationship between two numeric attributes.
  • Loess / smoothed curve: local regression to reveal trend.
  • Quantile plot (q-q plot): compare empirical distribution to a theoretical one.
  • Parallel coordinates: each object is a polyline across axes — good for high-dimensional numeric data.

Data Quality

ProblemDescriptionExample
Noiserandom error / distortion in a measured valuesensor jitter, typos
Outliersdata objects that deviate markedly from the restfraud, sensor fault
Missing valuesnot recorded / unavailable / "not applicable"blank field
Duplicate datarepeated records (data integration)same person twice
Inconsistentconflicting values from different sourcesunits differ

Handling Missing Values

  1. Ignore the tuple (if many attributes missing) — risks losing data.
  2. Fill manually (expensive).
  3. Use a global constant (e.g., "Unknown").
  4. Use the attribute mean / mode.
  5. Use the most probable value (e.g., regression / Bayesian inference).

Handling Noisy Data

  • Binning: sort and partition into bins; smooth by bin mean/median/boundaries.
  • Regression: fit a function to smooth (linear/ multiple regression).
  • Clustering: detect and remove outliers, smooth within clusters.
  • Machine learning / human inspection for correction.

Similarity and Dissimilarity

Definitions

  • Similarity: numerical measure of how alike two objects are. Usually in [0,1], higher = more similar.
  • Dissimilarity (distance): numerical measure of how different. Often in [0,); 0 = identical.
  • Proximity = similarity or dissimilarity.

Distance for Numeric (Interval/Ratio) Data

For data vectors p=(p1,,pn), q=(q1,,qn):

  • Minkowski distance (metric family):d(p,q)=(i=1n|piqi|h)1/h
  • L1 Manhattan (h=1): d=|piqi|.
  • L2 Euclidean (h=2): d=(piqi)2. Most common.
  • L Supremum / Chebyshev (h): d=maxi|piqi|.

Properties of a metric distance: non-negativity, identity (d(p,q)=0p=q), symmetry, triangle inequality d(p,r)d(p,q)+d(q,r).

Weighted and Other Distances

  • Weighted Euclidean: d=wi(piqi)2, wi0.
  • Mahalanobis distance: d=(pq)TΣ1(pq), where Σ is the covariance matrix — accounts for correlation & scale.

Similarity for Binary / Nominal Data

  • Binary (asymmetric) similarity — Jaccard coefficient:J=f11f01+f10+f11where f11 = both 1, f01,f10 = one 1; ignore f00 (both 0). Used for market-basket / asymmetric binary.
  • Simple matching coefficient (symmetric) includes f00: SMC=f11+f00f11+f00+f10+f01.
  • Nominal with M states: similarity =\frac{\text{# matches}}{M}.
  • Ordinal: map to ranks 1..M then treat as interval/ratio (often normalize to [0,1] by (r1)/(M1)) and apply numeric distances.
  • Cosine similarity (for high-dimensional sparse, e.g., text/doc vectors):sim(p,q)=pqpq=piqipi2qi2[1,1]Useful for TF-IDF document vectors; angle-based, ignores magnitude.

Correlation

  • Pearson correlation for numeric p,q:rpq=(pip¯)(qiq¯)(pip¯)2(qiq¯)2[1,1]+1 perfect positive, 1 perfect negative, 0 no linear correlation.

Data Matrix vs Dissimilarity Matrix

  • Data matrix (n×p): rows = objects, columns = attributes — the raw data we usually start with.
  • Dissimilarity matrix (n×n, symmetric, zero diagonal): d(i,j) = proximity of objects i and j. Many algorithms (clustering, MDS, some classifiers) consume only this matrix.
  • Converting data → dissimilarity is the first step for distance-based methods; the choice of measure defines what "similar" means and can dominate results.

Proximity for Mixed-Type Data

When a record mixes attribute types (numeric + nominal + binary), combine per-attribute normalized contributions:

d(x,y)=f=1pδf(x,y)df(xf,yf)f=1pδf(x,y)
  • δf=0 if xf or yf is missing/incomparable, else 1.
  • numeric: df=|xfyf|/(maxfminf).
  • binary/nominal: df=0 if equal, 1 if different.
  • ordinal: map to ranks then treat as numeric.

Worked Example

Two customers p=(age=25, math=yes, sports=no), q=(age=30, math=no, sports=yes), ages in [20,40]:

  • numeric age: d=(3025)/20=0.25.
  • math (binary): differ ⇒ 1; sports (binary): differ ⇒ 1.
  • mixed distance (0.25+1+1)/3=0.75 (higher = more different).

Choosing a Statistic — When to Use Which

StatisticOutlier-sensitive?Use when
Meanyessymmetric, clean data
Mediannoskewed / noisy data
Modeno (categorical)nominal data
Std / varianceyesscale matters, near-normal
IQR / MADnorobust spread

Noise vs Outlier (Reminder)

Noise = random error in a recorded value (handled by smoothing); an outlier is a genuine, often meaningful deviation. Not all outliers are noise and not all noise is an outlier — deciding which is a modeling choice that precedes cleaning.

Text & High-Dimensional Similarity (TF-IDF + Cosine)

For documents, represent each as a vector over terms with TF-IDF weights:

wt,d=tft,dlogNdft

where tf = term frequency in the doc, dft = number of docs containing the term, N = total docs. Compare docs by cosine similarity (angle between vectors) — magnitude-invariant and ideal for sparse bag-of-words.

Data Quality Dimensions (Summary)

DimensionMeaning
Accuracyclose to the true value
Completenessno missing values
Consistencyagrees across sources
Timelinessup to date
Validityconforms to schema/type
Uniquenessno duplicates

Choosing the Right Proximity (Guide)

  • Numeric, same scale → Euclidean / Manhattan.
  • Numeric, different scales → z-score first, then Euclidean; or Mahalanobis.
  • Asymmetric binary (market basket) → Jaccard.
  • Sparse high-D (text) → cosine.
  • Mixed types → per-attribute weighted formula.
  • Correlation question → Pearson r.

Summary

Understanding your data is the prerequisite for every later step. Know attribute scales (nominal/binary/ordinal/interval/ratio; discrete vs continuous) because they dictate valid statistics and proximity measures. Summarize central tendency (mean/median/mode) and dispersion (range/IQR/variance). Recognize and treat data-quality problems (noise, outliers, missing, duplicate, inconsistent). Choose proximity carefully: Minkowski/Euclidean for numeric, Jaccard for asymmetric binary, cosine for sparse high-dimensional vectors, Pearson for correlation.