Prerequisites: Q-Learning technique.
Reinforcement Learning is a type of Machine Learning paradigms in which a learning algorithm is trained not on preset data but rather based on a feedback system. These algorithms are touted as the future of Machine Learning as these eliminate the cost of collecting and cleaning the data.
In this article, we are going to demonstrate how to implement a basic Reinforcement Learning algorithm which is called the Q-Learning technique. In this demonstration, we attempt to teach a bot to reach its destination using the Q-Learning technique.
Step 1: Importing the required libraries
Step 2: Defining and visualising the graph
Note: The above graph may not look the same on reproduction of the code because the networkx library in python produces a random graph from the given edges.
Step 3: Defining the reward the system for the bot
Step 4: Defining some utility functions to be used in the training
Step 5: Training and evaluating the bot using the Q-Matrix
Now, Let’s bring this bot to a more realistic setting. Let us imagine that the bot is a detective and is trying to find out the location of a large drug racket. He naturally concludes that the drug sellers will not sell their products in a location which is known to be frequented by the police and the selling locations are near the location of the drug racket. Also, the sellers leave a trace of their products where they sell it and this can help the detective in finding out the required location. We want to train our bot to find the location using these Environmental Clues.
Step 6: Defining and visualizing the new graph with the environmental clues
Note: The above graph may look a bit different from the previous graph but they, in fact, are the same graphs. This is due to the random placement of nodes by the
Step 7: Defining some utility functions for the training process
Step 8: Visualising the Environmental matrices
Step 9: Training and evaluating the model
The example taken above was a very basic one and many practical examples like Self Driving Cars involve the concept of Game Theory.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course