decision Package

decision Package

Decision trees

infpy.decision.random() → x in the interval [0, 1).

attributes Module

The attributes of data we analyse with decision trees.

Not an attribute in the python sense

class infpy.decision.attributes.Attribute(name, fn)[source]

Bases: object

An attribute of the data to be classified

Not an attribute in the python sense

class infpy.decision.attributes.ContinuousAttribute(name, fn, mean, stddev)[source]

Bases: infpy.decision.attributes.Attribute

A continuous (of type float) attribute of the data to be classified

class infpy.decision.attributes.EnumerativeAttribute(name, fn, num_values)[source]

Bases: infpy.decision.attributes.Attribute

An enumerative attribute of the data to be classified

class infpy.decision.attributes.OrdinalAttribute(name, fn, num_values)[source]

Bases: infpy.decision.attributes.Attribute

An ordinal attribute of the data to be classified

decision Module

Implementation of a decision tree

class infpy.decision.decision.DecisionNode(rule, children)[source]

Bases: object

A node in a decision tree that makes a decision based on the data

class infpy.decision.decision.LeafNode(outcome)[source]

Bases: object

A node in a decision tree that returns one of the possible outcomes

class infpy.decision.decision.NodeCounter[source]

Bases: object

count = 0
class infpy.decision.decision.NodeMutator(p_mutation, context)[source]

Bases: object

Mutates nodes according to some probability

class infpy.decision.decision.PossibleOutcomes[source]

Bases: object

s = set([])
infpy.decision.decision.build_random_path(tree, path)[source]

Build a random path in tree to a leaf node


Returns (parent,node) where parent is always a DecisionNode

infpy.decision.decision.combine_trees(tree_1, tree_2)[source]

Randomly combine 2 trees in place

infpy.decision.decision.create_random_decision_tree(context, depth)[source]
infpy.decision.decision.insert_decision(decision_node, context, depth=0)[source]

Insert an extra decision in the tree

infpy.decision.decision.log_tree(tree, logger, level, indent=0)[source]
infpy.decision.decision.mutate_node(node, context)[source]

Mutate the given node

infpy.decision.decision.mutate_tree(tree, context, new_subtree_depth)[source]

Replace one node with a new random subtree of the given depth

infpy.decision.decision.print_tree(tree, indent=0)[source]
infpy.decision.decision.prune_tree(tree, rules_satisfied=None)[source]

Prunes the tree to remove useless nodes

infpy.decision.decision.random() → x in the interval [0, 1).
infpy.decision.decision.replace_rule(decision_node, context, depth=0)[source]

Replace the rule in the node with a completely new random rule

infpy.decision.decision.tree_has_only_one_outcome(tree, outcome=None)[source]

Does this tree have only one outcome and what is it?

Returns None if more than one outcome, otherwise returns outcome


Returns all the possible outcomes of this tree

infpy.decision.decision.visit_tree_nodes(tree, visitor)[source]

genepy_interface Module

Implements decision tree interface to the genepy genetic algorithm library

class infpy.decision.genepy_interface.DecisionTreeSpecies(context, initial_depth=3, p_mutation=0.1)[source]

Bases: object

Wraps a decision tree to interface to the pygene genetic algorithm library

Implements combination, mutation and random initialisation

mate(individual_1, individual_2)[source]



Mutation in place


Random initialisation

rule_generation Module

Implements rules to generate and modify decision trees

class infpy.decision.rule_generation.ComparisonRule(attr, constant)[source]

Bases: infpy.decision.rule_generation.Rule

A rule that compares the attribute’s value with a constant

class infpy.decision.rule_generation.Context[source]

Bases: object

The context object defines the data’s attributes and their range of values. It also defines the possible outcomes (classifications) of a decision tree.

attributes = []
outcomes = []
class infpy.decision.rule_generation.MembershipRule(attr, iterable)[source]

Bases: infpy.decision.rule_generation.Rule

A rule that tests whether the attribute’s value is a member of some set

class infpy.decision.rule_generation.Rule(attr)[source]

Bases: object

A rule in a decision tree.

A rule uses one attribute and to choose between several possible outcomes

class infpy.decision.rule_generation.StraightThroughRule(attr)[source]

Bases: infpy.decision.rule_generation.Rule

A rule that simply returns the attribute’s value

infpy.decision.rule_generation.new_mutated_rule(rule, degree_of_mutation=1.0)[source]

Create a new mutated copy of a rule


Chooses one of the attributes and creates a rule based on it.

See new_rule_for_attribute


Creates a new rule based on the attribute

Returns (rule,# possible outcomes)

A rule is function object that takes one argument (a datum) and returns an index into some children

infpy.decision.rule_generation.only_possible_outcome(satisfied_rule, outcome, rule_to_test)[source]

Given that the satisfied_rule has the given outcome, are we guaranteed what the outcome of the rule_to_test is?

Returns the outcome if we are sure, returns None if not

infpy.decision.rule_generation.random() → x in the interval [0, 1).

Table Of Contents

Previous topic

dbn Package

Next topic

test Package

This Page