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.
- Genetic Algorithm for Reinforcement Learning : Python implementation
- Epsilon-Greedy Algorithm in Reinforcement Learning
- Upper Confidence Bound Algorithm in Reinforcement Learning
- Reinforcement learning
- SARSA Reinforcement Learning
- Introduction to Thompson Sampling | Reinforcement Learning
- Neural Logic Reinforcement Learning - An Introduction
- Expected SARSA in Reinforcement Learning
- Learning Model Building in Scikit-learn : A Python Machine Learning Library
- ML | Types of Learning – Supervised Learning
- Introduction to Multi-Task Learning(MTL) for Deep Learning
- Artificial intelligence vs Machine Learning vs Deep Learning
- Learning to learn Artificial Intelligence | An overview of Meta-Learning
- How to Start Learning Machine Learning?
- Difference Between Artificial Intelligence vs Machine Learning vs Deep Learning
- Need of Data Structures and Algorithms for Deep Learning and Machine Learning
- Box Blur Algorithm - With Python implementation
- Page Rank Algorithm and Implementation
- Implementation of Perceptron Algorithm for NOT Logic Gate
- Implementation of Perceptron Algorithm for AND Logic Gate with 2-bit Binary Input
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.