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.

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. Data Science With Python Core Skills

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

    Prerequisite

  2. 1

    Math for Data Science

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

    7 resources

  3. 2

    Machine Learning With Python

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

    58 resources · Ends with a knowledge check

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.

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.

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

What should I know before I start?

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.

How much math do I need?

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.

Should I learn PyTorch or TensorFlow?

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.

How is this different from building AI apps?

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.

What’s included in a membership?

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.