{"id":3202,"date":"2025-10-06T16:08:23","date_gmt":"2025-10-06T14:08:23","guid":{"rendered":"https:\/\/tecnologia.euroinnova.com\/que-es-el-q-learning-y-como-funciona-este-aprendizaje-por-refuerzo\/"},"modified":"2026-08-05T11:04:58","modified_gmt":"2026-08-05T09:04:58","slug":"q-learning","status":"publish","type":"post","link":"https:\/\/tecnologia.euroinnova.com\/en\/q-learning","title":{"rendered":"What is Q-learning and how does this reinforcement learning work?"},"content":{"rendered":"<p dir=\"ltr\">Q-learning is a<strong> a machine learning technique that enables a model to learn through repetition and improve over time<\/strong> with a learning approach typical of mammals. It is a form of reinforcement learning that usually uses Python as its preferred programming language.<\/p>\n<p dir=\"ltr\">In a way, Q-learning <strong>imitates the way in which young children and animals carry out certain actions<\/strong> as good or bad. Thus, when an action is classified as good, the individual is rewarded, whilst when it is classified as bad, they are penalised.<\/p>\n<h2 dir=\"ltr\" id=\"como-funciona-el-q-learning\">How does Q-learning work?<\/h2>\n<p dir=\"ltr\">We\u2019re going to explain how Q-learning works in simple terms, using an example to make it clearer. Essentially, Q-learning is a method that helps an agent (such as a robot, a programme, etc.) learn to make the best decisions in a given environment in order to achieve the highest possible reward.<\/p>\n<p dir=\"ltr\">Imagine a game where <strong>A robot must move around a grid to find a treasure.<\/strong> The grid has different positions (states), and the robot can move up, down, left or right (actions).<\/p>\n<p dir=\"ltr\">Let\u2019s define a couple of <strong>key terms in reinforcement learning <\/strong>in order to explain how Q-learning works:<\/p>\n<ul>\n<li dir=\"ltr\" aria-level=\"1\">\n<p dir=\"ltr\" role=\"presentation\"><strong>States (S):<\/strong> These are the different positions on the grid. Each position represents a state.<\/p>\n<\/li>\n<li dir=\"ltr\" aria-level=\"1\">\n<p dir=\"ltr\" role=\"presentation\"><strong>Shares (A):<\/strong> These are the robot\u2019s possible movements: up, down, left, right.<\/p>\n<\/li>\n<li dir=\"ltr\" aria-level=\"1\">\n<p dir=\"ltr\" role=\"presentation\"><strong>Reward (R):<\/strong> This is what the robot gains or loses after making a move. For example, +10 points for finding the treasure and -1 point for every move that does not lead to the treasure. The value of the rewards will depend on how we configure the Q-learning algorithm.<\/p>\n<\/li>\n<li dir=\"ltr\" aria-level=\"1\">\n<p dir=\"ltr\" role=\"presentation\"><strong>Q-value (Q):<\/strong> It is a figure that tells us how effective it is for the robot to perform a certain action from a certain position.<\/p>\n<\/li>\n<\/ul>\n<h3 dir=\"ltr\" id=\"que-es-una-q-table-o-tabla-q\">What is a Q-table?<\/h3>\n<p dir=\"ltr\">Before we explain how this machine learning technique works, we need to explain what a Q-table is. A Q-table, or Q-table, <strong>is a table or matrix that uses the Q-learning algorithm to store information<\/strong> on the best actions that an agent (such as a robot or a programme) should take in different states to maximise its long-term reward.<\/p>\n<p dir=\"ltr\">The Q-table has the following features:<\/p>\n<ol>\n<li dir=\"ltr\" aria-level=\"1\">\n<p dir=\"ltr\" role=\"presentation\"><strong>Rows: <\/strong>Each row of the table represents a possible state in which the agent may find itself.<\/p>\n<\/li>\n<li dir=\"ltr\" aria-level=\"1\">\n<p dir=\"ltr\" role=\"presentation\"><strong>Columns:<\/strong> Each column in the table represents an action that the agent can take from that state.<\/p>\n<\/li>\n<li dir=\"ltr\" aria-level=\"1\">\n<p dir=\"ltr\" role=\"presentation\"><strong>Cells (Q-values, Q(s, a)): <\/strong>Each cell in the table contains a Q-value, which is a number indicating the quality of taking a specific action in a specific state. The higher the Q-value, the better that action is considered to be in that state (Bellman equation).<\/p>\n<\/li>\n<\/ol>\n<h3 dir=\"ltr\" id=\"proceso-de-q-learning\">Q-learning process<\/h3>\n<p dir=\"ltr\">Now, let\u2019s explain how our agent goes about improving its responses until it achieves an optimal result:<\/p>\n<h4 dir=\"ltr\">Initialisation<\/h4>\n<p dir=\"ltr\">We start with a Q-table full of zeros. This means that the agent has no information about which action is best in any state. This table has one row for each state (position on the grid) and one column for each action (possible moves).<\/p>\n<p dir=\"ltr\">Let\u2019s visualise the Q-table for this same example. The robot must find the treasure on a 2\u00d72 grid. Therefore, on the grid we represent four states (positions in which the robot can be found) which we can express in coordinates. The robot, for its part, has a range of four actions it can perform (move up, down, right or left). This is what the Q-table would look like:<\/p>\n<h5>Example of a Q-table\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0<\/h5>\n<table border=\"1\">\n<tbody>\n<tr>\n<th>Status<\/th>\n<th>Top<\/th>\n<th>Below<\/th>\n<th>Left<\/th>\n<th>Right<\/th>\n<\/tr>\n<tr>\n<td>(0,0)<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>(0,1)<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>(1,0)<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<tr>\n<td>(1,1)<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<td>0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4 dir=\"ltr\">Shares<\/h4>\n<p dir=\"ltr\">It is now up to the agent to decide what action to take. If the agent has not received any reward or penalty from the Q-learning algorithm, it will act randomly. If it has been trained previously, it will make decisions based on its past experiences.<\/p>\n<h4 dir=\"ltr\">Update<\/h4>\n<p dir=\"ltr\">The robot receives rewards or penalties \u2013 that is, positive or negative feedback \u2013 depending on whether its position is getting closer to or further away from the treasure. Every time the robot moves, the Q-table must update the calculation of rewards for each combination of actions performed by the robot, depending on its current state.<\/p>\n<h4 dir=\"ltr\">Iteration and termination<\/h4>\n<p dir=\"ltr\">This process is iterative; in other words, it is repeated until the Q-learning model can take no further actions and reaches a termination state, ideally having achieved a satisfactory outcome. Each time the algorithm terminates, this is called an episode.<\/p>\n<h2 dir=\"ltr\" id=\"aplicaciones-reales-del-q-learning\">Real-world applications of Q-learning<\/h2>\n<p dir=\"ltr\">The theory is all well and good, but what\u2019s the point of it all? Q-learning, like any other machine learning technique, can be put to practical use in many disciplines. Here are a few examples:<\/p>\n<ul>\n<li dir=\"ltr\" aria-level=\"1\">\n<p dir=\"ltr\" role=\"presentation\"><strong>Robotics: <\/strong>Robots can use Q-learning to learn how to navigate unfamiliar environments, avoid obstacles and achieve specific objectives.<\/p>\n<\/li>\n<li dir=\"ltr\" aria-level=\"1\">\n<p dir=\"ltr\" role=\"presentation\"><strong>Video games: <\/strong>It is used to create TASs (tool-assisted speedruns) that can play and improve performance in video games, ranging from simple games such as chess to complex ones such as StarCraft.<\/p>\n<\/li>\n<li dir=\"ltr\" aria-level=\"1\">\n<p dir=\"ltr\" role=\"presentation\"><strong>Autonomous driving: <\/strong>Cars learn to drive safely by obeying traffic signs and reacting appropriately to different situations on the road.<\/p>\n<\/li>\n<li dir=\"ltr\" aria-level=\"1\">\n<p dir=\"ltr\" role=\"presentation\"><strong>Product recommendations:<\/strong> It improves recommendations on platforms such as Netflix, YouTube and Amazon by learning from users\u2019 preferences and adapting to their tastes at all times.<\/p>\n<\/li>\n<li dir=\"ltr\" aria-level=\"1\">\n<p dir=\"ltr\" role=\"presentation\"><strong>Industry and manufacturing: <\/strong>Anticipate machinery failures and plan maintenance to minimise downtime.<\/p>\n<\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>El Q-learning es una t\u00e9cnica de aprendizaje autom\u00e1tico que permite a un modelo aprender a base de repeticiones y mejorar [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":757,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3202","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sin-categorizar"],"acf":[],"_links":{"self":[{"href":"https:\/\/tecnologia.euroinnova.com\/en\/wp-json\/wp\/v2\/posts\/3202","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tecnologia.euroinnova.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tecnologia.euroinnova.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tecnologia.euroinnova.com\/en\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tecnologia.euroinnova.com\/en\/wp-json\/wp\/v2\/comments?post=3202"}],"version-history":[{"count":0,"href":"https:\/\/tecnologia.euroinnova.com\/en\/wp-json\/wp\/v2\/posts\/3202\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/tecnologia.euroinnova.com\/en\/wp-json\/wp\/v2\/media\/757"}],"wp:attachment":[{"href":"https:\/\/tecnologia.euroinnova.com\/en\/wp-json\/wp\/v2\/media?parent=3202"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tecnologia.euroinnova.com\/en\/wp-json\/wp\/v2\/categories?post=3202"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tecnologia.euroinnova.com\/en\/wp-json\/wp\/v2\/tags?post=3202"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}