rdkit.ML.DecTree.Tree module

Implements a class used to represent N-ary trees

class rdkit.ML.DecTree.Tree.TreeNode(parent, name, label=None, data=None, level=0, isTerminal=0)

Bases: object

This is your bog standard Tree class.

the root of the tree is just a TreeNode like all other members.

AddChild(name, label=None, data=None, isTerminal=0)

Creates a new TreeNode and adds a child to the tree

Arguments

  • name: the name of the new node
  • label: the label of the new node (should be an integer)
  • data: the data to be stored in the new node
  • isTerminal: a toggle to indicate whether or not the new node is a terminal (leaf) node.

**Returns*

the _TreeNode_ which is constructed
AddChildNode(node)

Adds a TreeNode to the local list of children

Arguments

  • node: the node to be added

Note

the level of the node (used in printing) is set as well
Destroy()

Destroys this node and all of its children

GetChildren()

Returns a python list of the children of this node

GetData()

Returns the data stored at this node

GetLabel()

Returns the label of this node

GetLevel()

Returns the level of this node

GetName()

Returns the name of this node

GetParent()

Returns the parent of this node

GetTerminal()

Returns whether or not this node is terminal

NameModel(varNames)

Set the names of each node in the tree from a list of variable names.

Arguments

  • varNames: a list of names to be assigned

Notes

  1. this works its magic by recursively traversing all children
  2. The assumption is made here that the varNames list can be indexed by the labels of tree nodes
NameTree(varNames)

Set the names of each node in the tree from a list of variable names.

Arguments

  • varNames: a list of names to be assigned

Notes

  1. this works its magic by recursively traversing all children
  2. The assumption is made here that the varNames list can be indexed by the labels of tree nodes
Pickle(fileName='foo.pkl')

Pickles the tree and writes it to disk

Print(level=0, showData=0)

Pretty prints the tree

Arguments

  • level: sets the number of spaces to be added at the beginning of the output
  • showData: if this is nonzero, the node’s _data_ value will be printed as well

Note

this works recursively
PruneChild(child)

Removes the child node

Arguments

  • child: a TreeNode
ReplaceChildIndex(index, newChild)

Replaces a given child with a new one

Arguments

  • index: an integer
  • child: a TreeNode
SetData(data)

Sets the data stored at this node

SetLabel(label)

Sets the label of this node (should be an integer)

SetLevel(level)

Sets the level of this node

SetName(name)

Sets the name of this node

SetParent(parent)

Sets the parent of this node

SetTerminal(isTerminal)

Sets whether or not this node is terminal