예제 #1
0
def pyt_model_object():
    backend = 'PYT'
    ML_modelpath = helpers.get_adult_income_modelpath(backend=backend)
    m = dice_ml.Model(model_path=ML_modelpath,
                      backend=backend,
                      func='ohe-min-max')
    return m
예제 #2
0
 def _get_exp(self, backend, method="random"):
     dataset = helpers.load_adult_income_dataset()
     d = dice_ml.Data(dataframe=dataset, continuous_features=['age', 'hours_per_week'], outcome_name='income')
     ML_modelpath = helpers.get_adult_income_modelpath(backend=backend)
     m = dice_ml.Model(model_path=ML_modelpath, backend=backend)
     exp = dice_ml.Dice(d, m, method=method)
     return exp
def tf_model_object():
    backend = 'TF' + tf.__version__[0]
    ML_modelpath = helpers.get_adult_income_modelpath(backend=backend)
    m = dice_ml.Model(model_path=ML_modelpath,
                      backend=backend,
                      func='ohe-min-max')
    return m
예제 #4
0
파일: test_dice.py 프로젝트: rmazzine/DiCE
 def _get_exp(self,
              backend,
              method="random",
              is_public_data_interface=True):
     if is_public_data_interface:
         dataset = helpers.load_adult_income_dataset()
         d = dice_ml.Data(dataframe=dataset,
                          continuous_features=['age', 'hours_per_week'],
                          outcome_name='income')
     else:
         d = dice_ml.Data(features={
             'age': [17, 90],
             'workclass':
             ['Government', 'Other/Unknown', 'Private', 'Self-Employed'],
             'education': [
                 'Assoc', 'Bachelors', 'Doctorate', 'HS-grad', 'Masters',
                 'Prof-school', 'School', 'Some-college'
             ],
             'marital_status':
             ['Divorced', 'Married', 'Separated', 'Single', 'Widowed'],
             'occupation': [
                 'Blue-Collar', 'Other/Unknown', 'Professional', 'Sales',
                 'Service', 'White-Collar'
             ],
             'race': ['Other', 'White'],
             'gender': ['Female', 'Male'],
             'hours_per_week': [1, 99]
         },
                          outcome_name='income')
     ML_modelpath = helpers.get_adult_income_modelpath(backend=backend)
     m = dice_ml.Model(model_path=ML_modelpath, backend=backend)
     exp = dice_ml.Dice(d, m, method=method)
     return exp
예제 #5
0
def pyt_exp_object():
    backend = 'PYT'
    dataset = helpers.load_adult_income_dataset()
    d = dice_ml.Data(dataframe=dataset, continuous_features=['age', 'hours_per_week'], outcome_name='income')
    ML_modelpath = helpers.get_adult_income_modelpath(backend=backend)
    m = dice_ml.Model(model_path= ML_modelpath, backend=backend)
    exp = dice_ml.Dice(d, m)
    return exp
예제 #6
0
def test_model_initiation_fullpath():
    """
    Tests if model is initiated when full path to a model and explainer class is given to backend parameter.
    """
    pyt = pytest.importorskip("torch")
    backend = {'model': 'pytorch_model.PyTorchModel',
            'explainer': 'dice_pytorch.DicePyTorch'}
    ML_modelpath = helpers.get_adult_income_modelpath(backend=backend)
    m = dice_ml.Model(model_path= ML_modelpath, backend=backend)
    assert isinstance(m, dice_ml.model_interfaces.pytorch_model.PyTorchModel)
def test_model_initiation_fullpath():
    """
    Tests if model is initiated when full path to a model and explainer class is given to backend parameter.
    """
    tf_version = tf.__version__[0]
    backend = {
        'model':
        'keras_tensorflow_model.KerasTensorFlowModel',
        'explainer':
        'dice_tensorflow' + tf_version + '.DiceTensorFlow' + tf_version
    }
    ML_modelpath = helpers.get_adult_income_modelpath(backend=backend)
    m = dice_ml.Model(model_path=ML_modelpath, backend=backend)
    assert isinstance(
        m,
        dice_ml.model_interfaces.keras_tensorflow_model.KerasTensorFlowModel)
예제 #8
0
 def _get_model(self, backend):
     ML_modelpath = helpers.get_adult_income_modelpath(backend=backend)
     m = dice_ml.Model(model_path=ML_modelpath, backend=backend)
     return m
예제 #9
0
from dice_ml.utils import helpers # helper functions
from dice_ml.data_interfaces import public_data_interface
import numpy as np
import tensorflow as tf
from dice_ml.model_interfaces import keras_tensorflow_model
from dice_ml.dice_interfaces import dice_tensorflow2
import sys 
if __name__ == "__main__":
    data = helpers.load_adult_income_dataset()
    params = {}
    params['dataframe'] = data
    params['continuous_features'] = ['age', 'hours_per_week']
    params['outcome_name'] = 'income'
    
    data_inter = public_data_interface.PublicData(params)
    model_path = helpers.get_adult_income_modelpath()
    print("Loading model ")
    model = keras_tensorflow_model.KerasTensorFlowModel(model_path=model_path)
    print("Loading CE")
    dice = dice_tensorflow2.DiceTensorFlow2(data_inter, model)
	#
    query_instance = {'age':22,
                      'workclass':'Private',
                      'education':'HS-grad',
                      'marital_status':'Single',
                      'occupation':'Service',
                      'race': 'White',
                      'gender':'Female',
                      'hours_per_week': 45}
    counterfactual_samples  = dice.generate_counterfactuals(query_instance, total_CFs=4, desired_class="opposite")