Java Reference
In-Depth Information
The values of the features and the categories can be represented in
different ways. A generic solution could use Object to represent them. In
practice the use of String is flexible enough for most uses and has the
advantage of providing an immediate representation.
In our survey of the literature we focused on a simple kind of classifier:
decision trees. There are several other types of classifiers, the system should
be open to use on of them.
Decision point
How do we accommodate different types of classifiers?
Instead of providing a single classifier class we define the interface Classifier ,
which defines the method assignCategory . This method can be implemented
in different ways by different types of classifiers. In this chapter we will
develop only a decision tree classifier that is implemented by the DecisionTree
class.
As far as the decision tree classifier is concerned, we keep the same
classes, identified during the analysis phase, but we change the associations
between them. The design of these classes is shown in Figure 4.6.
Decision point
How can we implement the typed association Arc ?
Instead of having a Node object directly connected to its children we
insert an Arc object in between. This object is intended to contain the label
of the link. Also, class Node contains an attribute that represents the label of
the node. Since the tree is basically a static structure that remains stable
after it has been built, both label attributes are read-only.
DecisionTree
`` Interface pp
Classifier
! assignCategory()
! assignCategory()
! root
1
! children
Node
Arc
0 .. n
<<read only>> label : String
`` read only pp label : String
1
! destination
Figure 4.6 Decision tree classes
 
Search WWH ::




Custom Search