You are on page 1of 21

1

Artificial Intelligence with


Machine Learning in Java
3-4
Yes/No Game

Copyright © 2020, Oracle and/or its affiliates. All rights reserved.

2
Objectives
• This lesson covers the following objectives:
−Describe the use of decision trees
−Create a Yes/No game
−State the problems of creating a manual decision tree

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 3

3
Decision Trees Revisited
• A previous topic in this course was decision trees
• An example of creating a decision tree solution is a
Yes/No game
• You will create a Yes/No game so that a user is asked a
series of yes or no questions about which animal they
are thinking about

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 4

4
Task – Yes or No Game
• Using a similar tree structure to that of a decision tree:
−If the computer guesses correctly, then the computer wins
−If the computer does not guess correctly, then the player wins
and the program "learns" where they went wrong
−At the start, the computer will know to only ask one question,
but will not know the answer to it!

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 5

5
Yes/No Game Flow
The game will go like this:
• Computer: Is it a Mammal? y/n
• User: y
• Computer: Is it a dog? y/n
• User: n
• Computer: You win. I give up. What were you thinking
of?
• User: Cat

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 6

6
Yes/No Game Flow
• Computer: What question would you ask to tell the
difference between a cat and a dog?
• User: Does it climb trees?
• Computer: And what would your answer to this
question be for a cat?
• User: Yes
• Computer: Let’s go again.
• Computer: Is it a Mammal? y/n
• User: y

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 7

7
Yes/No Game Flow
• Computer: Does it climb trees? y/n
• User: y
• Computer: Is it a cat? y/n
• User: y
• Computer: I win!!

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 8

8
Yes/No Game Example
• There is an example supplied of the Yes/No game
working with animals
• Unzip YesNoGameDemo.zip, and then run it by typing
in the console:
−java –jar YesNoGame.jar
• Or, if you have Windows, double-click the RunMe.Bat
file

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 9

9
Task – Create Yes/No Game
• As more users play, the program "learns" more about
animals
• Your task is to write this game
• Good luck!

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 10

10
Decision Trees Continued
• This is a basic insight on how a decision tree may work
• It doesn’t have to be used for a game, but could be
used to help diagnose a computer problem
• Example:
−Does your computer start
−Is it powering on
−Is it plugged in

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 11

11
Task - Manual Decision Trees Problems
• Think about if there are limitations with the Yes/No
game (and other manual approaches) to creating a
decision?
• Hint:
−It would be faster if the computer had first asked if the animal
"barks"

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 12

12
Manual Decision Trees
• It is faster (and more efficient) to know which question
should be first, and in which order to ask the questions
• The solution may ask 20 questions, and if ordered
properly, the answer could be found more quickly
• This is when the best decision tree algorithms come
into the picture
• Using sample data, questions will be determined to
have more importance
• This is called information entropy

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 13

13
Decision Trees Data Set
• A data set will be used to create a decision tree
• The starting data can be a table with a list of
predictors/attributes
• A typical scenario is to decide if someone is going to
play an outdoor sport like golf or tennis. (Quinlan,
1986)
• Data is collected over a period of time to see whether
the sport was played

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 14

14
Play Outdoor Sport
Num Outlook Temperature Humidity Wind Play?
1 Sunny Hot High Weak No
2 Sunny Hot High Strong No
3 Overcast Hot High Weak Yes
4 Rain Mild High Weak Yes
5 Rain Cold Normal Weak Yes
6 Rain Cold Normal Strong No
7 Overcast Cold Normal Strong Yes
8 Sunny Mild High Weak No
9 Sunny Cold Normal Weak Yes
10 Rain Mild Normal Weak Yes
11 Sunny Mild Normal Strong Yes
12 Overcast Mild High Strong Yes
13 Overcast Hot Normal Weak Yes
14 Rain Mild High Strong No

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 15

15
Play Sport
• The predictors/attributes here are Outlook,
Temperature, Humidity and Wind
• The target/classification/Outcome is Play
• Which predictor is the most important?
• If we were to create a decision flow chart then we
would want the biggest factor to be the first choice
• Even in a limited amount of data it would be quite a bit
of work to see if a user would be likely to play, or even
what percentage that would be depending on one of
the predictors

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 16

16
Decision Trees
• These are based around a tree structure where a yes or
no type answer is given, or one of the classifications
like sunny or overcast to a question, either leading to
another question or an outcome (classification)
• If you really want to see how tricky it is, then try and
create a serious of closed response questions that
would allow the Play Sport scenario to be tested and
give the correct result

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 17

17
Manual Decision Tree Creation
• Example - Set the root to be temperature and ask 3
questions
−Is it hot?
−Is it cold?
−Is it mild?
• Then ask questions under that and so on until every
test case has a path

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 18

18
Automatic Decision Trees
• As you should have already noticed, manually creating
decision trees is a fairly difficult and time consuming
task
• In our example we only had 14 rows
• Imagine if you had over 1000!
• This is when automatic creation of our decision trees
comes into place

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 19

19
Summary
• In this lesson, you should have learned how to:
−Describe the use of decision trees
−Create a yes/no game
−State the problems of creating a manual decision tree

AiML 3-4
Yes/No Game Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 20

20
21

You might also like