Machine Learning - Spring 2004
==============================
Lab experiments 4
-----------------
Programs needed: lgg.pl
Data files: animals.pl
---------------------------
GENERATING, VIEWING AND ACCESSING RULES CREATED BY LGG
------------------------------------------------------
?- ['c:/prolog/lgg'].
?- ['c:/prolog/animals'].
?- listing(example). THIS IS JUST TO SEE THE EXMAPLES, AS THEY WILL BE THEN COMBINED BY LGG
example(1, mammal, [has_covering=hair, milk=t, homeothermic=t, habitat=land, eggs=f, gills=f]).
example(2, mammal, [has_covering=none, milk=t, homeothermic=t, habitat=sea, eggs=f, gills=f]).
example(3, mammal, [has_covering=hair, milk=t, homeothermic=t, habitat=sea, eggs=t, gills=f]).
example(4, mammal, [has_covering=hair, milk=t, homeothermic=t, habitat=air, eggs=f, gills=f]).
example(5, fish, [has_covering=scales, milk=f, homeothermic=f, habitat=sea, eggs=t, gills=t]).
example(6, reptile, [has_covering=scales, milk=f, homeothermic=f, habitat=land, eggs=t, gills=f]).
example(7, reptile, [has_covering=scales, milk=f, homeothermic=f, habitat=sea, eggs=t, gills=f]).
example(8, bird, [has_covering=feathers, milk=f, homeothermic=t, habitat=air, eggs=t, gills=f]).
example(9, bird, [has_covering=feathers, milk=f, homeothermic=t, habitat=land, eggs=t, gills=f]).
example(10, amphibian, [has_covering=none, milk=f, homeothermic=f, habitat=land, eggs=t, gills=f]).
?- lrn.
example((8, 9), bird, [has_covering=feathers, milk=f, homeothermic=t, eggs=t, gills=f])
example((6, 7), reptile, [has_covering=scales, milk=f, homeothermic=f, eggs=t, gills=f])
example((((1, 2), 3), 4), mammal, [milk=t, homeothermic=t, gills=f])
example(5, fish, [has_covering=scales, milk=f, homeothermic=f, habitat=sea, eggs=t, gills=t])
example(10, amphibian, [has_covering=none, milk=f, homeothermic=f, habitat=land, eggs=t, gills=f])
NOTE that while working the algorithm prints the lgg's of the examples/hypotheses it picks.
The ID's of these examples are then put in parentheses. In this way the lgg that has been
created is shown as a binary tree where the leaves are the original examples.
At the same time the algorithm creates rules that are in fact the same as the generalized examples
shown above. These rules are represented in the same format as the ones created by ID3.
To see the rules we may use listing(if), as shown below.
?- listing(if).
if[has_covering=feathers, milk=f, homeothermic=t, eggs=t, gills=f]then bird.
if[has_covering=scales, milk=f, homeothermic=f, eggs=t, gills=f]then reptile.
if[milk=t, homeothermic=t, gills=f]then mammal.
if[has_covering=scales, milk=f, homeothermic=f, habitat=sea, eggs=t, gills=t]then fish.
if[has_covering=none, milk=f, homeothermic=f, habitat=land, eggs=t, gills=f]then amphibian.
Or we may access the rules directly and use "model" to see their coverage:
?- if H then C,model(H,M).
H = [has_covering=feathers, milk=f, homeothermic=t, eggs=t, gills=f]
C = bird
M = [8, 9] ;
H = [has_covering=scales, milk=f, homeothermic=f, eggs=t, gills=f]
C = reptile
M = [6, 7] ;
H = [milk=t, homeothermic=t, gills=f]
C = mammal
M = [1, 2, 3, 4] ;
H = [has_covering=scales, milk=f, homeothermic=f, habitat=sea, eggs=t, gills=t]
C = fish
M = [5] ;
H = [has_covering=none, milk=f, homeothermic=f, habitat=land, eggs=t, gills=f]
C = amphibian
M = [10]