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
datadata with labels
targetcolumn number of label
maxDepthmax depth tree is grown
performregression or classification
usinginfoGain or giniIndex
tolerancefor 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
nodenode to be printed
depthdepth of the node wrt. root
Return Value
None
-
Classfies/Predicts an example by traversing
Declaration
Swift
public func classify(example: [[String]]) -> StringReturn Value
classification/predictions as a string
-
Scores the tree’s accuracy on test data
Declaration
Swift
public func score(testData: [[String]]) -> (Float, [String])Parameters
testDatatest data as a 2D string array with feature header
Return Value
- accuracy of classifications as float
- classifications as string array
DecisionTree Class Reference