Skill area · Machine Learning

Teach your programs to learn from data

Train, evaluate, and understand machine learning and AI models in Python

Real Python takes you from your first regression model to neural networks, computer vision, and natural language processing with scikit-learn, NumPy, PyTorch, and TensorFlow. Learn how the algorithms work, not just which function to call.

Machine Learning on Real Python

What you’ll be able to do

From first model to deep learning, step by step

Machine learning is easier to trust when you understand what’s happening underneath. Real Python builds your intuition first, then shows you the libraries professionals use.

Prepare and evaluate

Split your data into training and test sets, and measure how well a model really performs on data it hasn’t seen.

scikit-learnNumPy

Train classic models

Fit linear and logistic regression, classify with k-nearest neighbors, and find groups with k-means clustering.

regressionkNNk-means

Build neural networks

Write a neural network from scratch to see how it learns, then move up to deep learning frameworks.

PyTorchTensorFlowKeras

Work with images, text, and audio

Detect and recognize faces, classify sentiment in text, and turn speech and audio into model-ready data.

OpenCVNLTKspaCy

Your roadmap

A clear path into machine learning

Machine learning builds on working with data and a bit of math. Follow these learning paths in order, or jump in where you’re ready. Each one mixes tutorials, video courses, quizzes, and exercises, and tracks your progress as you go.

  1. ✓

    Prerequisite

    Load, clean, and explore data with pandas, NumPy, and Matplotlib. If you can already do this comfortably, skip ahead.

    Learning Path

    Data Science With Python Core Skills

    22 Resources ⋅ Skills: Pandas, NumPy, Data Cleaning, Data Visualization, Statistics, CSV, JSON, Jupyter Notebooks

  2. 1

    Build the foundations models rely on: statistics, correlation, linear and logistic regression, and gradient descent, all explained with Python code.

    Learning Path

    Math for Data Science

    5 Resources ⋅ Skills: Statistics, Correlation, Linear Regression, Logistic Regression, NumPy, SciPy, pandas, Gradient Descent

  3. 2

    Ends with a knowledge check

    Go from machine learning principles and your first neural network to computer vision, natural language processing, and algorithms like kNN, k-means, and GANs.

    Learning Path

    Machine Learning With Python

    31 Resources ⋅ Skills: Image Processing, Computer Vision, Text Classification, Speech Recognition, NLP, Deep Learning, LLMs, RAG

Need a refresher on working with data first? See Data Science & Analytics. Want to build apps on top of large language models? Continue with Building AI Apps & Agents.

Try it now

Build a linear regression model

This is a real exercise from the Starting With Linear Regression in Python video course, using the same data as the notebook above. Write your function in the editor and click Run Tests.

Loading exercise...

Running tests, hints, and solutions are included with a Real Python membership. Not a member yet? You can still read the task and write your solution before you join.

Learn it every way

Read it, watch it, test it, practice it

Every machine learning topic comes in the formats that help it stick. Mix them however you like.

Tutorials

In-depth guides that explain the ideas behind each algorithm and walk you through working code.

Browse tutorials →

Video courses

Watch an instructor build models step by step, from linear regression to your own neural network.

Build a neural network →

Quizzes

Check what you’ve learned in a few minutes and see exactly which concepts to review.

Test your ML knowledge →

Coding exercises

Fit scikit-learn models and write a neural network’s forward pass and training step in your browser.

How exercises work →

Mentor AI

Confused by a shape error? Ask right where you are

Machine learning code fails in ways that can feel cryptic: an “Expected 2D array” error, a model that scores perfectly in training and poorly on new data, or a loss that won’t go down.

Mentor AI sees the tutorial, lesson, or exercise you’re on and your code, and nudges you toward the fix one hint at a time, so you understand what your model is actually doing.

Meet Mentor AI →

The machine learning toolkit

Learn the libraries behind real ML projects

From the foundations every model builds on to specialized tools for images, text, and audio.

scikit-learn
Classic ML
NumPy
Arrays & math
PyTorch
Deep learning
TensorFlow
Deep learning
Keras
Neural networks
Gradient descent
How models learn
OpenCV
Computer vision
face_recognition
Face recognition
NLTK
Text processing
spaCy
NLP pipelines
TorchAudio
Audio data
DVC
Data versioning

Fresh from the library

Recently added

The Real Python team keeps adding machine learning tutorials, quizzes, and hands-on exercises, so you can practice what you read.

See all machine learning content →

Questions and answers

You should be comfortable with Python basics and with loading and exploring data in pandas and NumPy. If you’re not there yet, start with Data Science & Analytics, or with the Python Basics learning path if you’re new to Python.

Less than you might think to get started, since libraries handle the heavy lifting. Understanding a few ideas like regression and gradient descent helps you choose and debug models, and the Math for Data Science path explains them with Python code rather than proofs.

Start with scikit-learn for classic machine learning. When you’re ready for deep learning, both frameworks are good choices. PyTorch vs TensorFlow compares them so you can pick the one that fits your project.

Machine learning is about training and evaluating your own models on your own data. Building AI apps and agents focuses on using existing large language models through APIs and frameworks. If that’s your goal, see Building AI Apps & Agents.

Every Real Python membership includes all video courses, quizzes, coding exercises, and learning paths for machine learning and every other topic, along with Mentor AI as it rolls out.

Start building models that learn

Get your free learning plan and follow the full machine learning roadmap, with courses, quizzes, coding exercises, and a mentor at your side.

Get your free learning plan