DecisionTree

public class DecisionTree

Undocumented

  • training data set whole as inputed by user in init

    Declaration

    Swift

    public var originalDataSet: DataSet
  • root node of the decision tree

    Declaration

    Swift

    public var root: Node?
  • max depth tree is grown

    Declaration

    Swift

    public var maxDepth: Int
  • regression or classification task

    Declaration

    Swift

    public var perform: String
  • column number of target var

    Declaration

    Swift

    public var target: Int
  • tolerance for regression

    Declaration

    Swift

    public var tolerance: Float
  • Creates original DataSet to be stored and grows decision tree

    Declaration

    Swift

    public init (data: [[String]],
                 target: Int,
                 maxDepth: Int = 9999,
                 perform: String,
                 using: String,
                 tolerance: Float = 0.1)

    Parameters

    data

    data with labels

    target

    column number of label

    maxDepth

    max depth tree is grown

    perform

    regression or classification

    using

    infoGain or giniIndex

    tolerance

    for regression only

    Return Value

    DecisionTree

  • displays the grown tree by calling print tree

    Declaration

    Swift

    public func displayTree()

    Return Value

    None

  • prints part of tree at given node and indents wrt. depth

    Declaration

    Swift

    public func printTree(node: Node, depth: Int)

    Parameters

    node

    node to be printed

    depth

    depth of the node wrt. root

    Return Value

    None

  • Forms decision regression tree using gini index recursively

    Declaration

    Swift

    public func giniR(dataset: DataSet, depth: Int) -> Node

    Parameters

    dataset

    data left to be used

    depth

    current depth

    Return Value

    Node that splits data best

  • Forms decision classification tree using gini index recursively

    Declaration

    Swift

    public func giniC(dataset: DataSet, depth: Int) -> Node

    Parameters

    dataset

    data left to be used

    depth

    current depth

    Return Value

    Node that splits data best

  • Examine the dataset to create classification Tree with id3 recursively

    Declaration

    Swift

    public func id3C(dataset: DataSet, depth: Int) -> Node

    Parameters

    dataset

    data left to be used

    depth

    current depth

    Return Value

    Node that splits data best

  • / Examine the dataset to create regression tree with id3 recursively

    Declaration

    Swift

    public func id3R(dataset: DataSet, depth: Int) -> Node

    Parameters

    dataset

    data left to be used

    depth

    current depth

    Return Value

    Node that splits data best

  • Classfies/Predicts an example by traversing

    Declaration

    Swift

    public func classify(example: [[String]]) -> String

    Return Value

    classification/predictions as a string

  • Scores the tree’s accuracy on test data

    Declaration

    Swift

    public func score(testData: [[String]]) -> (Float, [String])

    Parameters

    testData

    test data as a 2D string array with feature header

    Return Value

    • accuracy of classifications as float
    • classifications as string array