secml icon indicating copy to clipboard operation
secml copied to clipboard

Poisoning Multiclass dataset

Open GiorgosMandi opened this issue 1 year ago • 0 comments

I am trying to poison a multiclass dataset, however, whichever poisoning strategy I use I get an error that looks like this:

ValueError: The data (x,y) has more than two classes.

or in the case of CAttackPoisoningSVM

ValueError: input labels should be binary in {0, +1} interval

I have tried to wrap my secml classifier with CClassifierMulticlassOVA but then I get:

NotImplementedError: We cannot poisoning that classifier

So, does secml supports the poisoning of multiclass datasets? and If yes how?

Thank you in advance.

Steps to reproduce

# x_train is a np.ndarray
# y_train is a np.ndarray consisting of multiple classes
dataset_train = CDataset(x_train, y_train)
clf = CClassifierSVM(kernel=CKernelRBF(gamma=0.001), C=1)
clf.fit(dataset_train.X, dataset_train.Y)
lb, ub = dataset_train.X.min(), dataset_train.X.max()
solver_params = {
    'eta': eps,
    'max_iter': max_iter,
    'eps': eps
}
pois_attack = CAttackPoisoningSVM(classifier=clf,
                                  training_data=dataset_train,
                                  val=dataset_train,
                                  lb=lb, ub=ub,
                                  dmax=1,
                                  solver_type='pgd',
                                  solver_params=solver_params)

pois_attack.n_points = adversarial_points_indices.shape[0]
pois_y_pred, pois_scores, pois_ds, f_opt = pois_attack.run(x=dataset_train.X, y=dataset_train.Y)

Output:

ValueError: input labels should be binary in {0, +1} interval

GiorgosMandi avatar Nov 09 '22 12:11 GiorgosMandi