From Tables to Features and Targets

Machine learning starts with a table

Before any of the later modules talk about language models, agents, or vector databases, it helps to build the mental model underneath all of it: machine learning (ML) is a way of teaching a computer to spot a pattern in past examples, so it can make a reasonable guess about a new example it hasn't seen. Instead of a programmer writing an explicit rule like if tenure < 3 months: flag as risky, the computer looks at thousands of past rows and works out which combination of details tends to go with which outcome.

Scenario: A subscription business wants to predict which customers are about to cancel ("churn") so a retention team can call them first. Someone exports a spreadsheet with one row per customer and columns for age, plan, monthly income bracket, how many months they've been a subscriber (tenure), and whether they eventually cancelled.

In that spreadsheet, every column the model is allowed to look at before making its prediction is called a feature - age, plan, and tenure are all features. The one column holding the answer you want to predict is called the target, sometimes written as the label. Here the target is cancelled (yes/no). Training a model is the process of showing it many rows of features next to their known targets so it can learn the relationship between them.

You'll do almost all of this early data work in Python with two libraries. Pandas represents a table as a DataFrame - rows and named columns, like a spreadsheet you can script. NumPy is the lower-level numerical library Pandas is built on; it provides fast arrays of numbers and the special value NaN ("not a number"), which Pandas uses to mark a cell as missing.

The very first thing any careful practitioner does with a new table is look at it before trusting it:

import pandas as pd

df = pd.read_csv("customers.csv")
print(df.shape)          # (rows, columns)
print(df.dtypes)         # what type pandas thinks each column is
print(df.isna().sum())   # how many missing cells per column
print(df.head())         # eyeball the first few rows
(5000, 6)
age            int64
plan          object
income        object
tenure_months  int64
cancelled       bool
dtype: object
age               0
plan              0
income          312
tenure_months     0
cancelled         0
dtype: int64

That output already tells a story: income is 312 rows short, and it's stored as object (Pandas' catch-all type for text) instead of a number - a strong hint that at least one row has something like "unknown" or "$45,000" typed into a column that should hold plain numbers.

Analogy: Preparing data is like checking ingredients before cooking. A beautiful recipe (a sophisticated model) cannot rescue spoiled food, missing measurements, or a label pasted onto the wrong jar. Time spent here pays off far more than time spent tuning the model later.
Goal: In the data-hygiene lab, diagnose invalid numeric values and missing cells before creating a clean feature table - the same first step shown above, applied to a broken dataset.