コード例 #1
0
 def __init__(self, frecords, classifier, label_mappings, record_mappings,
              get_labels_of_record):
     '''
     Constructor.
     
     frecords - generator returning records.
         NOTE: if a user wants to manipulate, which codes to consider(e.g. higher or lower level) 
         it is good to give a specific frecords parameter
         
     classifier - constructor of a multi-label classifier, parametrized by frecords only.
     
     label_mappings - a list equal to depth of a classification tree that is to be constructed. consecutive elements are functions that
         map label into sub-label that is important in the current node-level
     
     record_mappings - a list equal to depth of a classification tree that is to be constructed. consecutive elements are functions that
         map record into sub-record (in terms of labels) that is important in the current node-level; mapping should be specified with child_id for
         additional filtering
         IMPORTANT: SHOULD NOT MODIFY RECORD INTERNALLY, BUT RETURN A NEW RECORD!
     '''
     #derivable fields:
     self.max_depth = len(label_mappings) - 1
     self.get_labels_of_record = get_labels_of_record
     #Build the classification tree.
     PRINTER("[MlHierarchical: init]: start of training...")
     self.mltree = tree_dfs_builder(
         frecords, lambda records, curr_depth, child_id: self.node_builder(
             records, curr_depth, child_id, classifier, record_mappings),
         lambda records, curr_depth, child_id: self.children_splitter(
             records, curr_depth, child_id, label_mappings), self.max_depth,
         0, '')  #we start at depth 0
コード例 #2
0
 def __init__(self, records, train_labels, classifier, label_mappings,
              continue_deepening, is_leaf_node):
     '''
     Constructor.
     
     records -records list.
     
     train_labels - consecutive labels, for each record
     
     classifier - constructor of a multi-label classifier, parametrized by records, train_labels and list_of_all_labels.
     
     label_mappings - a list equal to depth of a classification tree that is to be constructed. consecutive elements are functions that
         map label into sub-label that is important in the current node-level
     
     continue_deepening - returns a boolean value, wether a given node has at least one non-leaf chid
     
     is_leaf_node - returns a boolean value indicating wether a node is a leaf
     '''
     #derivable fields:
     self.max_depth = len(label_mappings) - 1
     #Build the classification tree.
     PRINTER("[MlHierarchical: init]: start of training...")
     self.continue_deepening = continue_deepening  #wether to continue deepening from a child_id
     self.is_leaf_node = is_leaf_node
     self.mltree = tree_dfs_builder(
         records, lambda records, curr_depth, child_id: self.node_builder(
             records, curr_depth, child_id, classifier, label_mappings,
             train_labels),
         lambda records, curr_depth, child_id: self.children_splitter(
             records, curr_depth, child_id, label_mappings, train_labels),
         self.max_depth, 0, 'START_NODE',
         self.continue_deepening)  #we start at depth 0
コード例 #3
0
 def __init__(self, records, train_labels, classifier, label_mappings, continue_deepening, is_leaf_node):
     '''
     Constructor.
     
     records -records list.
     
     train_labels - consecutive labels, for each record
     
     classifier - constructor of a multi-label classifier, parametrized by records, train_labels and list_of_all_labels.
     
     label_mappings - a list equal to depth of a classification tree that is to be constructed. consecutive elements are functions that
         map label into sub-label that is important in the current node-level
     
     continue_deepening - returns a boolean value, wether a given node has at least one non-leaf chid
     
     is_leaf_node - returns a boolean value indicating wether a node is a leaf
     '''
     #derivable fields:
     self.max_depth = len(label_mappings)-1
     #Build the classification tree.
     PRINTER("[MlHierarchical: init]: start of training...")
     self.continue_deepening = continue_deepening#wether to continue deepening from a child_id
     self.is_leaf_node = is_leaf_node
     self.mltree = tree_dfs_builder(records, 
                                    lambda records, curr_depth, child_id: self.node_builder(records, curr_depth, child_id, classifier, label_mappings, train_labels), 
                                    lambda records, curr_depth, child_id: self.children_splitter(records, curr_depth, child_id, label_mappings, train_labels), self.max_depth, 0, 'START_NODE', self.continue_deepening)#we start at depth 0
コード例 #4
0
 def __init__(self, frecords, classifier, label_mappings,
              get_labels_of_record):
     '''
     Constructor.
     
     frecords - generator returning records.
         NOTE: if a user wants to manipulate, which codes to consider(e.g. higher or lower level) 
         it is good to give a specific frecords parameter
         
     classifier - constructor of a multi-label classifier, parametrized by frecords and get_labels_of_record only.
     
     label_mappings - a list equal to depth of a classification tree that is to be constructed. consecutive elements are functions that
         map label into sub-label that is important in the current node-level
         
     get_labels_of_record - returns a list of labels of the record
     '''
     #derivable fields:
     self.max_depth = len(label_mappings) - 1
     self.get_labels_of_record = get_labels_of_record
     #Build the classification tree.
     PRINTER("[init]: start of training...")
     self.mltree = tree_dfs_builder(
         frecords, lambda records, curr_depth, child_id: self.node_builder(
             records, curr_depth, child_id, classifier, label_mappings,
             get_labels_of_record),
         lambda records, curr_depth, child_id: self.children_splitter(
             records, curr_depth, child_id, label_mappings,
             get_labels_of_record), self.max_depth, 0, '',
         lambda x: True)  #we start at depth 0
コード例 #5
0
 def __init__(self, frecords, classifier, label_mappings, record_mappings, get_labels_of_record):
     '''
     Constructor.
     
     frecords - generator returning records.
         NOTE: if a user wants to manipulate, which codes to consider(e.g. higher or lower level) 
         it is good to give a specific frecords parameter
         
     classifier - constructor of a multi-label classifier, parametrized by frecords only.
     
     label_mappings - a list equal to depth of a classification tree that is to be constructed. consecutive elements are functions that
         map label into sub-label that is important in the current node-level
     
     record_mappings - a list equal to depth of a classification tree that is to be constructed. consecutive elements are functions that
         map record into sub-record (in terms of labels) that is important in the current node-level; mapping should be specified with child_id for
         additional filtering
         IMPORTANT: SHOULD NOT MODIFY RECORD INTERNALLY, BUT RETURN A NEW RECORD!
     '''
     #derivable fields:
     self.max_depth = len(label_mappings)-1
     self.get_labels_of_record = get_labels_of_record
     #Build the classification tree.
     PRINTER("[MlHierarchical: init]: start of training...")
     self.mltree = tree_dfs_builder(frecords, 
                                    lambda records, curr_depth, child_id: self.node_builder(records, curr_depth, child_id, classifier, record_mappings), 
                                    lambda records, curr_depth, child_id: self.children_splitter(records, curr_depth, child_id, label_mappings), self.max_depth, 0, '')#we start at depth 0
コード例 #6
0
 def __init__(self, frecords, classifier, label_mappings, get_labels_of_record):
     '''
     Constructor.
     
     frecords - generator returning records.
         NOTE: if a user wants to manipulate, which codes to consider(e.g. higher or lower level) 
         it is good to give a specific frecords parameter
         
     classifier - constructor of a multi-label classifier, parametrized by frecords and get_labels_of_record only.
     
     label_mappings - a list equal to depth of a classification tree that is to be constructed. consecutive elements are functions that
         map label into sub-label that is important in the current node-level
         
     get_labels_of_record - returns a list of labels of the record
     '''
     #derivable fields:
     self.max_depth = len(label_mappings)-1
     self.get_labels_of_record = get_labels_of_record
     #Build the classification tree.
     PRINTER("[init]: start of training...")
     self.mltree = tree_dfs_builder(frecords, 
                                    lambda records, curr_depth, child_id: self.node_builder(records, curr_depth, child_id, classifier, label_mappings, get_labels_of_record), 
                                    lambda records, curr_depth, child_id: self.children_splitter(records, curr_depth, child_id, label_mappings, get_labels_of_record), 
                                    self.max_depth, 0, '', lambda x: True)#we start at depth 0