Exemplo n.º 1
0
    alibox.split_AL(test_ratio=0.3, initial_label_rate=0.05, split_count=5)

    # Use the default Logistic Regression classifier
    model = alibox.get_default_model()

    # The cost budget is 50 times querying
    stopping_criterion = alibox.get_stopping_criterion('num_of_queries', 30)

    # experiment
    meta_regressor = joblib.load('meta_lr.joblib')
    # meta_query = QueryMetaData(X, y, meta_regressor)
    meta_result = []

    for round in range(5):

        meta_query = QueryMetaData(X, y, meta_regressor)
        # Get the data split of one fold experiment
        train_idx, test_idx, label_ind, unlab_ind = alibox.get_split(round)
        # Get intermediate results saver for one fold experiment
        saver = alibox.get_stateio(round)
        # calc the initial point
        model.fit(X=X[label_ind.index, :], y=y[label_ind.index])
        pred = model.predict(X[test_idx, :])
        accuracy = sum(pred == y[test_idx]) / len(test_idx)
        saver.set_initial_point(accuracy)

        while not stopping_criterion.is_stop():
            # Select a subset of Uind according to the query strategy
            # Passing model=None to use the default model for evaluating the committees' disagreement
            select_ind = meta_query.select(label_ind, unlab_ind, model=None)
            label_ind.update(select_ind)
Exemplo n.º 2
0
        # Use pre-defined strategy
        unc = QueryInstanceUncertainty(X, y)
        qbc = QueryInstanceQBC(X, y)
        eer = QureyExpectedErrorReduction(X, y)
        # random = QueryRandom(X, y)

        unc_result.append(copy.deepcopy(main_loop(alibox, unc, round)))
        qbc_result.append(copy.deepcopy(main_loop(alibox, qbc, round)))
        # eer_result.append(copy.deepcopy(main_loop(alibox, eer, round)))
        # random_result.append(copy.deepcopy(main_loop(alibox, random, round)))

    rfr_regression_result = []
    for round in range(splitcount):

        meta_query = QueryMetaData(X, y, rfr)
        # Get the data split of one fold experiment
        train_idx, test_idx, label_ind, unlab_ind = alibox.get_split(round)
        # Get intermediate results saver for one fold experiment
        saver = alibox.get_stateio(round)
        # calc the initial point
        model.fit(X=X[label_ind.index, :], y=y[label_ind.index])
        pred = model.predict(X[test_idx, :])
        accuracy = sum(pred == y[test_idx]) / len(test_idx)
        saver.set_initial_point(accuracy)

        while not stopping_criterion.is_stop():
            # Select a subset of Uind according to the query strategy
            # Passing model=None to use the default model for evaluating the committees' disagreement
            select_ind = meta_query.select(label_ind, unlab_ind, model=model)
            label_ind.update(select_ind)
Exemplo n.º 3
0
    s_c_300_1model_result = []


    q_t_50_1model_result = []
    q_t_70_1model_result = []
    q_t_90_1model_result = []
    q_t_100_1model_result = []
    q_t_110_1model_result = []
    q_t_200_1model_result = []
    q_t_300_1model_result = []

    ridge_qt50_7_result = []

    for name, regressor in meta_regressor.items():
        for round in range(splitcount):
            meta_query = QueryMetaData(X, y, regressor, copy.deepcopy(label_index_round[round]), copy.deepcopy(unlabel_index_round[round]), copy.deepcopy(model_output_round[round]))
            # Get the data split of one fold experiment
            train_idx, test_idx, label_ind, unlab_ind = alibox.get_split(round)
            # Get intermediate results saver for one fold experiment
            saver = alibox.get_stateio(round)
            # calc the initial point
            label_ind = copy.deepcopy(label_index_round[round][4])
            unlab_ind = copy.deepcopy(unlabel_index_round[round][4])
            model.fit(X=X[label_ind.index, :], y=y[label_ind.index])
            pred = model.predict(X[test_idx, :])
            accuracy = sum(pred == y[test_idx]) / len(test_idx)
            saver.set_initial_point(accuracy)

            while not stopping_criterion.is_stop():
                # Select a subset of Uind according to the query strategy
                # Passing model=None to use the default model for evaluating the committees' disagreement
    #         st = alibox.State(select_index=select_ind, performance=accuracy)
    #         saver.add_state(st)
    #         saver.save()

    #         # Passing the current progress to stopping criterion object
    #         stopping_criterion.update_information(saver)
    #     # Reset the progress in stopping criterion object
    #     stopping_criterion.reset()
    #     lr_cdata_random_result.append(copy.deepcopy(saver))

    # the regression way
    rfr_regression_result = []
    for round in range(splitcount):

        meta_query = QueryMetaData(X, y, rfr_meta,
                                   copy.deepcopy(label_index_round[round]),
                                   copy.deepcopy(unlabel_index_round[round]),
                                   copy.deepcopy(model_output_round[round]))
        # Get the data split of one fold experiment
        train_idx, test_idx, label_ind, unlab_ind = alibox.get_split(round)
        # Get intermediate results saver for one fold experiment
        saver = alibox.get_stateio(round)
        # calc the initial point
        label_ind = copy.deepcopy(label_index_round[round][4])
        unlab_ind = copy.deepcopy(unlabel_index_round[round][4])
        model.fit(X=X[label_ind.index, :], y=y[label_ind.index])
        pred = model.predict(X[test_idx, :])
        accuracy = sum(pred == y[test_idx]) / len(test_idx)
        saver.set_initial_point(accuracy)

        while not stopping_criterion.is_stop():
            # Select a subset of Uind according to the query strategy