som/som.py
def predict(self, test_vectors):
        """Predicts the class label of a test vector or multiple test vectors,
        according to the class label of the bmu.
        """
        # Calculate the best matching label for each node
        if not self.ready_for_prediction:
            # totals = sum((node.labels for node in self.codebook), Counter())
            for node in self.codebook:
                # Remove unlabeled hits
                try:
                    node.labels.pop(None)
                except KeyError:
                    pass
                # # Take into account small clusters. A frequency approach
                # freq_counter = Counter({label: count / totals[label]
                #                    for label, count in node.labels.items()})
                # if len(freq_counter) > 0:
                #     node.label = freq_counter.most_common(1)[0][0]
                # else:
                #     node.label = ''
                # Or ignore small clusters and just aim for accuracy
                if len(node.labels) > 0:
                    node.label = node.labels.most_common(1)[0][0]
                else:
                    node.label = ''
            self.ready_for_prediction = True

        # Return the label of the best matching unit for the given test_vectors
        if isinstance(test_vectors, collections.Iterable):
            return [self.bmu(test_vector).label for test_vector in test_vectors]
        else:
            return self.bmu(test_vectors).label
Predicts the class label of a test vector or multiple test vectors,
        according to the class label of the bmu.
        
Predicts the class label of a test vector or multiple test vectors,
according to the class label of the bmu.
Predicts the class label of a test vector or multiple test vectors according to the class label of the bmu .
def predict(self, test_vectors):
        if not self.ready_for_prediction:
            for node in self.codebook:
                try:
                    node.labels.pop(None)
                except KeyError:
                    pass
                if len(node.labels) > 0:
                    node.label = node.labels.most_common(1)[0][0]
                else:
                    node.label = ''
            self.ready_for_prediction = True
        if isinstance(test_vectors, collections.Iterable):
            return [self.bmu(test_vector).label for test_vector in test_vectors]
        else:
            return self.bmu(test_vectors).label
def predict ( self , test_vectors ) : if not self . ready_for_prediction : for node in self . codebook : try : node . labels . pop ( None ) except KeyError : pass if len ( node . labels ) > 0 : node . label = node . labels . most_common ( 1 ) [ 0 ] [ 0 ] else : node . label = '' self . ready_for_prediction = True if isinstance ( test_vectors , collections . Iterable ) : return [ self . bmu ( test_vector ) . label for test_vector in test_vectors ] else : return self . bmu ( test_vectors ) . label
Predicts the class label of a test vector or multiple test vectors,
according to the class label of the bmu.
Predicts the class label of a test vector or multiple test vectors according to the class label of the bmu .
"""Predicts the class label of a test vector or multiple test vectors,
        according to the class label of the bmu.
        """ # Calculate the best matching label for each node # totals = sum((node.labels for node in self.codebook), Counter()) # Remove unlabeled hits # # Take into account small clusters. A frequency approach # freq_counter = Counter({label: count / totals[label] #                    for label, count in node.labels.items()}) # if len(freq_counter) > 0: #     node.label = freq_counter.most_common(1)[0][0] # else: #     node.label = '' # Or ignore small clusters and just aim for accuracy # Return the label of the best matching unit for the given test_vectors
self
test_vectors