On this page11 sections
  1. Prerequisites
  2. Connection With Previous Lectures
  3. Learning Objectives
  4. Lesson
  5. Code Examples
  6. Common Beginner Mistakes
  7. Best Practices
  8. Mini Challenge
  9. Practice Questions
  10. Practice Answers
  11. Key Takeaways

Lecture 003 — Python ML Libraries Tour

Category1 — ML Foundations
Lecture003 of 011
Estimated video length16 min
TargetPython 3.10+ · numpy, pandas, scikit-learn
LevelBeginner

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

Popular Python libraries for ML
LibraryRole
NumPyNumerical computing on large multi-dimensional arrays; vectorized math, linear algebra, random number generation.
PandasTabular data loading/cleaning/analysis via DataFrames and Series; built on top of NumPy.
Matplotlib / SeabornStatic plotting and statistical visualization (Seaborn is built on Matplotlib).
Scikit-learnThe classical-ML workhorse: classification, regression, clustering, preprocessing, and evaluation metrics, built on NumPy/SciPy.
TensorFlowGoogle's deep learning framework, good for large-scale/GPU-accelerated training; uses NumPy internally for tensor manipulation.
KerasHigh-level neural network API (often layered on TensorFlow) — good for fast prototyping.
PyTorchDeep 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:

python
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.txt so 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

  1. Which library is built on top of NumPy and adds labeled, tabular data structures?
  2. Why does this course mostly use scikit-learn instead of TensorFlow/PyTorch?
  3. What do fit() and predict() each do in the scikit-learn pattern?
  4. What is train_test_split protecting against?

Practice Answers

  1. Pandas.
  2. Most of the course covers classical ML (regression, classification, clustering) — problems scikit-learn solves faster, with less data, and more interpretably than deep learning.
  3. fit() trains the model on the training data; predict() applies the trained model to new, unseen inputs.
  4. 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_split keeps evaluation honest by holding out unseen data