1

I am asking dimensional wise etc. I am trying to implement this amazing work with random forest https://www.kaggle.com/allunia/how-to-attack-a-machine-learning-model/notebook

Both logistic regression and random forest are from sklearn but when I get weights from random forest model its (784,) while the logistic regression returns (10,784)

My most problems are mainly dimension and NaN, infinity or a value too large for dtype errors with attack methods. The weights using logical regression is (10,784) but with Random Forest its (784,) may be this caused the problem? Or can you suggest some modifications to attack methods? I tried Imputer for NaN values error but it wanted me to reshape so I've got this. I tried applying np.mat for the dimension errors I'm getting but they didnt work.

def non_targeted_gradient(target, output, w):
    target = target.reshape(1, -1)
    output = output.reshape(1, -1)
    w = w.reshape(1,-1)
    target = imp.fit_transform(target)
    output = imp.fit_transform(output)
    w = imp.fit_transform(w)
    ww = calc_output_weighted_weights(output, w)
    for k in range(len(target)):
        if k == 0:
            gradient = np.mat((1-target[k])) * np.mat((w[k]-ww))
        else:
            gradient += np.mat((1-target[k])) * np.mat((w[k]-ww))
    return gradient

I'm probably doing lots of things wrong but the TL;DR is I'm trying to apply Random Forest instead of Logistic regression at the link above.

Edit:

I've added a wrapper for randomforestclassifier:

class RandomForestWrapper(RandomForestClassifier):
    def fit(self, *args, **kwargs):
        super(RandomForestClassifierWithCoef, self).fit(*args, **kwargs)
        self.coef_ = self.feature_importances_
Jeredriq Demas
  • 616
  • 1
  • 9
  • 36
  • 2
    First, `RandomForestClassifier` does not have any `coef_` attribute you can use as weights. Second, assuming by the output shape, I think that you are using `feature_importances_` attribute of the `RandomForestClassifier` which is wrong, because feature importances are not equal to coefficients which you can directly apply to a new sample. – Vivek Kumar Dec 10 '18 at 09:45
  • @VivekKumar I've did it as shown above and you're right dear sir astonishing guess. So what should I do instead? – Jeredriq Demas Dec 10 '18 at 10:42
  • No I dont think that can be done easily. Decision Trees use a different strategy to find the classes, so maybe you need to find the relevant papers containing the adversarial attack theory for decision trees and then implement those. – Vivek Kumar Dec 10 '18 at 11:04
  • @VivekKumar can you take a look at this question too? https://stackoverflow.com/questions/53827086/ – Jeredriq Demas Dec 18 '18 at 06:40

0 Answers0