robusttrees

[ICML 2019, 20 min long talk] Robust Decision Trees Against Adversarial Examples

https://github.com/chenhongge/robusttrees

Science Score: 28.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: arxiv.org
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (16.3%) to scientific vocabulary

Keywords

adversarial-examples decision-trees gbdt gbm gbrt robust-decision-trees xgboost
Last synced: 9 months ago · JSON representation ·

Repository

[ICML 2019, 20 min long talk] Robust Decision Trees Against Adversarial Examples

Basic Info
Statistics
  • Stars: 67
  • Watchers: 7
  • Forks: 11
  • Open Issues: 4
  • Releases: 0
Topics
adversarial-examples decision-trees gbdt gbm gbrt robust-decision-trees xgboost
Created about 7 years ago · Last pushed 11 months ago
Metadata Files
Readme License Citation

README.md

Robust Decision Trees Against Adversarial Examples

We developed a novel algorithm to train robust decision tree based models (notably, Gradient Boosted Decision Tree). This repo contains our implementation under the XGBoost framework. We plan to merge robust training as a feature to XGBoost upstream in near future.

Please refer to our paper for more details on the proposed algorithm:

Hongge Chen, Huan Zhang, Duane Boning, and Cho-Jui Hsieh "Robust Decision Trees Against Adversarial Examples", ICML 2019 [video of the talk] [slides] [poster]

We also provide our implementation of an attack proposed in Kantchelian et al. ICML 2016 to test the robustness of a GBDT model. This method uses Mixed Integer Linear Programming (MILP) to find the exact minimum adversarial example.

Sep 4, 2019: Checkout our new tree ensemble verification method in NeurIPS 2019! It is much faster and very tight compared to MILP. [GitHub] [paper]

robust_gbdt

Installation

Clone this repo and compile it: git clone --recursive https://github.com/chenhongge/RobustTrees.git cd RobustTrees ./build.sh

For detailed compilation options please refer to XGBoost Documentation. For building Python package interface, see these instructions.

Run

Since our code is based on XGBoost with the addition of robust training, the interface is exactly the same as XGBoost. We use the same configuration file format as in XGBoost. To run a configuration file to train your model, simply run

./xgboost <configuration file> In data/ folder we provide some example configuration files to start with. See section download the dataset to download the required datasets. For example, to train a 200-tree MNIST model with depth 8 and epsilon 0.3, just run

./xgboost data/ori_mnist.conf

Configuration files with .unrob use natural training and those without .unrob use our proposed robust training. In natural training, the tree_method parameter is set as exact.

Configuration Parameters

We added two additional parameters to XGBoost:

(1) tree_method controls which training method to use. We add a new option robust_exact for this parameter. Setting tree_method = robust_exact will use our proposed robust training. For other training methods, please refer to XGBoost documentation.

(2) robust_eps is the L inifity perturbation norm (epsilon) used in training. Since the same epsilon value will be applied for all features, it is recommended to normalize your data (e.g., make sure all features are in range 0 - 1). Normalization will not change tree performance

Please refer to XGBoost Documentation for all other parameters used in XGBoost.

Known Issues

XGBoost treats all missing feature values in LIBSVM input file as actually "missing" and deals with them specially to improve accuracy. But in our robust training setting, we assume no missing values, since a perturbation from "missing" to a certain epsilon value is not clearly defined. To workaround this issue, it is suggested to manually add 0 back for all missing values in LIBSVM input so that XGBoost treats them as 0 values rather than missing values. Otherwise, when evaluating robustness, if a model is trained on datasets with missing values and tested on a point with missing feature values, that missing feature should not be perturbed in an attack.

Note that in the original LIBSVM format, missing features values are defined as 0. Applying the workaround above will need to explicitly write 0 features in LIBSVM input. We will add an option to provide a cleaner fix to this issue in a future release.

Reproducing Results on Our Paper

Download the datasets

First download the datasets. We normalized all feature values to [0,1] already.

bash cd data ./download_data.sh

You may also run each line of download_data.sh to download each individual dataset. The datasets are in LIBSVM format.

Now just run each configuration file to train models, for example:

```bash

train a robust MNIST model, epsilon is set to 0.3 in conf file

./xgboost data/ori_mnist.conf

train a natural MNIST model

./xgboost data/ori_mnist.unrob.conf ```

Testing Robustness

Here we provide our implementation of an attack proposed in Kantchelian et al. ICML 2016 to test the robustness of a GBDT model. This method uses Mixed Integer Linear Programming (MILP) to find the exact minimum adversarial example. The formulation in the original paper can only handle binary classification models. We generalized this formulation to multi-class models by targeting all classes other than the predicted one.

This code uses Gurobi to solve the MILP problem and is tested in Python 3.6.8. We suggest to use Conda to manage your Python environments. The following packages need to be installed:

```bash

just install the original XGBoost

conda install -c conda-forge xgboost conda install -c gurobi gurobi conda install -c anaconda scipy conda install -c anaconda scikit-learn conda install -c anaconda numpy ```

After training, you will get a .model file. We provide robust and natural 200-tree MNIST models in mnist_models/. To run the attack, simply do

python xgbKantchelianAttack.py -d=<path to data> -m=<path to the model> -c=<number of classes>

Some datasets' LIBSVM may index the features starting from 0, such as HIGGS and cod-rna. If that is the case, add a parameter --feature_start=0.

You can also use -o=<which point to start>, -n=<how many point to be attacked> to choose the points you want to attack.

In Kantchelian et al.'s algorithm, a guard value is used, which can be specified with --guard_val=<guard value>. You may also round the threshold values in the model to certain number of digits by setting --round_digits=<number of digits>.

For example, to run attack on trained MNIST models in the previous step, download MNIST data and run:

```bash

attack robust MNIST model

python xgbKantchelianAttack.py -d=data/orimnist.test0 -m=mnistmodels/robustmnist0200.model -c=10

attack natural MNIST model

python xgbKantchelianAttack.py -d=data/orimnist.test0 -m=mnistmodels/naturalmnist0200.model -c=10 ```

The output of the script will give us average Linf distortion and running time over all examples.

Known Issues

This implemetation of Kantchelian's attack is based on the .json model file dumped by XGBoost. XGBoost can only offer precision up to 8 digits, but the minimum difference between two nodes' thresholds in the json file can be smaller than 1e-8 (due to floating-point error in dump). Here rounding may be an option, but it may be tricky to choose guard value after rounding. For example, if we round thresholds to 1e-6, then guard value should be at least less than 5e-7 to avoid mistake. If we do not round thresholds, XGBoost's predict() may give wrong results on some adversarial examples. Those adversarial examples are perturbed across the thresholds, but since the perturbation is so small, in XGBoost's predict(), the perturbation fails to misclassify. Therefore, we add a manual predict function to give output based on the .json tree file produced by XGBoost. This manual prediction should always work.

Owner

  • Name: Hongge Chen
  • Login: chenhongge
  • Kind: user
  • Location: Cambridge, MA, USA
  • Company: MIT

PhD, MIT EECS, chenhonggecn@gmail.com

Citation (CITATION)

@inproceedings{Chen:2016:XST:2939672.2939785,
 author = {Chen, Tianqi and Guestrin, Carlos},
 title = {{XGBoost}: A Scalable Tree Boosting System},
 booktitle = {Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining},
 series = {KDD '16},
 year = {2016},
 isbn = {978-1-4503-4232-2},
 location = {San Francisco, California, USA},
 pages = {785--794},
 numpages = {10},
 url = {http://doi.acm.org/10.1145/2939672.2939785},
 doi = {10.1145/2939672.2939785},
 acmid = {2939785},
 publisher = {ACM},
 address = {New York, NY, USA},
 keywords = {large-scale machine learning},
}

GitHub Events

Total
  • Watch event: 1
  • Pull request event: 1
  • Create event: 1
Last Year
  • Watch event: 1
  • Pull request event: 1
  • Create event: 1

Issues and Pull Requests

Last synced: 9 months ago

All Time
  • Total issues: 3
  • Total pull requests: 5
  • Average time to close issues: about 10 hours
  • Average time to close pull requests: 6 days
  • Total issue authors: 3
  • Total pull request authors: 2
  • Average comments per issue: 1.0
  • Average comments per pull request: 0.0
  • Merged pull requests: 2
  • Bot issues: 0
  • Bot pull requests: 4
Past Year
  • Issues: 0
  • Pull requests: 1
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 1
Top Authors
Issue Authors
  • EvanGertis (1)
  • Baptiste-Moreau (1)
  • snazrul1 (1)
Pull Request Authors
  • dependabot[bot] (4)
  • weifanjiang (1)
Top Labels
Issue Labels
Pull Request Labels
dependencies (4) java (1)

Dependencies

R-package/DESCRIPTION cran
  • R >= 3.3.0 depends
  • Matrix >= 1.1 imports
  • data.table >= 1.9.6 imports
  • magrittr >= 1.5 imports
  • methods * imports
  • stringi >= 0.5.2 imports
  • Ckmeans.1d.dp >= 3.3.1 suggests
  • DiagrammeR >= 0.9.0 suggests
  • ggplot2 >= 1.0.1 suggests
  • igraph >= 1.0.1 suggests
  • knitr * suggests
  • lintr * suggests
  • rmarkdown * suggests
  • testthat * suggests
  • vcd >= 1.3 suggests
jvm-packages/pom.xml maven
  • com.esotericsoftware.kryo:kryo 2.21
  • commons-logging:commons-logging 1.2
  • org.scala-lang:scala-compiler 2.13.3
  • org.scala-lang:scala-library 2.13.3
  • org.scala-lang:scala-reflect 2.13.3
  • org.scalatest:scalatest_2.11 3.0.0 test
jvm-packages/xgboost4j/pom.xml maven
  • com.typesafe.akka:akka-actor_${scala.binary.version} 2.3.11 compile
  • com.typesafe.akka:akka-testkit_${scala.binary.version} 2.3.11 test
  • junit:junit 4.13.1 test
jvm-packages/xgboost4j-example/pom.xml maven
  • org.apache.spark:spark-mllib_${scala.binary.version} ${spark.version} provided
  • ml.dmlc:xgboost4j-flink 0.80-SNAPSHOT
  • ml.dmlc:xgboost4j-spark 0.80-SNAPSHOT
  • org.apache.commons:commons-lang3 3.4
jvm-packages/xgboost4j-flink/pom.xml maven
  • ml.dmlc:xgboost4j 0.80-SNAPSHOT
  • org.apache.commons:commons-lang3 3.4
  • org.apache.flink:flink-clients_${scala.binary.version} ${flink.version}
  • org.apache.flink:flink-ml_${scala.binary.version} ${flink.version}
  • org.apache.flink:flink-scala_${scala.binary.version} ${flink.version}
jvm-packages/xgboost4j-spark/pom.xml maven
  • org.apache.spark:spark-core_${scala.binary.version} ${spark.version} provided
  • org.apache.spark:spark-mllib_${scala.binary.version} ${spark.version} provided
  • org.apache.spark:spark-sql_${scala.binary.version} ${spark.version} provided
  • ml.dmlc:xgboost4j 0.80-SNAPSHOT
doc/requirements.txt pypi
  • breathe *
  • guzzle_sphinx_theme *
  • mock *
  • sphinx *
python-package/setup.py pypi
  • numpy *
  • scipy *