Code Monkey home page Code Monkey logo

pysafe's Introduction

pysafe

Contact: Fares Meghdouri - [email protected]

Python implementation of the per-SAmple Feature Elimination algorithm

Installation

pyodm can be installed using pip by running pip install git+https://github.com/CN-TU/pysafe

Usage

Create a model

from pysafe import SAFE

# create a new model with default parameters
safe_model = SAFE('forward_selection', random_state=2020)

Scan a Keras model

import numpy
#import pandas

# read the data
X = np.load('my_data.npy')
y = np.load('my_labels.npy')
#or
#X = pandas.read_csv('my_data.csv')
#X = pandas.read_csv('my_datalabels.csv')

# scan the model for adversarial samples
safe_model.scan(keras_model, X, y, aim='worst')

# scan the model for improving accuracy
#safe_model.scan(keras_model, X, y, aim='better')

# get the robustness of each feature
print(safe_model.get_robustness())

# get the subliminal dataset data
print(safe_model.X)

# get the subliminal dataset labels
print(safe_model.y_worst)
print(safe_model.y_better)

Learn Combinations With a SAFE Model

# if you want to use knn
safe_model.learn(algorithm = 'knn')

# if you want to use ann with predefined model
#safe_model.learn(algorithm = 'ann')

# if you want to pass your pre-trained model
#safe_model.learn(algorithm = 'ann', learner=my_model)

# if you want to pass your empty model
#safe_model.learn(algorithm = 'ann', learner=my_model, train=True)

Robustness of Features in a Dataset

safe_model.get_robustness(data=my_dataset)

Features to Select in a Test Set

# to get the combinations
safe_model.get_selection(data=my_dataset)

# to apply the combinations on a dataset (without typing the previous command)
safe_model.clean_data(data=my_dataset)

Compare Accuracy Before and After SAFE

safe_model.get_accuracy(data=my_data, labels=my_labels)

Behaviour of a Sample Before and After SAFE

safe_model.get_behaviour(data=my_data_sample)
# this will yield the prediction before and after SAFE

Get Adversarial Sample Candidates

# get all candidates in a dataset that can chnage their prediction by a value higher than a threshold (0.9)
safe_model.get_candidates(data=my_dataset, threshold=0.9)

pysafe's People

Contributors

fm94 avatar

Watchers

James Cloos avatar  avatar

Forkers

cn-tu

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.