コード例 #1
0
class NeuralNetworkClassifier(object):
    "Multi Layer Neural Network Classifier"

    def __init__(self, num_nodes_list):
        self.network = None
        self.num_nodes_list = num_nodes_list

    def train_all(self, data_table):

        num_inputs = len(data_table[0]) - 1  # minus one for the answer
        data_cols = np.rot90(data_table, -1)

        self.network = MultiLayerNetwork(num_inputs, self.num_nodes_list)

        normalized_data_cols = map(stats.zscore_map, data_cols)
        normalized_data = np.rot90(normalized_data_cols, 1)

        # run stuff through, and change the weights if it's wrong

    def predict(self, row):
        # could return multiple answers it thinks are right
        answers = self.network.activate(row)

        # Pick the "rightest" one
        return np.argmax(answers)

    def predict_all(self, data_table):
        return map(predict, data_table)
コード例 #2
0
    def train_all(self, data_table):

        num_inputs = len(data_table[0]) - 1  # minus one for the answer
        data_cols = np.rot90(data_table, -1)

        self.network = MultiLayerNetwork(num_inputs, self.num_nodes_list)

        normalized_data_cols = map(stats.zscore_map, data_cols)
        normalized_data = np.rot90(normalized_data_cols, 1)