Commit 9dd4c529 authored by Katharine Jarmul's avatar Katharine Jarmul
Browse files

updating with model extraction

parent aad6ed25
Loading
Loading
Loading
Loading

data/car.data.csv

0 → 100644
+1728 −0

File added.

Preview size limit exceeded, changes collapsed.

data/car_cleaned.csv

0 → 100644
+1729 −0

File added.

Preview size limit exceeded, changes collapsed.

data/car_tree.pkl

0 → 100644
+14.6 KiB

File added.

No diff preview for this file type.

+105 −1
Changes for notebooks/03 - Model Extraction Attack.ipynb: 105 added lines, 1 removed line.
Original line number Diff line number Diff line
%% Cell type:code id: tags:

``` python
import sys
sys.path.append('../steal_ml/')
```

%% Cell type:code id: tags:

``` python
from sklearn.externals import joblib
from tree_stealer import *
from feature import *
```

%% Cell type:code id: tags:

``` python
model_to_query = joblib.load('../data/car_tree.pkl')
```

%% Cell type:code id: tags:

``` python
model_to_query.predict_log_proba?
```

%% Cell type:code id: tags:

``` python
class LocalPredictTreeExtractor(TreeExtractor):

    def get_classes(self):
        return list(range(1,5))

    def get_features(self):
        return [
            CatFeature('buying', 'buying', range(1,5)),
            ContFeature('maint', 'maint', 1, 4),
            ContFeature('doors', 'doors', 2, 5),
            ContFeature('persons', 'persons', 2, 8),
            ContFeature('lug_boot', 'lug_boot', 1, 3),
            CatFeature('safety', 'safety', range(1,5)),
        ]

    def make_prediction(self, query):
        prediction = model_to_query.predict([list(query.values())])

        return LeafID(prediction[0], .9,
                            self.rounding, query)
```

%% Cell type:code id: tags:

``` python
extractor = LocalPredictTreeExtractor()
```

%% Cell type:code id: tags:

``` python
all_leaves = extractor.extract()
```

%% Cell type:code id: tags:

``` python
for key, value in all_leaves.items():
    print(key.val)
    print(value)
```

%% Cell type:code id: tags:

``` python
extractor.queryCount
```

%% Cell type:code id: tags:

``` python
import pandas as pd
cleaned_data = pd.read_csv('../data/car_cleaned.csv')
```

%% Cell type:code id: tags:

``` python
cleaned_data.head()
```

%% Cell type:code id: tags:

``` python
model_to_query.predict([[4, 4, 4, 3, 4, 4]])
```

%% Cell type:markdown id: tags:

### Your Turn

- Try some of the data in the cleaned car dataset: Does the model predict it properly? Do the extracted rules also apply?
- Try out a few more of the rules you see above. Can you find one that is an error?
- Feel free to peruse the other attacks: https://github.com/ftramer/Steal-ML

%% Cell type:code id: tags:

``` python
```
+1133 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading