← All courses CSIS 3352 · Module 2

Data Preparation and Preprocessing for AI

📅 Quiz 2 — due 9/1 · Covered on Midterm (Modules 1–9) — moved to Tue Oct 27
📌 Lecture 2 does not print a numbered list of learning objectives. The 14 objectives below were derived from the deck's own section structure and slide titles, so the wording is not the professor's. Every fact underneath them comes only from the Lecture 2 slides.
⚠️ Source inconsistency: the Hands-on Activity slide (slide 19) is footer-labeled "Lecture 4 — Data Quality & Data Cleaning," but this deck is Lecture 2 / Module 2, titled "Data Preparation and Preprocessing for Artificial Intelligence." The Module 2 labeling here follows the deck's title slide and the syllabus.
Section 1 · Data Quality, Missing Values, Duplicates & Outliers Section 2 · Encoding & Scaling Section 3 · Incorrect Data, Noise, Validation & Integrity

Study Guide

Module 2 · Lecture 2 — Data Preparation & Preprocessing

Why data quality matters

  • Garbage in, garbage out — bad data leads to bad decisions, broken models, and wasted time.
  • Cost — poor data quality is estimated to cost organizations millions of dollars every year.
  • Effort — cleaning is usually the single largest time investment in a real data science project.

The six data quality dimensions

DimensionMeaningExample
AccuracyData correctly reflects the real-world values and events it represents.A customer's email address is spelled correctly.
CompletenessAll required data is present and nothing important is missing.Every customer record has an email, phone number, and address.
ConsistencyData is uniform across different systems and formats."USA", "U.S.", and "United States" are used consistently.
TimelinessData is up-to-date and available when it is needed.Inventory levels are updated in real time as items are sold.
UniquenessEach piece of data is unique and not duplicated unnecessarily.No duplicate customer profiles exist in the database.
ValidityData conforms to defined rules, formats, and business constraints.A date of birth is a valid date (e.g., not 02/30/2024).

High-quality data builds trust, improves decisions, reduces costs, and drives better business outcomes.

Missing values

  • What — empty or null cells where data should exist.
  • Common causes — a skipped form field, sensor failure, a merge between mismatched sources, or a system error.
  • Three types — Missing Completely at Random (MCAR), Missing at Random (MAR), and Missing Not at Random (MNAR).
⚠️ The deck names three types of missing data — MCAR, MAR, and MNAR — and expands the acronyms, but it does not define or differentiate them. Those definitions are absent from the source, so none is supplied here.

Handling missing values:

  • Deletion — drop rows/columns with too many missing values (use carefully; you lose data).
  • Mean / median / mode imputation — fill in a statistically reasonable replacement value.
  • Forward-fill / backward-fill — carry the nearest known value forward or backward (common in time series).
  • Understand why first — the cause should drive the fix.

Duplicate records

  • What — the same real-world entity appears more than once in the dataset.
  • Common causes — repeated form submissions, merging multiple data sources, or system syncing errors.
  • Impact — can silently bias analysis and inflate counts, averages, and totals.
  • Exact duplicates — identical across every column; easy to detect and safely drop.
  • Near-duplicates — slightly different (typos, spacing, formatting); harder to catch, often needs fuzzy matching.
  • In pandas — .duplicated() to find them, .drop_duplicates() to remove them.
  • Caution — always double-check what actually counts as a "duplicate" before removing anything.
⚠️ "Fuzzy matching" is named as the technique for catching near-duplicates but is not defined in the deck; no definition is supplied here.

Outliers

  • What — data points that differ significantly from the rest of the dataset.
  • Origin — can be genuine (a real, rare event) or an error (a data-entry mistake or sensor glitch).
  • Example — one $500,000 order in a dataset where the average order is $50.

Detection methods:

MethodRuleNote
IQR (Interquartile Range)Flag x if x < Q1 − 1.5×IQR or x > Q3 + 1.5×IQR, where IQR = Q3 − Q1.More robust to extreme values.
Z-scorez = (x − μ) / σ; commonly flag |z| > 3 (μ = mean, σ = standard deviation).Assumes a roughly normal distribution.

Visual methods work too: box plots and scatter plots make outliers easy to spot by eye.

Handling outliers: investigate first (genuine vs. error); remove it (if clearly an error that would distort analysis); cap or limit it (winsorizing — pull extremes toward a reasonable boundary); transform the data (e.g., a log transform); or keep it (if it is a genuine, meaningful data point for your question).

Encoding categorical data — why we need it

  • Machine learning models need numbers, not text labels.
  • Categorical data — like "Red", "Blue", "Green" — must be converted, or encoded, into a numeric form.
  • The encoding method matters: a poor choice can introduce a false sense of order or relationship between categories.

Label encoding vs. one-hot encoding

AspectLabel EncodingOne-Hot Encoding
How it worksAssigns each category an integer (Red=0, Blue=1, Green=2).Creates a separate binary (0/1) column for each category.
OrderImplies a false order — e.g., Red (0) < Blue (1) < Green (2).No ordinal relationship — each category is independent.
Trade-offSimple, but the implied order can mislead.No false order, but adds more columns.
Best forOrdinal data (e.g., Low/Medium/High).Nominal data (no natural order).

Normalization & standardization — why scale data?

  • Features on very different scales (e.g., Age 0–100 vs. Income 0–200,000) can distort many ML models.
  • Scaling puts all features on a comparable range, so no single feature unfairly dominates.
  • Especially important for distance-based models (k-NN, k-means) and gradient-based models (neural networks).

The scaling equations

MethodFormulaNotes
Min-Max Normalizationx' = (x − min(x)) / (max(x) − min(x))Rescales values into a fixed [0, 1] range. Sensitive to outliers. Use when you need a strictly bounded range (e.g., neural network inputs).
Z-Score Standardizationz = (x − μ) / σCenters data around a mean of 0 with a standard deviation of 1. More robust when outliers are present. Use when data may contain outliers or is not uniformly distributed.
Min-Max: x' = (x − min(x)) / (max(x) − min(x)) → [0, 1] Z-Score: z = (x − μ) / σ → mean 0, std 1

Incorrect data

  • What — data that is present, but wrong: typos, wrong units, or impossible values.
  • Examples — age = 250, a negative price, "Februaryy" instead of "February", inconsistent date formats.
  • Catching it — requires domain knowledge and clear validation rules.
IssueExample from the lecture
Impossible age250, 1500
Negative price−$10.00
Misspelled month"Februarry" instead of "February" (bullet text: "Februaryy")
Invalid date13/32/2026
Inconsistent units / valuesLeads to errors and bad insights.

Noise in data

  • What — random variation or fluctuation in data that is not meaningful signal.
  • Different from outliers — noise is small and everywhere; outliers are extreme and isolated.
  • Where — common in sensor data, audio/image data, and survey responses.
  • Why it matters — too much noise can hide the real underlying pattern.

Data validation

Data validation is checking that data meets defined rules before it is used.

CheckQuestion it asks
Type checkIs this actually a number, date, or text as expected?
Range checkIs age between 0 and 120? Is a percentage between 0 and 100?
Format checkIs the email address, phone number, or date properly formatted?
Consistency checkDoes the end date come after the start date?

Validation should happen as early as possible — ideally right at the point of collection.

Data integrity

  • What — the overall accuracy, consistency, and reliability of data across its entire lifecycle.
  • Ongoing — not a one-time cleaning step; it is an ongoing responsibility.
  • Practices — access controls, audit trails, backups, validation pipelines, and clear data governance.

Hands-on activity — inspect a messy dataset

  • In groups, you receive a deliberately messy dataset — missing values, duplicates, outliers, bad encodings, and typos included.
  • Task: identify and list every data quality issue you can find.
  • Discuss: what would you do to fix each one, and why?
  • Findings are reviewed together as a class.

Flashcards

Question
Answer

Practice Quiz

Discussion Board Prep

Notes Template

Module 2 · Lecture 2 — Print this tab for in-class notes

📌 Module 2 source material

Everything on this page comes from Lecture 2 — Data Preparation and Preprocessing for Artificial Intelligence (Dr. Al Amin), 20 slides, posted to Blackboard. Quiz 2 is due 9/1. This module is covered on the Midterm (Modules 1–9), moved to Tue Oct 27.

Six data quality dimensions

Missing values — causes & types

Handling missing values

Duplicates — exact vs. near

Outliers — what & example

IQR vs. Z-score detection

Handling outliers (5 options)

Why encode categorical data

Label vs. one-hot encoding

Why scale — where it matters

Min-max vs. z-score equations

Incorrect data — examples

Noise vs. outliers

Four validation checks

Data integrity practices

Hands-on: messy dataset