Skip to content

Commit

Permalink
Correct DataFrame numeric handle
Browse files Browse the repository at this point in the history
Signed-off-by: rmazzine <[email protected]>
  • Loading branch information
rmazzine committed Sep 12, 2023
1 parent 6c07992 commit 770121c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions dice_ml/counterfactual_explanations.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ def plot_counterplots(self, dice_model):
"""
counterplots_out = []
for cf_examples in self.cf_examples_list:
features_names = list(cf_examples.test_instance_df.columns)[:-1]
features_dtypes = list(cf_examples.test_instance_df.dtypes)[:-1]
self.features_names = list(cf_examples.test_instance_df.columns)[:-1]
self.features_dtypes = list(cf_examples.test_instance_df.dtypes)[:-1]
factual_instance = cf_examples.test_instance_df.to_numpy()[0][:-1]

def convert_data(x):
df_x = pd.DataFrame(data=x, columns=features_names)
df_x = pd.DataFrame(data=x, columns=self.features_names)
# Transform each dtype according to features_dtypes
for feature_name, f_dtype in zip(features_names, features_dtypes):
df_x[feature_name] = df_x[feature_name].astype(f_dtype)
for feature_name, f_dtype in zip(self.features_names, self.features_dtypes):
df_x[feature_name] = pd.to_numeric(df_x[feature_name], errors='ignore').astype(f_dtype)

return df_x

Expand Down Expand Up @@ -158,7 +158,7 @@ def model_pred(x):
factual=factual_instance,
cf=cf_instance[:-1],
model_pred=model_pred,
feature_names=features_names,
feature_names=self.features_names,
))
return counterplots_out

Expand Down

0 comments on commit 770121c

Please sign in to comment.