Esempio n. 1
0
def q14():
    T = 1
    clf = AdaBoost(T, lambda u: DecisionStump(u), lambda dd: dd.err_)
    X, y = load_ada_boost_train()
    clf.fit(X, y)
    print clf.u
    print np.sum(clf.u)
    print 'AND SEE q13'
Esempio n. 2
0
def do_boost(x, y, m):
    ada_boost = AdaBoost(x, y, m)
    accuracy = accuracy_score(ada_boost.predict(x), y)

    print("Шаг бустинга:", m)
    print("Точность:", accuracy)
    print()

    draw_boost(x, y, ada_boost)
Esempio n. 3
0
def draw_dependency(X, Y):
    x = []
    y = []
    for i in range(1, 100):
        x.append(i)
        ada_boost = AdaBoost(X, Y, i)
        y.append(accuracy_score(ada_boost.predict(X), Y))

    plt.plot(x, y)
    plt.show()
Esempio n. 4
0
def test(file):
    dataset = utils.dataset_reader(file)
    X_train, y_train, X_test, y_test = utils.data_process(dataset)

    n_estimators = 30

    print('AdaBoost Optimal for:', file)
    ada_boost = AdaBoost(n_estimators=n_estimators)

    ada_boost.fit(X_train, y_train, X_test, y_test)

    utils.plot_error_vs_t('local error', ada_boost.local_errs,
                          ada_boost.n_estimators)
    utils.plot_error_vs_t('train error', ada_boost.train_errs,
                          ada_boost.n_estimators)
    utils.plot_error_vs_t('test error', ada_boost.test_errs,
                          ada_boost.n_estimators)

    print('AdaBoost Random for:', file)
    ada_boost_random = AdaBoost(n_estimators=n_estimators,
                                decision_stumps='random')

    ada_boost_random.fit(X_train, y_train, X_test, y_test)

    utils.plot_error_vs_t('local error', ada_boost_random.local_errs,
                          ada_boost_random.n_estimators)
    utils.plot_error_vs_t('train error', ada_boost_random.train_errs,
                          ada_boost_random.n_estimators)
    utils.plot_error_vs_t('test error', ada_boost_random.test_errs,
                          ada_boost_random.n_estimators)
Esempio n. 5
0
def adaBoost():
    X, y = make_classification(n_samples=350, n_features=15, n_informative=10,
                            random_state=1111, n_classes=2,
                            class_sep=1., n_redundant=0)
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.15,
                                                        random_state=1111)

    model = AdaBoost(n_estimators=10, max_tree_depth=5,
                max_features=8)
    model.fit(X_train, y_train)
    predictions = model.predict(X_test)
    print(predictions)
    print(predictions.min())
    print(predictions.max())
    print('classification, roc auc score: %s'
        % roc_auc_score(y_test, predictions))
Esempio n. 6
0
def train(example_file, out_file, learning_type):
    """
    Trains a model basesd on example_data and learning
    approach and writes model to serialized object.

    :param example_file:    training file
    :param out_file:        hypothesis file
    :param learning_type:   learning approach

    :return:
    """
    if learning_type == 'dt':
        # print('Trainning Model with decision trees')
        decisionModel = DecisionTree(example_file, out_file)
        decisionModel.train()

    if learning_type == 'ada':
        # print('Trainning model with adaboost')
        adaModel = AdaBoost(example_file, out_file)
        adaModel.train()
Esempio n. 7
0
def q13():
    T = 300
    clf = AdaBoost(T, lambda u: DecisionStump(u), lambda dd: dd.err_)
    X, y = load_ada_boost_train()
    clf.fit(X, y)
    print clf.e
    print 'Ein:', clf.score(X, y)
    print '%f <= U_T <= %f' % (np.min(clf.U), np.max(clf.U))
    print 'e_t >= %f' % np.min(clf.e)
    X, y = load_ada_boost_test()
    print 'Eout:', clf.score(X, y)
    print 'U(2):', clf.U[1]
def apply_ada_boost(filename, estimators):
    ab = AdaBoost(filename, estimators=estimators, learning_rate=0.1)

    #ab.split_data()
    ab.start_data()
    ab.train_ada_boost()
    ab.test_ada_boost()

    ab.switch_folds()
    ab.train_ada_boost()
    ab.test_ada_boost()