Пример #1
0
def run(*args):
    config = copy(CLASSIFIER_CONFIG)
    for conf in args:
        config[conf[0]] = conf[1]

    data_set = data_manager.load_data_set(config.data_set)
    classifier_scores = []
    for nrun in range(config.runs):
        X = data_set.data
        y = data_set.target
        class_indices = list(set(y))

        if config.training_test_split:
            X_train, X_test, y_train, y_test = train_test_split(X,
                                                                y,
                                                                test_size=0.33)
        else:
            X_train = X_test = X
            y_train = y_test = y

        clf = acoc.PolyACO(X_train.shape[1], class_indices, config)
        clf.train(X_train, y_train)
        predictions = clf.evaluate(X_test)

        classifier_scores.append(acoc.compute_score(predictions, y_test))
        print("\nRun {}/{} score: {:.4f}".format(nrun + 1, config.runs,
                                                 classifier_scores[-1]))
    return classifier_scores
Пример #2
0
def run(**kwargs):
    conf = copy(CLASSIFIER_CONFIG)
    for k, v in kwargs.items():
        conf[k] = v

    data_set = data_manager.load_data_set(conf.data_set)
    X = data_set.data
    y = data_set.target
    class_indices = list(set(y))

    # Split data into training and testing set
    if conf.training_test_split:
        X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)
    else:
        X_train = X_test = X
        y_train = y_test = y

    clf = acoc.PolyACO(X.shape[1], class_indices, save_folder=SAVE_FOLDER)
    clf.train(X_train, y_train, start_time=conf.start_time)
    predictions = clf.evaluate(X_test)
    return acoc.compute_score(predictions, y_test)
Пример #3
0
        ]
        if len(vertices_in_column) > 0:
            next_north = min(vertices_in_column, key=lambda pos: pos.y)
            edge = Edge(vertex, next_north, tau_initial)
            edges.append(edge)
    return edges


if __name__ == "__main__":
    from acoc.acoc_plotter import plot_pheromones, plot_matrix_and_data
    from utils import generate_folder_name

    plot = True
    save = True
    show = False
    data_set = data_manager.load_data_set('breast_cancer')

    data = data_set.data[:, :2]
    target = np.array([data_set.target]).T
    np.place(target, target == 4, 1)
    np.place(target, target == 2, 0)
    dt = np.concatenate((data, target), axis=1)

    # dt = np.array([[0, 0.02, 0],
    #                [0.05, 0, 1],
    #                [1, 1, 1]])
    mtrx = AcocMatrix(dt)
    pol = mtrx.edges[:4]
    mtrx.edges[1].pheromone_strength = 5
    mtrx.edges[0].pheromone_strength = 3
    save_folder = generate_folder_name()
Пример #4
0
        vertices_in_column = [p for p in vertices if p.y > vertex.y and p.x == vertex.x]
        if len(vertices_in_column) > 0:
            next_north = min(vertices_in_column, key=lambda pos: pos.y)
            edge = Edge(vertex, next_north, tau_initial)
            edges.append(edge)
    return edges


if __name__ == "__main__":
    from acoc.acoc_plotter import plot_pheromones, plot_matrix_and_data
    from utils import generate_folder_name

    plot = True
    save = True
    show = False
    data_set = data_manager.load_data_set('breast_cancer')

    data = data_set.data[:, :2]
    target = np.array([data_set.target]).T
    np.place(target, target == 4, 1)
    np.place(target, target == 2, 0)
    dt = np.concatenate((data, target), axis=1)

    # dt = np.array([[0, 0.02, 0],
    #                [0.05, 0, 1],
    #                [1, 1, 1]])
    mtrx = AcocMatrix(dt)
    pol = mtrx.edges[:4]
    mtrx.edges[1].pheromone_strength = 5
    mtrx.edges[0].pheromone_strength = 3
    save_folder = generate_folder_name()