Saturday, 28 February 2015

Review 2.3: Modeling with Decision Trees - Classify using a Decision Tree

The code of classifying using a decision tree is as following:

def classify(item:List[String], dtree:DTreeNode):Option[Map[String,Int]] = {
  if (dtree.result!=None)
   return dtree.result
  if (dtree.colIndex==None)
   return None
  val (set1, set2) = divide(List(item), dtree.colIndex.get , dtree.split)
  if (set1.length!=0) {
   if (dtree.left==None)
    return None
   return classify(item,dtree.left.get)
  if (set2.length!=0) {
   if (dtree.right==None)
    return None
   return classify(item,dtree.right.get)
  return None

The result of classifying item [google,UK,yes,21] using the constructed decision tree.

No comments:

Post a Comment