On this page11 sections
Lecture 003 — Python ML Libraries Tour
| Category | 1 — ML Foundations |
| Lecture | 003 of 011 |
| Estimated video length | 16 min |
| Target | Python 3.10+ · numpy, pandas, scikit-learn |
| Level | Beginner |
Seven libraries, one job each. This lecture maps who does what — then Lecture 004 starts using them for real.
Contents
Prerequisites · Connection · Objectives · Lesson · Code Examples · Common Mistakes · Best Practices · Mini Challenge · Practice Questions · Answers · Takeaways
Prerequisites
- Python installed, with
pip install numpy pandas scikit-learn - Lecture 002 — the vocabulary (vectors, gradients) these libraries implement
Connection With Previous Lectures
Lecture 002 gave the math vocabulary; this lecture shows which library handles which part of it in code. Every later lecture's code examples use scikit-learn, built on NumPy and pandas.
Learning Objectives
By the end of this lecture you will be able to:
- Name the core Python ML libraries and the one job each is best known for
- Explain why scikit-learn, not TensorFlow/PyTorch, is the default for most of this course
- Load data and train a first scikit-learn model end-to-end
Lesson
| Library | Role |
|---|---|
| NumPy | Numerical computing on large multi-dimensional arrays; vectorized math, linear algebra, random number generation. |
| Pandas | Tabular data loading/cleaning/analysis via DataFrames and Series; built on top of NumPy. |
| Matplotlib / Seaborn | Static plotting and statistical visualization (Seaborn is built on Matplotlib). |
| Scikit-learn | The classical-ML workhorse: classification, regression, clustering, preprocessing, and evaluation metrics, built on NumPy/SciPy. |
| TensorFlow | Google's deep learning framework, good for large-scale/GPU-accelerated training; uses NumPy internally for tensor manipulation. |
| Keras | High-level neural network API (often layered on TensorFlow) — good for fast prototyping. |
| PyTorch | Deep learning library with dynamic computation graphs; popular in research for its flexibility/debuggability. |
This course leans almost entirely on scikit-learn through Lecture 009 — it covers
regression, classification, clustering, and evaluation with one consistent API
(.fit() / .predict() / .score()). TensorFlow/PyTorch only enter in Lecture 010, for
neural networks specifically.
Code Examples
Example 1 — The scikit-learn Pattern
Every scikit-learn model follows the same three-step shape: load data, fit() on training
data, predict() on new data. This example classifies tabular data with logistic regression:
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
df = pd.read_csv("movies.csv")
X, y = df[["feature1", "feature2"]], df["label"]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
clf = LogisticRegression()
clf.fit(X_train, y_train)
print("Accuracy:", accuracy_score(y_test, clf.predict(X_test)))X is the feature matrix (what we predict from), y is the target (what we predict).
train_test_split holds out 20% of the data to check the model honestly, on examples it never
trained on — the idea Lecture 008 covers in depth.
Common Beginner Mistakes
1. Reaching for TensorFlow/PyTorch as "the next step up" from scikit-learn for every problem — many tabular/structured-data problems are solved faster, with less data, and more interpretably with scikit-learn models (or gradient-boosted trees) than with deep learning.
2. Confusing NumPy arrays and pandas DataFrames — NumPy arrays are purely numeric; pandas DataFrames add labeled columns/rows and mixed types, which is why most real-world loading starts with pandas and converts to NumPy under the hood when it reaches scikit-learn.
3. Not pinning library versions — scikit-learn's API is fairly stable, but exact outputs (e.g., default parameter values) can shift between major versions.
Best Practices
- Default to scikit-learn for classical ML; reach for TensorFlow/PyTorch only once a problem specifically needs deep learning (Lecture 010 explains when that is).
- Load and inspect data with pandas before feeding it to any model.
- Keep
pip freeze > requirements.txtso experiments stay reproducible.
Mini Challenge
Run the Example 1 pattern against any small CSV with a binary label column, and print the
shape of X_train vs. X_test to confirm the 80/20 split happened as expected.
Practice Questions
- Which library is built on top of NumPy and adds labeled, tabular data structures?
- Why does this course mostly use scikit-learn instead of TensorFlow/PyTorch?
- What do
fit()andpredict()each do in the scikit-learn pattern? - What is
train_test_splitprotecting against?
Practice Answers
- Pandas.
- Most of the course covers classical ML (regression, classification, clustering) — problems scikit-learn solves faster, with less data, and more interpretably than deep learning.
fit()trains the model on the training data;predict()applies the trained model to new, unseen inputs.- Evaluating a model on the same data it trained on, which would hide how well it generalizes to data it hasn't seen.
Key Takeaways
- NumPy = arrays/math, pandas = tabular data, scikit-learn = classical ML, TensorFlow/ PyTorch = deep learning
- Every scikit-learn model follows the same
fit()/predict()shape - Default to scikit-learn; reach for deep learning only when the problem actually needs it
train_test_splitkeeps evaluation honest by holding out unseen data