Beginner-Friendly Topic
Take your time - it's perfectly normal to re-read this topic 2-3 times. Try the interactive code editor below to run code yourself. Use the Q&A section to check your understanding before moving on. You've got this! 🚀
Features and Labels
Features are the inputs to an AI model. Labels are the correct answers. Understanding this distinction is essential for understanding how AI learns.
Features: What Goes In
Features are the measurable properties of each example that the AI uses as input.
For a house price predictor:
- Feature 1: Size in square feet
- Feature 2: Number of bedrooms
- Feature 3: Distance from city center
- Feature 4: Year built
For an email spam detector:
- Feature 1: Number of times the word 'free' appears
- Feature 2: Whether the email has a lot of capital letters
- Feature 3: Number of links in the email
- Feature 4: Length of the email
Feature selection is one of the most important skills in AI. Better features lead to better models.
Deep Learning ⊂ Machine Learning ⊂ Artificial Intelligence
Labels: The Correct Answers
Labels are the correct answers that the AI is trying to predict or learn.
For a house price predictor: the label is the actual sale price of the house.
For an email spam detector: the label is 'spam' or 'not spam'.
For a medical diagnosis system: the label is the confirmed diagnosis.
In supervised learning, every training example has both features (inputs) and a label (correct answer).
Features and Labels in Code
# A simple dataset with features and labels
# Features = inputs, Label = correct answer
# Student score prediction
student_data = [
# [study_hours, previous_score, attendance_pct] -> final_score
([5, 70, 90], 75), # studied 5h, had 70 before, 90% attendance -> got 75
([2, 50, 60], 55),
([8, 80, 95], 88),
([1, 40, 50], 45),
([6, 75, 85], 80),
]
# Separate features (X) and labels (y)
X = [row[0] for row in student_data] # all features
y = [row[1] for row in student_data] # all labels (scores)
print("Features (inputs):")
for i, features in enumerate(X):
print(f" Student {i+1}: study_hours={features[0]}, prev_score={features[1]}, attendance={features[2]}%")
print()
print("Labels (correct answers):")
for i, score in enumerate(y):
print(f" Student {i+1}: actual final score = {score}")
print()
print("The AI learns the relationship between features and labels")
print("Then predicts scores for new students it has never seen")Try It Yourself
Common Mistake
Warning
A common mistake is choosing features that accidentally include information about the answer (this is called data leakage). For example, if you are predicting exam scores, you cannot use the final exam score as a feature because you are trying to predict it.