Data Types and Data Transformation — Normalization, Discretization, Sampling, Compression
Attribute types (nominal, binary, ordinal, interval, ratio; discrete vs continuous), data quality issues, and the preprocessing steps the syllabus names — normalisation (min-max, z-score, decimal scaling), smoothing and binning, discretisation (equal-width, equal-frequency, entropy-based, concept hierarchies), sampling (simple random, stratified, cluster, systematic, reservoir) and data reduction and compression (lossless vs lossy, dimensionality and numerosity reduction).
Real data is messy: values on different scales, continuous attributes where categories are needed, too many rows or columns, noise and missing entries. Preprocessing turns raw data into a form that mining and machine learning algorithms can use.
Data types (attribute types)
| Type | Meaning | Examples | Meaningful operations |
|---|---|---|---|
| Nominal (categorical) | names/labels, no order | colour, PIN code, blood group | , , mode |
| Binary | two states; symmetric or asymmetric | gender, test positive/negative | as nominal |
| Ordinal | ordered categories, unknown gaps | rating, grade, size S/M/L | , median, percentiles |
| Interval | numeric, equal units, no true zero | °C, calendar year | , , mean, s.d. |
| Ratio | numeric with a true zero | height, income, kelvin, counts | all, including ratios |
- Discrete attributes take countable values (counts, categories); continuous ones take real values.
- In databases, the physical data types are
INT,DECIMAL(p, s),FLOAT,CHAR(n),VARCHAR(n),DATE,TIMESTAMP,BOOLEAN,BLOB— choosing exactDECIMALfor money avoids floating-point error.
Data quality and cleaning
- Missing values: ignore the tuple, fill with a constant, the mean/median (or class-conditional mean), or a predicted value.
- Noise: smooth by binning, regression or clustering; detect outliers with z-scores (), the IQR rule ( or ) or clustering.
- Inconsistencies and duplicates: reconcile codes and units, deduplicate records.
Normalisation (feature scaling)
Distance-based methods (k-NN, k-means, SVM) and gradient descent are distorted when attributes have different scales.
| Method | Formula | Result |
|---|---|---|
| Min-max | range (or any target); sensitive to outliers; out-of-range values for new data | |
| Z-score | mean 0, s.d. 1; preferable with outliers or unknown range | |
| Decimal scaling | , smallest with | shifts the decimal point |
| Robust scaling | resistant to outliers |
Other transformations: smoothing, aggregation (daily → monthly sales), attribute construction (area from length × width), log transforms for skewed data, one-hot encoding of nominal attributes.
Discretisation
Convert a continuous attribute into intervals (labels), reducing noise and enabling algorithms that need categorical inputs.
| Method | How | Supervised? |
|---|---|---|
| Equal-width binning | intervals of width | no |
| Equal-frequency (equal-depth) binning | each bin gets about values | no |
| Clustering-based | cluster values; clusters become intervals | no |
| Entropy-based | choose split points maximising information gain about the class | yes |
| ChiMerge | merge adjacent intervals whose class distributions are similar ( test) | yes |
| Histogram analysis | split at valleys of the histogram | no |
Smoothing by binning: after binning, replace values by the bin mean, bin median, or the nearer bin boundary.
Concept hierarchies generalise discretised or categorical values to higher levels (street < city < state < country; age → young/middle-aged/senior) and are central to data warehouses — see data warehousing.
Sampling
| Method | Description | When useful |
|---|---|---|
| SRSWOR | simple random sample without replacement | default |
| SRSWR | with replacement (an item can be picked twice) | bootstrap |
| Stratified | partition into strata (e.g. classes), sample each proportionally | skewed/imbalanced data |
| Cluster | sample whole groups (pages, households) | when data is naturally grouped |
| Systematic | every -th record after a random start | ordered lists, simple; beware periodicity |
| Reservoir | uniform sample of from a stream of unknown length in one pass | streams, big data |
import random
def reservoir(stream, k):
sample = []
for i, x in enumerate(stream): # i = 0, 1, 2, ...
if i < k:
sample.append(x)
else:
j = random.randint(0, i) # inclusive
if j < k:
sample[j] = x # keep x with probability k/(i+1)
return sample
Every item ends up in the sample with probability . Sampling cost scales with the sample size, not the data size — the key to mining very large data sets.
Data reduction and compression
Dimensionality reduction (fewer attributes):
- feature selection (filter, wrapper, embedded methods);
- feature extraction: PCA, wavelet transforms, random projections — see PCA.
Numerosity reduction (fewer or smaller data representations):
- parametric: regression or log-linear models store only parameters;
- non-parametric: histograms, clustering (store centroids), sampling, data cubes (pre-aggregation).
Compression:
| Lossless (exact reconstruction) | Lossy (approximate) |
|---|---|
| run-length encoding, Huffman coding, LZ77/gzip, dictionary encoding | truncated PCA/SVD, wavelet thresholding, JPEG, quantisation |
Columnar databases combine dictionary encoding, run-length encoding of sorted columns and bit-packing to compress analytical data many-fold.
Quick revision
Practice questions
GATE-style questions: 3 one-mark and 8 two-mark. Wrong MCQs cost ⅓ of their marks in the real exam; MSQ and NAT have no negative marking. Attempt each before opening the solution.
Income values range from 12,000 to 98,000. Using min-max normalisation to , the value 73,600 maps to ______ (round to two decimals).
Income has mean 54,000 and standard deviation 16,000. The z-score normalised value of 73,600 is ______ (round to two decimals).
An attribute takes values from to . Normalisation by decimal scaling divides every value by , with the smallest integer such that all scaled absolute values are below 1. The value of is ______.
The sorted values 4, 8, 15, 21, 21, 24, 25, 28, 34 are discretised into 3 equal-width bins over (widths of 10; the last bin includes 34). The number of values in the third (highest) bin is ______.
The same values 4, 8, 15, 21, 21, 24, 25, 28, 34 are split into 3 equal-frequency (equal-depth) bins and smoothed by bin means. The value assigned to every element of the second bin is ______.
A survey records customer satisfaction as poor, fair, good or excellent. This attribute is
Which statements about measurement scales are correct?
One or more options are correct.
A data set has 95% records from class A and 5% from class B. Which sampling method best guarantees that a 1% sample still contains class B records in proportion?
Reservoir sampling selects items uniformly at random from a stream of items in one pass. The probability that any particular item ends up in the sample is ______.
The string AAAABBBCCD is compressed with run-length encoding into (symbol, count) pairs. The number of pairs produced is ______.
Which of the following is a lossy data reduction technique?