Machine learning is a way of programming computers to find patterns in data and make predictions, without a human writing explicit rule-by-rule logic for every case — the algorithm learns the rules from examples instead.
# Traditional programming: a human writes the rules
def is_spam(email):
if "free money" in email.lower():
return True
# ... endless manual rules
# Machine learning: the algorithm learns rules from labeled examples
from sklearn.linear_model import LogisticRegression
model = LogisticRegression()
model.fit(X_train, y_train) # learns patterns from thousands of labeled emails
predictions = model.predict(X_test)
Machine learning splits into three broad categories. Supervised learning learns from labeled examples (input paired with the correct answer) to predict labels for new, unseen input — further split into regression (predicting a continuous number, like a house price) and classification (predicting a category, like spam/not-spam). Unsupervised learning finds structure in unlabeled data — clustering similar customers together, for instance, with no predefined "correct" grouping. Reinforcement learning (not covered in depth in this notebook) learns through trial and error, receiving rewards or penalties for actions taken in an environment — the basis of game-playing AI and robotics control.
scikit-learn (sklearn) is the standard Python library for classical machine learning — nearly every algorithm exposes the same consistent .fit()/.predict() interface, which is exactly why switching between different models in scikit-learn code is often just a one-line change, a design choice this notebook leans on heavily throughout.