Closed sina-salek closed 4 years ago
Not sure why this error occurs, it's hard to say without looking at the code. Can you share your full code? It worked for me with the German credit data. Below is the code:
import dice_ml
from dice_ml.utils import helpers # helper functions
import tensorflow as tf
german = pd.read_csv('german_credit.csv')
german['credits_this_bank']= german['credits_this_bank'].astype(str) # has only 4 values - converting to categorical just for better results.
german['people_under_maintenance']= german['people_under_maintenance'].astype(str)
german_dtypes = german.columns.to_series().groupby(german.dtypes).groups
german_dtypes = {k.name: v.tolist() for k, v in german_dtypes.items()}
continuous_features = german_dtypes['int64']
continuous_features = [feat for feat in continuous_features if feat != 'default']
print(continuous_features) #['duration_in_month', 'credit_amount', 'installment_as_income_perc', 'present_res_since', 'age']
d = dice_ml.Data(dataframe=german, continuous_features=continuous_features, outcome_name='default')
query_instance = {'duration_in_month': 24.0,
'credit_amount': 1747.0,
'installment_as_income_perc': 4.0,
'present_res_since': 1.0,
'age': 24.0,
'account_check_status': '< 0 DM',
'credit_history': 'existing credits paid back duly till now',
'purpose': 'radio/television',
'savings': '... < 100 DM',
'present_emp_since': '... < 1 year ',
'personal_status_sex': 'male : single',
'other_debtors': 'co-applicant',
'property': 'if not A121 : building society savings agreement/ life insurance',
'other_installment_plans': 'none',
'housing': 'own',
'credits_this_bank': '1',
'job': 'unskilled - resident',
'people_under_maintenance': '1',
'telephone': 'none',
'foreign_worker': 'no'}
backend = 'TF'+tf.__version__[0] # TF2
print(backend)
m = dice_ml.Model(model_path= 'german_dice_ann.h5', backend=backend)
print(m.model.summary()) # trained on a neural net with 1 hidden layer of 20 neurons
dice_exp = exp.generate_counterfactuals(query_instance, total_CFs=4, desired_class="opposite", verbose=0)
dice_exp.visualize_as_dataframe(show_only_changes=True) # outputs 4 valid CFs
Let me know if you still face any difficulty.
Hmm! I'm not sure what happened. I just ran my own code and it works fine! Not sure what the problem was yesterday! Thanks again for your time.
Hi again, I understand you must be extremely busy. I appreciate your time.
I was now trying to use the same ANN model as in your notebook, but with the German credit data. The model trains fine. But I get the following error message when I try to run the line: dice_exp = exp.generate_counterfactuals(query_instance, total_CFs=4, desired_class=1)
I have copier the entire error message below. Thanks
divide by zero encountered in double_scalars
InvalidArgumentError Traceback (most recent call last)