This device is not compatible.


Train an Agent to Self-Drive a Taxi using Reinforcement Learning

In this project, we’ll train an agent to pick up passengers and drop them at their destination in the fastest way possible using reinforcement learning algorithms built from scratch. We’ll use the Gymnasium library to simulate the environment and Matplotlib to plot the learning curves.

Train an Agent to Self-Drive a Taxi using Reinforcement Learning

You will learn to:

Perform reinforcement learning.

Work with Gymnasium environments (formerly OpenAI Gym).

Train and test a Q-learning agent.

Train and test a SARSA agent.


Machine Learning


Reinforcement Learning

Autonomous Vehicles


Programming in Python

Basic knowledge of machine learning



Gymnasium logo



Project Description

In this project, we’ll use reinforcement learning to train an agent to become a taxi driver whose job is to pick up passengers and bring them to their destination in the fastest way possible.
We’ll first learn how to work with the Gymnasium API (formerly Open AI Gym), which is a standard API for developing and comparing reinforcement learning algorithms, and explore the properties of the Taxi environment.
Then, we’ll implement two popular reinforcement learning algorithms: Q-learning, which is an off-policy algorithm, and SARSA, which is an on-policy algorithm. We’ll implement both algorithms from scratch in Python and then use them to train and test the taxi driver.
Finally, we’ll plot the learning curves of the algorithms and compare their performance.

The Taxi environment
The Taxi environment

Project Tasks


Getting Started

Task 0: Introduction


The Taxi Environment

Task 1: Explore The Taxi Environment

Task 2: Implement a Basic Agent-Environment Interaction Loop


Build the Q-Learning Agent

Task 3: Implement the Q-Learning Algorithm

Task 4: Train the Q-Learning Agent

Task 5: Fine-Tune the Hyperparameters

Task 6: Display the Learning Curve

Task 7: Show the Learned Policy in Action


Build the SARSA Agent

Task 8: Implement the SARSA Algorithm

Task 9: Train and Test the SARSA Agent