Data Set Concepts and Preparation

CS 212, AI Programming 1

Topics  
1. What is AI, Python 6. Artificial Neural Networks: Image recognition
2. Symbolic AI: rule-based 7. Generative AI
3. Classical Machine Learning
Bayes’ Rule
8. Custom chatbot
4. scikit-learn
Working withData Sets
9. LLM fine-tuning
5. ML: Scikit Learn Part 2 10. Ethics

Table of Contents

Working with Data

Developing a proper dataset is the most crucial part of building a successful machine learning model, as performance depends entirely on the quality of the data (“garbage in, garbage out”).

I. Core Components of a Dataset

A. Classes and Labels

B. Features and Feature Vectors

C. Types of Features

  1. Floating-Point Numbers (Continuous): Numbers with a decimal point (real numbers), used directly by most models (e.g., 2.33 cm).
  2. Interval Values (Discrete): Integers where the difference (interval) between values is meaningful and equal (e.g., pixel intensity, number of petals).
  3. Ordinal Values: Express an ordering, but the difference between the values is not necessarily the same (e.g., educational level encoded as 1, 2, 3).
  4. Categorical Values: Numbers used as codes to express a category, with no inherent relationship between them (e.g., 0 for male, 1 for female, 0 for red).
    • One-Hot Encoding: A technique to make categorical values ordinal by mapping them to a binary vector (one feature per category), where only one element is 1 (e.g., male $\to [1, 0]$, female $\to [0, 1]$).

II. Feature Selection and Dimensionality

A. Feature Selection Rule of Thumb

B. The Curse of Dimensionality

III. Features of a Good Dataset

A. Interpolation vs. Extrapolation

B. The Parent Distribution

C. Prior Class Probabilities

D. Confusers (Hard Negatives)

E. Dataset Size

IV. Data Preparation Techniques

A. Scaling Features

B. Missing Features

V. Splitting the Dataset

We split the full dataset into three non-overlapping subsets:

Subset Purpose Typical Size
Training Data Used to train the model and adjust its parameters. 90%
Validation Data Used during training to tune the model’s architecture (hyperparameters) and decide when to stop. 5%
Test Data Used only once at the very end to evaluate the final, complete model’s performance. 5%

A. Partitioning Methods

  1. Partitioning by Class (Exact Split): Manually ensuring that the class ratios (prior probabilities) are preserved exactly in each subset. (Tedious, but useful for small or severely imbalanced datasets).
  2. Random Sampling: Randomizing the full dataset and slicing off the sections for training, validation, and test. (Simpler, and generally sufficient for large datasets).

B. k-Fold Cross Validation

VI. Data Inspection

Reference


Creative Commons License AI Programming 1 lecture notes by Brian Bird, written in , are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.


Google Gemini Flash 2.5 Pro was used to draft these notes.