What is Machine Learning?
Machine Learning is teaching computers to learn from data without being explicitly programmed for every case. Instead of writing rules, you show the computer examples and it figures out the patterns.
Types of ML
- Supervised Learning — Learn from labeled examples (most common). Predict house prices, classify spam.
- Unsupervised Learning — Find patterns in unlabeled data. Clustering customers by behavior.
- Reinforcement Learning — Learn by trial and error with rewards. Games, robotics.
The ML Workflow
Key Vocabulary
- Features (X) — Input columns used to make predictions
- Target (y) — The column we're trying to predict
- Training set — Data the model learns from (usually 80%)
- Test set — Data to evaluate how well the model performs (20%)
- Overfitting — Model memorized training data but fails on new data
What is Scikit-learn?
Scikit-learn (sklearn) is Python's most popular ML library. It has consistent API across all algorithms: every model has the same fit(), predict(), and score() methods.
sklearn's Main Modules
sklearn.linear_model— Linear/Logistic Regressionsklearn.tree— Decision Treessklearn.ensemble— Random Forest, Gradient Boostingsklearn.preprocessing— Scale, encode, transform datasklearn.model_selection— train_test_split, cross-validationsklearn.metrics— accuracy, MSE, confusion matrix
Preprocessing — Scaling Features
What is Linear Regression?
Linear Regression finds the best straight line through your data to predict a continuous number. It answers: "Given house size, what is the predicted price?"
Metrics: R² and RMSE
- R² (R-squared) — How much variance the model explains. 1.0 = perfect, 0 = no better than average. Aim for > 0.85.
- RMSE (Root Mean Squared Error) — Average prediction error in the same unit as y. Lower is better.
Classification vs Regression
When the answer is a category (spam/not spam, fraud/normal, pass/fail) — use classification. Logistic Regression is the simplest classifier.
Understanding the Classification Report
- Precision — Of all predicted positives, how many were actually positive? (avoid false alarms)
- Recall — Of all actual positives, how many did we catch? (avoid missing cases)
- F1-score — Balance between precision and recall. Use when classes are imbalanced.
Decision Trees
A Decision Tree splits data by asking yes/no questions. Random Forest = 100s of trees voting together — much more accurate and robust.
The Confusion Matrix
Cross-Validation
What is Feature Engineering?
"Garbage in, garbage out." The quality of your features determines the quality of your model more than the algorithm itself.
Handling Missing Values for ML
Why SQL + Python?
Most real-world data lives in databases. Python's sqlite3 module lets you query SQLite databases, and pandas can read SQL queries directly.
SQL Queries with pandas
What is a REST API?
APIs let programs talk to each other over HTTP. REST APIs return data (usually JSON) when you call a URL. Python's requests library makes this simple.
Working with JSON APIs + pandas
API Authentication & Headers
Web Scraping with BeautifulSoup
When there's no API, you can scrape the HTML directly. requests fetches the page, BeautifulSoup parses the HTML.