def test_init(): with pytest.raises(ValueError): ToolBox(y[0:5], X, query_type='AllLabels', saving_path=None) with pytest.raises(NotImplementedError): ToolBox(y, X, query_type='AllLabel', saving_path=None) with pytest.raises(Exception): ToolBox(y, x=None, query_type='Features', saving_path=None)
def test_get_split(): with pytest.raises(Exception): t = ToolBox(X=X, y=y, query_type='AllLabels', saving_path=None) a, b, c, d = t.get_split() tb.split_AL(test_ratio=0.3, initial_label_rate=0.1, split_count=split_count) a, b, c, d = tb.get_split() assert (check_one_to_one_correspondence(a, b, c, d))
n_features=20, n_informative=2, n_redundant=2, n_repeated=0, n_classes=2, n_clusters_per_class=2, weights=None, flip_y=0.01, class_sep=1.0, hypercube=True, shift=0.0, scale=1.0, shuffle=True, random_state=None) split_count = 5 acebox = ToolBox(X=X, y=y, query_type='AllLabels', saving_path=None) # split data acebox.split_AL(test_ratio=0.3, initial_label_rate=0.1, split_count=split_count) # use the default Logistic Regression classifier model = acebox.get_default_model() # query 50 times stopping_criterion = acebox.get_stopping_criterion('num_of_queries', 50) # use pre-defined strategy, The data matrix is a reference which will not use additional memory randomStrategy = QueryRandom() uncertainStrategy = QueryInstanceUncertainty(X, y)
import os import numpy as np from sklearn.datasets import load_iris from acepy.experiment import State, StateIO from acepy.toolbox import ToolBox X, y = load_iris(return_X_y=True) split_count = 5 cur_path = os.path.abspath('.') toolbox = ToolBox(X=X, y=y, query_type='AllLabels', saving_path=cur_path) # split data toolbox.split_AL(test_ratio=0.3, initial_label_rate=0.1, split_count=split_count) train_ind, test_ind, L_ind, U_ind = toolbox.get_split(round=0) # -------Initialize StateIO---------- saver = StateIO(round=0, train_idx=train_ind, test_idx=test_ind, init_L=L_ind, init_U=U_ind, saving_path='.') # or by using toolbox # saver = toolbox.get_stateio(round=0) saver.init_L.difference_update([0, 1, 2]) saver.init_U.update([0, 1, 2]) # -------Basic operations------------ st1_batch1 = State(select_index=[1], performance=0.89) my_value = 'my_entry_info' st1_batch1.add_element(key='my_entry', value=my_value) st1_batch2 = State(select_index=[0, 1], performance=0.89) st2_batch1 = State(select_index=[0], performance=0.89) st3_batch1 = State(select_index=[2], performance=0.89)