Machine Learning: Data Representation and Exploration Notes

Machine Learning Overview and Historical Context

  • Artificial intelligence (AI) encompasses historical developments and significant scientific breakthroughs that led to modern applications.

  • Historical Milestones:

    • Perceptron (1958): A foundational neural network structure. The mathematical model defines the output (oo) as o=sign(kwkik)o = sign(∑_k w_k i_k), where iki_k are inputs, wkw_k are weights, and outputs are typically in the set {1,+1}\{-1, +1\}.

    • Backpropagation (1986): A critical development in training neural networks, enabling deeper architectures and complex function mappings, such as f(4)=5f(4) = 5, f(8)=5f(8) = 5, f(12)=9f(12) = 9, and f(16)=17f(16) = 17.

  • Modern AI Applications:

    • Consumer AI: Generative models for content creation.

    • Research AI: Applications in Protein Folding (biology), Game Engines (simulation), and Autonomous Driving (transportation).

Fundamental Data Representation

  • Objects of interest (e.g., cars, persons, countries) are assumed to be represented as dd-dimensional column vectors unless otherwise noted.

  • Example: Porsche Playing Cards: A car is represented as a 6-dimensional column vector (d=6d = 6):

    • Porsche 959 (1988):

    • Model Year: 19881988

    • Displacement: 2849cm32849\,cm^3

    • Power Output: 331kW331\,kW

    • Acceleration: 3.7s3.7\,s

    • Top Speed: 315km/h315\,km/h

    • Weight: 1450kg1450\,kg

    • Porsche 911 GT1 (1997): [1997,3163,400,3.7,310,11201997, 3163, 400, 3.7, 310, 1120]

    • Porsche Carrera GT (2003): [2003,5733,450,3.9,330,13802003, 5733, 450, 3.9, 330, 1380]

  • The Data Matrix (XX):

    • All representations are collected into a matrix XX.

    • Rows: Called samples (denoted nn).

    • Columns: Called features (denoted dd).

    • Notation:

    • X=(x1TxiTxnT)X = \begin{pmatrix} x_1^T \\ \vdots \\ x_i^T \\ \vdots \\ x_n^T \end{pmatrix}

    • xiTx_i^T: The ii-th sample.

    • xjx_{\cdot j}: The jj-th feature (entire column).

    • xijx_{ij}: The jj-th feature of the ii-th sample.

Feature Types and Encodings

  • Features are categorized based on their data properties:

  • Categorical Features (Unordered):

    • Binary: Takes two values, e.g., xij{true, false},{yes, no},{pass, fail},{dead, alive}x_{ij} \in \{\text{true, false}\}, \{\text{yes, no}\}, \{\text{pass, fail}\}, \{\text{dead, alive}\}.

    • Nominal: Takes multiple unordered values, e.g., xij{English, German, French},{cat, dog, rabbit},{biology, physics, chemistry}x_{ij} \in \{\text{English, German, French}\}, \{\text{cat, dog, rabbit}\}, \{\text{biology, physics, chemistry}\}.

  • Numerical Features (Ordered):

    • Ordinal: Ordered labels without consistent spacing, e.g., xij{low income, medium income, high income},{disagree, neutral, agree}x_{ij} \in \{\text{low income, medium income, high income}\}, \{\text{disagree, neutral, agree}\}.

    • Discrete: Countable values, e.g., xij{0,1,2,}x_{ij} \in \{0, 1, 2, \dots\}.

    • Continuous: Real-valued numbers, e.g., xijR0x_{ij} \in \mathbb{R}_{\ge 0} (mass, distance).

  • 1-of-k Encoding (One-Hot Encoding): Categorical data is converted to numerical vectors. For example, animal types [cat, dog, rabbit] become binary columns where a "cat" is [1,0,01, 0, 0] and a "rabbit" is [0,0,10, 0, 1].

Complex Data Structures

  • Text Data: Represented using Bag-of-Words.

    • Words are counted after ignoring capitalization and punctuation based on a defined dictionary.

    • Pro: Allows distance/similarity computation between documents.

    • Con: Ignores word order (e.g., "The policeman handcuffed the robber" looks the same as "The robber handcuffed the policeman").

  • Image Data: Represented as sequences of grayscale pixel intensities.

    • Values range from 00 (black) to 255255 (white).

    • Dimensionality is extremely high; a (1080,1920)(1080, 1920) resolution image has over 2,000,0002,000,000 pixels.

  • Graph Data: Represented via Adjacency Matrices.

    • Entries can be binary (presence of an edge) or numerical (edge weights).

Operations on Features

  • Aggregation: Grouping raw features to reduce combinations (e.g., grouping specific cities into countries like Germany or France).

  • Transformation (Discretization/Binning): Turning numerical data into categorical data (e.g., converting ages into bins like <20, [20,25)[20, 25), and 25\ge 25).

  • Selection: Removing irrelevant features (e.g., StudentID) to treat similar samples equally.

  • Data Size Rule of Thumb: A popular approximation for the required number of samples is n > 10 \times d.

  • Data Cleaning: Identifying and fixing issues including noise (distortion), outliers (entry errors), missing values, and duplicated data.

Data Exploration and Categorical Statistics

  • Exploration aims to find outliers, corrupt data, feature correlations, and understand data distribution/ranges using statistics and visualization.

  • Frequency: The fraction of entries belonging to a specific class kk.

  • Distribution: The set of frequencies for all classes.

  • Mode: The most frequent class in the dataset.

  • Entropy (H(xj)H(x_{\cdot j})): Measures the randomness or "average units of information" in a sample.

    • Formula: H(xj)=c=1Kp(c)log(p(c))H(x_{\cdot j}) = -\sum_{c=1}^K p(c) \cdot \log(p(c))

    • Range: 00 (no randomness) to log(K)\log(K) (total randomness, where all classes have equal frequency).

    • Exercise (Binary Entropy): If a binary feature is "1" with probability 0.90.9, the entropy is (0.9log2(0.9)+0.1log2(0.1))0.47-(0.9 \cdot \log_2(0.9) + 0.1 \cdot \log_2(0.1)) \approx 0.47.

Numerical Statistics

  • Range: Defined by the minimum and maximum: (minixij,maxixij)(\min_{i} x_{ij}, \max_{i} x_{ij}). Anomalies (negative mass, unit mismatch) can be identified here.

  • Arithmetic Mean (μj\mu_j): A measure of central tendency: μj=1ni=1nxij\mu_j = \frac{1}{n} \sum_{i=1}^n x_{ij}.

  • Standard Deviation (σj\sigma_j): A measure of statistical dispersion: σj=1ni=1n(xijμj)2\sigma_j = \sqrt{\frac{1}{n} \sum_{i=1}^n (x_{ij} - \mu_j)^2}.

  • Sample Variance: Denoted as σj2\sigma_j^2.

  • Robust Statistics:

    • Median (medjmed_j): The middle value of a sorted list. For odd nn, it is at position n+12\frac{n+1}{2}. For even nn, it is the average of positions n2\frac{n}{2} and n2+1\frac{n}{2} + 1. It is less sensitive to outliers than the mean.

    • Interquartile Range (IQRjIQR_j): The range between the first quartile (Q1Q_1, 0.250.25-quantile) and third quartile (Q3Q_3, 0.750.75-quantile). IQRj=[Q1,Q3]IQR_j = [Q_1, Q_3].

  • Quantiles: A value zz is a qq-quantile if a fraction qq of entries are z\le z.

    • 0.00min0.00 \rightarrow \min, 0.25Q10.25 \rightarrow Q_1, 0.50med0.50 \rightarrow med, 0.75Q30.75 \rightarrow Q_3, 1.00max1.00 \rightarrow \max.

Correlation and Distances

  • Sample Covariance: cov(xj,xk)=1ni=1n(xijμj)(xikμk)cov(x_{\cdot j}, x_{\cdot k}) = \frac{1}{n} \sum_{i=1}^n (x_{ij} - \mu_j)(x_{ik} - \mu_k).

  • Correlation Coefficient (ρ\rho): Measures linear correlation: ρ(xj,xk)=cov(xj,xk)σjσk\rho(x_{\cdot j}, x_{\cdot k}) = \frac{cov(x_{\cdot j}, x_{\cdot k})}{\sigma_j \cdot \sigma_k}.

    • Range: [1,+1][-1, +1].

    • Invariance: Invariant under linear transformations ax+ba \cdot x + b.

  • Distances:

    • Euclidean Distance: d(xj,xk)=xjxk2=i=1n(xijxik)2d(x_{\cdot j}, x_{\cdot k}) = \|x_{\cdot j} - x_{\cdot k}\|_2 = \sqrt{\sum_{i=1}^n (x_{ij} - x_{ik})^2}.

    • Hamming Distance: Counts the number of positions where values differ: d(xj,xk)=i=1n[xijxik]d(x_{\cdot j}, x_{\cdot k}) = \sum_{i=1}^n [x_{ij} \neq x_{ik}] (useful for categorical data).

Limitations of Statistics and Visualization Tools

  • Anscombe's Quartet & Datasaurus Dozen: Datasets with identical summary statistics (mean, variance, correlation) but vastly different visual distributions, highlighting the necessity of visualization.

  • Visualization Methods:

    • Quantile Plot: Maps data values against their $q$-quantiles.

    • Box Plot: Displays {min,Q1,med,Q3,max}\{min, Q_1, med, Q_3, max\} and IQRIQR visually.

    • Histogram: Visualizes counts aggregated into bins.

    • Line Plot: Shows one variable as a function of another.

    • Scatter Plot: Explores joint distribution of two features; color can represent a third variable.

    • Matrix Plot: Heatmap showing all matrix entries or pairwise correlations.

Introduction to Supervised Learning

  • Motivation: Determining cause-and-effect in complex scenarios (e.g., tracking food intake to identify allergies).

  • Setup:

    • Input: Features of samples (e.g., quantities of food eaten).

    • Output: Class labels (e.g., sick or not sick).

    • Goal: Find a model to accurately predict labels for new samples.

  • Classification: A branch of supervised learning where labels are categorical. The resulting model is a classifier.