Skip to content

SercanKaraoglu/decision-tree-impl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

decision-tree-impl

Scala implementation trial for Decision Tree

this is not just cool, tail-recursion in Scala is more than that.

def classify(tree: Tree, testSource: Vector[Row]): Vector[Any] = {
    @tailrec def classifier(t: Tree, observation: Row): Any = t match {
      case Node(attrId: Int, value: String, leftBranch: Tree, rightBranch: Tree) => if (value == observation.getString(attrId)) classifier(leftBranch, observation) else classifier(rightBranch, observation)
      case Node(attrId: Int, value: Double, leftBranch: Tree, rightBranch: Tree) => if (value > observation.getDouble(attrId)) classifier(leftBranch, observation) else classifier(rightBranch, observation)
      case NonEmptyLeaf(targetValues: ValueSet) => targetValues.head
      case EmptyLeaf() => Nil
    }

    testSource.map(classifier(tree, _))
 }

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages