nimblebox logo
Docs
v3.3.1b

Q-learning Blackjack

Here's the code for this specimen on Github

NimbleBox Projects provide a simple way to manage all the complexities of training and deploying your models. In this code we will see how to use NimbleBox Projects to train a Q-learning agent to play Blackjack. Here's all the parts we are going to use:

The code for this blog is taken from Farama-Foundation's gymnasium

Key Concepts

Here's some things about this project you should know

Q-LearningQ-learning is a reinforcement learning algorithm where we learn to predict the best action to take in a given state. It is a model-free algorithm, which means that it does not require a model of the environment.Read more
gymnasiumgymnasium is a toolkit for developing and comparing reinforcement learning algorithms. It supports teaching agents everything from walking to playing games like Pong or Pinball. It's a follow up to OpenAI's gym.Read more
Experiment TrackerVisualise your training metrics with charts and tables, recreate exactly where you left off and compare to make decisions. Run any computation on NBX-Jobs.Read more

🍇 Step 1: Create a new Project

Go to NimbleBox dashboard and click on "New Project" button to create your project. Once complete, open it and copy the project ID.

🦾 Step 2: Upload the code

You can get the full code from here. A quick overview of the code:

  • BlackJackAgent: this class is the single learning agent that contains the q_values table
  • create_grid and create_plots: are helper functions to create the plots
  • main: contains the code to create an environment and train the agent

Here's all the code we have added:

Python
Loading...

🥨 Step 3: Train the agent

To train the agent we will run this with different parameters all we need to do is run the following commands:

Shell
Loading...

Once the training is done this is how the plots will look like:

Project on NimbleBox

🃏 Bottomline

You can see how easy it is to build train and store your agents on NimbleBox.

nbox SDKnbox provides built in access to all the APIs and packages them in the most user friendly manner.Star 0