The purpose of this post is to demonstrate a basic example of how machine learning works.
In this example, the computer learns how to play a game of Top Trumps more effectively to increase its chance of winning the game.
It does so by running a learning sequence. During this learning sequence its machine learning algorithm pick two random cards from the deck and compare them against a random criteria.
Based on which card wins the round, it updates its knowledge base accordingly. By repeating this process many times (number of iterations), the algorithm records in its knowledge base statistics for each category of each card. (Probability of winning the round)
The algorithm hence progressively learns which criteria has the highest probability of winning and records this information for each card of the deck.
These probabilities become more accurate when you increase the number of iterations of the learning sequence.
Use the buttons provided in the code pen below to show the impact of the learning phase on the knowledge base.
See the Pen Machine Learning Top Trumps by 101 Computing (@101Computing) on CodePen.
Machine Learning?
Let’s consider the following definition of Machine Learning:
Let’s apply this defintion to our Top Trumps Machine Learning algorithm:
- E: (The Experience/learning sequence): The experience consists of randomly picking two cards and comparing them against a criteria to see which card would win the round.
- T: (The Task): Playing a full game of Top Trumps against an end-user.
- P: (The Performance Measure): The probability of winning the game.
In our example, the probability (P) of winning a game of Top Trumps (T) increases with the number of iterations of the learning sequence (Experience E).
So we effectively have a machine learning algorithm.
Obviously, with a fixed data sets of 9 cards and 4 criteria per card, the learning is limited. More complex scenarios use a similar approach with larger data sets which are often open/limitless and where the computer can constantly learn and improve the accuracy of its knowledge base by either analysing existing data sets or populating new data by interacting with real end-users/human beings.
Next Step?
To complete this algorithm, the next step would be to implement the playing phase, where the computer should use its knowledge base to play against an end-user.




Start by setting the starting node (A) as the current node.
Check all the nodes connected to A and update their “Shortest Distance from A” and set their “previous node” to “A”.
Set the current node (A) to “visited” and use the unvisited node with the smallest total distance as the current node (e.g. in this case: Node C).

Check all unvisited nodes connected to the current node (E) and add the distance from A to E to all distances from the connected nodes. Replace their values only if the new distance is lower than the previous one.
We found a path from A to Z, but is it the shortest one?


Start by setting the starting node (A) as the current node.
Check all the nodes connected to A and update their “Distance from A” and set their “previous node” to “A”.
Set the current node (A) to “visited” and use the closest unvisited node to A as the current node (e.g. in this case: Node C).
Check all unvisited nodes connected to the current node and add the distance from A to C to all distances from the connected nodes. Replace their values only if the new distance is lower than the previous one.
Set the current node C status to Visited.
B -> D 3+5 = 8 < 10 – Change Node D
D -> E 8+2 = 10 < 12 – Change Node E
E -> Z 10+5 = 15 > 14 – We do not change node Z.
We found the shortest path from A to Z.



















In our previous blog post, 













