コード例 #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
ファイル: test_polyaco.py プロジェクト: cair/PolyACOPlus
 def test_evaluate_returns_1_point_of_class_0_rest_class_1(self):
     clf = acoc.PolyACO(self.data.shape[1], self.class_indices)
     clf.model = [[self.polygon1, self.polygon2]] * len(clf.planes)
     result = clf.evaluate(self.data)
     self.assertEqual(sum(result), 4)
     class_0_count = list(result).count(0)
     self.assertEqual(class_0_count, 1)
コード例 #3
0
ファイル: test_polyaco.py プロジェクト: cair/PolyACOPlus
 def test_evaluate_3_classes_2_dimensions(self):
     data = np.array([[0.1, 0.5], [1.1, 0.5], [1.1, 1.3], [1.1, 1.4]])
     clf = acoc.PolyACO(data.shape[1], [0, 1, 2])
     polygon3 = load_simple_polygon(Vertex(1, 0))
     clf.model = [[self.polygon1, self.polygon2, polygon3]]
     result = list(clf.evaluate(data))
     self.assertEqual(result.count(0), 1)
     self.assertEqual(result.count(1), 2)
     self.assertEqual(result.count(2), 1)
コード例 #4
0
ファイル: test_polyaco.py プロジェクト: cair/PolyACOPlus
 def test_evaluate_3_classes_3_dimensions_with_overlap(self):
     data = np.array([[0.5, 0.5, 0.5], [0.5, 1.5, 1.5], [2.5, 2.5, 2.5]])
     clf = acoc.PolyACO(data.shape[1], [0, 1, 2])
     clf.model = [[
         self.polygon1, self.polygon2,
         load_simple_polygon(Vertex(2, 2))
     ]] * len(clf.planes)
     result = list(clf.evaluate(data))
     self.assertEqual(result.count(0), 1)
     self.assertEqual(result.count(1), 1)
     self.assertEqual(result.count(2), 1)
コード例 #5
0
def run(**kwargs):
    conf = dict(CLASSIFIER_CONFIG)
    for k, v in kwargs.items():
        conf[k] = v

    clf = acoc.PolyACO(conf, SAVE_FOLDER)
    data = pickle.load(open('utils/data_sets.pickle', 'rb'),
                       encoding='latin1')['semicircle_gaussian']

    best_ant_history, _ = clf.train(data)
    print(", Best ant score: {}".format(max(best_ant_history)))
    return best_ant_history
コード例 #6
0
def run(*args):
    config = dict(CONFIG)
    for conf in args:
        config[conf[0]] = conf[1]
    data = pickle.load(open('utils/data_sets.pickle',
                            'rb'))[config['data_set']]
    number_runs = config['number_runs']

    clf = acoc.PolyACO(config)

    run_times = np.zeros(number_runs, dtype=float)
    for i in range(number_runs):
        iter_string = "Iteration: {}/{}".format(i + 1, number_runs)

        start = time.clock()
        clf.train(data, print_string=', ' + iter_string)
        end = time.clock()
        run_times[i] = end - start

        utils.print_on_current_line(iter_string)
    return np.mean(run_times)
コード例 #7
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)
コード例 #8
0
ファイル: test_polyaco.py プロジェクト: cair/PolyACOPlus
 def test_evaluate_returns_list_with_equal_length_as_input(self):
     clf = acoc.PolyACO(self.data.shape[1], self.class_indices)
     clf.model = [[self.polygon1, self.polygon2]] * len(clf.planes)
     result = clf.evaluate(self.data)
     self.assertEqual(len(result), self.data.shape[0])
コード例 #9
0
ファイル: test_polyaco.py プロジェクト: cair/PolyACOPlus
 def test_evaluate_before_training_raise_value_error(self):
     clf = acoc.PolyACO(2, self.class_indices)
     with self.assertRaises(RuntimeError):
         clf.evaluate(self.data)
コード例 #10
0
ファイル: test_polyaco.py プロジェクト: cair/PolyACOPlus
 def test_class_indices_with_duplicate_indices_raise_warning(self):
     with self.assertWarns(UserWarning):
         acoc.PolyACO(2, [0, 0])
コード例 #11
0
ファイル: test_polyaco.py プロジェクト: cair/PolyACOPlus
 def test_3_classes_has_3_spaces_in_each_plane_in_polygon_list(self):
     clf = acoc.PolyACO(3, [0, 1, 2])
     for plane in clf.model:
         self.assertEqual(len(plane), 3)