Skip to content

Commit

Permalink
add compas examples - model and reality examples
Browse files Browse the repository at this point in the history
  • Loading branch information
TFRicardoMoya committed Dec 1, 2023
1 parent 79091e8 commit d15981d
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 50 deletions.
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[report]
omit =
setup.py
*test*
38 changes: 38 additions & 0 deletions examples/compas_reality_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-

u"""
© 2023 Telefónica Digital España S.L.
This file is part of XAIoGraphs.
XAIoGraphs is free software: you can redistribute it and/or modify it under the terms of the Affero GNU General Public
License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any
later version.
XAIoGraphs is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Affero GNU General Public License
for more details.
You should have received a copy of the Affero GNU General Public License along with XAIoGraphs. If not,
see https://www.gnu.org/licenses/."""

from xaiographs import Explainer
from xaiographs import Why
from xaiographs.datasets import load_compas_reality_discretized, load_compas_reality_why

LANG = 'en'

# LOAD DATASETS & SEMANTICS
df_compas, feature_cols, target_cols = load_compas_reality_discretized()
df_values_semantics, df_target_values_semantics = load_compas_reality_why(language=LANG)

# EXPLAINER
explainer = Explainer(importance_engine='LIDE', verbose=1)
explainer.fit(df=df_compas, feature_cols=feature_cols, target_cols=target_cols)

# WHY
why = Why(language=LANG,
explainer=explainer,
why_values_semantics=df_values_semantics,
why_target_values_semantics=df_target_values_semantics,
verbose=1)
why.fit()
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"titanic_example = xaiographs.examples.titanic_example:main",
"body_performance_example = xaiographs.examples.body_performance_example:main",
"education_performance_example = xaiographs.examples.education_performance_example:main",
"compas_example = xaiographs.examples.compas_example:main"
"compas_example = xaiographs.examples.compas_example:main",
"compas_reality_example = xaiographs.examples.compas_reality_example:main",
]
}
)
3 changes: 3 additions & 0 deletions xaiographs/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,6 @@
from .datasets import load_compas
from .datasets import load_compas_discretized
from .datasets import load_compas_why

from .datasets import load_compas_reality_discretized
from .datasets import load_compas_reality_why
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
target,feature_value,reason
Recid,Age_range_25 - 45,some in the age range between 25 and 45 years were repeat offenders
Recid,Age_range_Greater than 45,few of those over 45 were repeat offenders
Recid,Age_range_Less than 25,many of those under 25 years of age were repeat offenders
Recid,is_recid_NO,few were Non-recidivists
Recid,is_recid_YES,many were repeat offenders
Recid,is_violent_recid_NO,few were No Violent Repeat Offenders
Recid,is_violent_recid_YES,many were Violent Repeat Offenders
No_Recid,Age_range_25 - 45,some in the age range between 25 and 45 years were repeat offenders
No_Recid,Age_range_Greater than 45,many of those over 45 years of age were repeat offenders
No_Recid,Age_range_Less than 25,few people under 25 years of age were repeat offenders
No_Recid,is_recid_NO,many were Non-recidivists
No_Recid,is_recid_YES,few were repeat offenders
No_Recid,is_violent_recid_NO,many were Non-Violent Repeat Offenders
No_Recid,is_violent_recid_YES,few were Violent Repeat Offenders
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
target,feature_value,reason
Recid,Age_range_25 - 45,algunos del rango de edad entre 25 y 45 años fueron reincidentes
Recid,Age_range_Greater than 45,pocos de los mayores de 45 años fueron reincidentes
Recid,Age_range_Less than 25,muchos de los menores de 25 años fueron reincidentes
Recid,is_recid_NO,pocos eran No Reincidentes
Recid,is_recid_YES,muchos eran Reincidentes
Recid,is_violent_recid_NO,pocos eran No Reincidentes Violentos
Recid,is_violent_recid_YES,muchos eran Reincidentes Violentos
No_Recid,Age_range_25 - 45,algunos del rango de edad entre 25 y 45 años fueron reincidentes
No_Recid,Age_range_Greater than 45,muchos de los mayores de 45 años fueron reincidentes
No_Recid,Age_range_Less than 25,pocos menores de 25 años fueron reincidentes
No_Recid,is_recid_NO,muchos eran No Reincidentes
No_Recid,is_recid_YES,pocos eran Reincidentes
No_Recid,is_violent_recid_NO,muchos eran No Reincidentes Violentos
No_Recid,is_violent_recid_YES,pocos eran Reincidentes Violentos
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
feature_value,reason
Age_range_25 - 45,middle-aged
Age_range_Greater than 45,be older than 45 years
Age_range_Less than 25,be young
is_recid_NO,not being a repeat offender
is_recid_YES,be a repeat offender
is_violent_recid_NO,not being a repeat offender
is_violent_recid_YES,be a violent repeat offender
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
feature_value,reason
Age_range_25 - 45,ser de mediana edad
Age_range_Greater than 45,ser mayor de 45 años
Age_range_Less than 25,ser joven
is_recid_NO,no ser reincidente
is_recid_YES,ser reincidente
is_violent_recid_NO,no ser reincidente
is_violent_recid_YES,ser reincidente violento
Loading

0 comments on commit d15981d

Please sign in to comment.