concept action in category machine learning

This is an excerpt from Manning's book Machine Learning with TensorFlow, Second Edition.
If the 70-30 split seems odd to you, think about it like this. Let’s say your physics teacher gives you a practice exam and tells you the real exam will be no different. You might as well memorize the answers and earn a perfect score without understanding the concepts. Similarly, if you test your model on the training dataset, you’re not doing yourself any favors. You risk a false sense of security, because the model may merely be memorizing the results. Now, where’s the intelligence in that?
Instead of the 70-30 split, machine-learning practitioners typically divided their dataset 60-20-20. Training consumes 60% of the dataset, and testing uses 20%, leaving the other 20% for validation, which is explained in the next chapter.
You learn what makes people happy, for example, by interacting with friends, family, or even strangers, and you figure out how to ride a bike by trying out various muscle movements until riding just clicks. When you perform actions, you’re sometimes rewarded immediately. For example, finding a good restaurant nearby might yield instant gratification. Other times, the reward doesn’t appear right away, such as traveling a long distance to find an exceptional place to eat. Reinforcement learning is about choosing the right actions, given any state—such as in figure 13.1, which shows a person making decisions to arrive at their destination.
Whereas supervised and unsupervised learning appear at opposite ends of the spectrum, reinforcement learning (RL) exists somewhere in the middle. It’s not supervised learning, because the training data comes from the algorithm deciding between exploration and exploitation. And it’s not unsupervised, because the algorithm receives feedback from the environment. As long as you’re in a situation where performing an action in a state produces a reward, you can use reinforcement learning to discover a good sequence of actions to take that maximize expected rewards.
You may notice that reinforcement-learning lingo involves anthropomorphizing the algorithm into taking actions in situations to receive rewards. The algorithm is often referred to as an agent that acts with the environment. It shouldn’t be a surprise that much of reinforcement-learning theory is applied in robotics. Figure 13.2 demonstrates the interplay between states, actions, and rewards.
Figure 13.2 Actions are represented by arrows, and states are represented by circles. Performing an action on a state produces a reward. If you start at state s1, you can perform action a1 to obtain a reward r(s1, a1).
![]()
Most reinforcement-learning algorithms follow similar implementation patterns. As a result, it’s a good idea to create a class with the relevant methods to reference later, such as an abstract class or interface. See the following listing for an example and figure 13.7 for an illustration. Reinforcement learning needs two operations well defined: how to select an action, and how to improve the utility Q-function.
Figure 13.7 Most reinforcement-learning algorithms boil down to just three main steps: infer, do, and learn. During the first step, the algorithm selects the best action (a), given a state (s), using the knowledge it has so far. Next, it does the action to find out the reward (r) as well as the next state (s'). Then it improves its understanding of the world by using the newly acquired knowledge (s, r, a, s').
![]()
Listing 13.5 Defining a superclass for all decision policies
class DecisionPolicy: def select_action(self, current_state): #A pass def update_q(self, state, action, reward, next_state): #B passNext, let’s inherit from this superclass to implement a policy where decisions are made at random, otherwise known as a random decision policy. You need to define only the select_action method, which will randomly pick an action without even looking at the state. The following listing shows how to implement it.
Lisitng 13.6 Implementing a random decision policy
class RandomDecisionPolicy(DecisionPolicy): #A def __init__(self, actions): self.actions = actions def select_action(self, current_state): #B action = random.choice(self.actions) return action

This is an excerpt from Manning's book Machine Learning with TensorFlow.
Unlike supervised learning, where training data is conveniently labeled by a “teacher,” reinforcement learning trains on information gathered by observing how the environment reacts to actions. Reinforcement learning is a type of machine learning that interacts with the environment to learn which combination of actions yields the most favorable results. Because we’re already anthropomorphizing algorithms by using the words environment and action, scholars typically refer to the system as an autonomous agent. Therefore, this type of machine learning naturally manifests itself in the domain of robotics.
To reason about agents in the environment, we introduce two new concepts: states and actions. The status of the world frozen at a particular time is called a state. An agent may perform one of many actions to change the current state. To drive an agent to perform actions, each state yields a corresponding reward. An agent eventually discovers the expected total reward of each state, called the value of a state.
Like any other machine-learning system, performance improves with more data. In this case, the data is a history of previous experiences. In reinforcement learning, we don’t know the final cost or reward of a series of actions until it’s executed. These situations render traditional supervised learning ineffective, because we don’t know exactly which action in the history of action sequences is to blame for ending up in a low-value state. The only information an agent knows for certain is the cost of a series of actions that it has already taken, which is incomplete. The agent’s goal is to find a sequence of actions that maximizes rewards.
You learn what makes people happy, for example, by interacting with friends, family, or even strangers, and you figure out how to ride a bike by trying out various muscle movements until riding just clicks. When you perform actions, you’re sometimes rewarded immediately. For example, finding a good restaurant nearby might yield instant gratification. Other times, the reward doesn’t appear right away, such as traveling a long distance to find an exceptional place to eat. Reinforcement learning is about making the right actions, given any state—such as in figure 8.1, which shows a person making decisions to arrive at their destination.
Most reinforcement-learning algorithms follow similar implementation patterns. As a result, it’s a good idea to create a class with the relevant methods to reference later, such as an abstract class or interface. See the following listing for an example and figure 8.7 for an illustration. Reinforcement learning needs two operations well defined: how to select an action, and how to improve the utility Q-function.
2 Improve the Q-function from a new experience of taking an action. Figure 8.7. Most reinforcement-learning algorithms boil down to just three main steps: infer, do, and learn. During the first step, the algorithm selects the best action (a), given a state (s), using the knowledge it has so far. Next, it does the action to find out the reward (r) as well as the next state (s’). Then it improves its understanding of the world by using the newly acquired knowledge (s, r, a, s’).
![]()
Next, let’s inherit from this superclass to implement a policy where decisions are made at random, otherwise known as a random decision policy. You need to define only the select_action method, which will randomly pick an action without even looking at the state. The following listing shows how to implement it.

This is an excerpt from Manning's book Algorithms of the Intelligent Web, Second Edition.
Listing 2.4. The k-means algorithm in action
from sklearn.cluster import KMeans from sklearn import datasets iris = datasets.load_iris() X = iris.data #1 km = KMeans(n_clusters=3) #2 km.fit(X) print(km.labels_) #1 - Contains only the data, not the labels #2 - Passes in the value of k, which in this case is equal to 3
For two cities, you’d use their longitude and latitude coordinates to calculate their geographical proximity. Think of the ratings as the coordinates in the space of items or users. Let’s look at these concepts in action. We’ll select three users and associate with them a list of movies (items) and their hypothetical rankings. As is typically the case, ratings will range between 1 and 5 (inclusive). The assignments for the first two users (Frank and Constantine) involve ratings that are either 4 or 5—these people really like all the movies we selected. But the third user’s ratings (Catherine’s) are between 1 and 3. So clearly, we expect the first two users to be similar to each other and be dissimilar to the third user. When we load the example data in the script, we have available the users, movies, and ratings shown in table 3.1.
Figure 7.5. Probability density function over the beliefs in payout probabilities for each bandit. Note that the three plots are identical and that the area under the curve is equal to 1. This illustrates our belief that all payout probabilities are equally likely for each bandit. This will change as we observe the bandits in action.
![]()

This is an excerpt from Manning's book Mahout in Action.
Figure 9.1. K-means clustering in action. Starting with three random points as centroids (top left), the map stage (top right) assigns each point to the cluster nearest to it. In the reduce stage (bottom left), the associated points are averaged out to produce the new location of the centroid, leaving you with the final configuration (bottom right). After each iteration, the final configuration is fed back into the same loop until the centroids come to rest at their final positions.
![]()