ISmDecisionTree.Tree

Syntax

Tree: ISlTreeNode;

Description

The Tree property returns the created decision tree.

Comments

A decision tree is a hierarchical tree of rules, where each object corresponds to a single node giving the decision. A rule is a logical construction represented as "if... then ...".

Example

To execute the example, add a link to the Stat system assembly.

Sub UserDecisionTree;
Var
    dTree: SmDecisionTree;
    expl, ex1, ex2: Array[12Of Double;
    res, i, j: Integer;
    TreeNode: ISlTreeNode;
    CatList: Array Of Integer;
    S: String;
    // Procedure of outputting the decision tree
    Sub print(nodes: ISlTreeNodes);
    Var
        i: Integer;
        Node: ISlTreeNode;
        s: String;
    Begin
        For i := 0 To nodes.Count - 1 Do
            Debug.Indent;
            Node := nodes.Item(i);
            s := "Value '" + Node.Value.ToString + "' ";
            s := s + "in the series '" + Node.ExplanatorieIndex.ToString + "' ";
            s := s + "has weight '" + Node.Weight.ToString + "' ";
            s := s + "and support '" + Node.Instances.ToString + "'";
            Debug.WriteLine(s);
            print(nodes.Item(i).Children);
            Debug.Unindent;
        End For;
    End Sub print;
Begin
    dTree := New SmDecisionTree.Create;
    // Set initial data
    ex1[0] := 0; ex2[0] := 0; expl[0] := 0;
    ex1[1] := 0; ex2[1] := 1; expl[1] := 1;
    ex1[2] := 1; ex2[2] := 0; expl[2] := 2;
    ex1[3] := 1; ex2[3] := 1; expl[3] := 3;
    ex1[4] := 0; ex2[4] := 0; expl[4] := 0;
    ex1[5] := 0; ex2[5] := 1; expl[5] := 1;
    ex1[6] := 1; ex2[6] := 0; expl[6] := 2;
    ex1[7] := 1; ex2[7] := 1; expl[7] := 3;
    ex1[8] := 1; ex2[8] := 1; expl[8] := Integer.MinValue;
    ex1[9] := 1; ex2[9] := 0; expl[9] := Integer.MinValue;
    ex1[10] := 1; ex2[10] := 0; expl[10] := Integer.MinValue;
    ex1[11] := 1; ex2[11] := 1; expl[11] := Integer.MinValue;
    // Set explained series
    dTree.Dependent.Value := expl;
    // Define explanatory series
    dTree.Explanatories.Add.Value := ex1;
    dTree.Explanatories.Add.Value := ex2;
    // Run calculation and show results
    res := dTree.Execute;
    If res <> 0 Then
        Debug.WriteLine(dTree.Errors);
    Else
        Debug.WriteLine("Initial values; Processed values;");
        For i := 0 To 11 Do
            Debug.Write(dTree.Dependent.Value[i].ToString + " ");
            Debug.WriteLine(dTree.FilledDependent.Value[i]);
        End For;
        // Output decision tree
        TreeNode := dTree.Tree;
        If TreeNode.Parent = Null Then
            Debug.WriteLine("Decision tree:");
            print(TreeNode.Children);
        End If;
        // Display list of categories
        CatList := dTree.CategoriesList;
        If CatList.Length > 0 Then
            Debug.WriteLine("List of categories:"); Debug.Indent;
            For i := 0 To CatList.Length - 1 Do
                Debug.WriteLine(CatList[i]);
            End For;
            Debug.Unindent;
        End If;
        Debug.WriteLine("Summary results of classification:");
        Debug.Indent;
        s := "";
        For i := 0 To dTree.ClassificationSummary.GetUpperBound(1Do
            For j := 0 To dTree.ClassificationSummary.GetUpperBound(2Do
                s := s + dTree.ClassificationSummary[i, j].ToString + " ";
            End For;
            Debug.WriteLine(s);
            s := "";
        End For;
        Debug.Unindent;
        Debug.WriteLine("Results of training set classification:");
        Debug.Indent;
        For i := 0 To dTree.FilledLearningSample.GetUpperBound(1Do
            Debug.WriteLine(dTree.FilledLearningSample[i]);
        End For;
        Debug.Unindent;
    End If;
End Sub UserDecisionTree;

After executing the example the console window displays missing data treatment results, decision tree and list of categories.

See also:

ISmDecisionTree