Update README.md
Browse files
README.md
CHANGED
|
@@ -644,26 +644,39 @@ We used the following python script to create this Hugging Face dataset.
|
|
| 644 |
|
| 645 |
```python
|
| 646 |
# Load the dataset into a pandas DataFrame
|
| 647 |
-
|
| 648 |
import pandas as pd
|
| 649 |
df_compas = pd.read_csv("https://github.com/propublica/compas-analysis/raw/master/compas-scores-two-years.csv")
|
| 650 |
|
| 651 |
from datasets import Dataset, DatasetDict, Features, Value, ClassLabel
|
| 652 |
|
| 653 |
# Define continuous (numerical) and categorical columns
|
| 654 |
-
categorical_columns =
|
| 655 |
"sex", "age_cat", "race", "c_charge_degree", "c_charge_desc", "is_recid",
|
| 656 |
"r_charge_degree", "violent_recid", "is_violent_recid", "vr_charge_degree",
|
| 657 |
"type_of_assessment", "score_text", "v_type_of_assessment", "v_score_text",
|
| 658 |
"event", "two_year_recid"
|
| 659 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 660 |
|
| 661 |
-
string_columns = [
|
| 662 |
-
"name", "first", "last",
|
| 663 |
-
"compas_screening_date", "dob", "c_jail_in", "c_jail_out", "c_offense_date",
|
| 664 |
-
"c_arrest_date", "r_offense_date", "r_jail_in", "r_jail_out", "vr_offense_date",
|
| 665 |
-
"screening_date", "v_screening_date", "start", "end", 'c_case_number', 'r_case_number', 'r_charge_desc'
|
| 666 |
-
]
|
| 667 |
|
| 668 |
# Convert categorical columns to category type and store mappings
|
| 669 |
category_mappings = {}
|
|
@@ -672,8 +685,7 @@ for col in categorical_columns:
|
|
| 672 |
|
| 673 |
# Define Hugging Face dataset schema
|
| 674 |
hf_features = Features({
|
| 675 |
-
|
| 676 |
-
**{col: Value("string") for col in list(df_compas.columns) if col not in categorical_columns}
|
| 677 |
})
|
| 678 |
|
| 679 |
# Create a dataset dictionary
|
|
@@ -690,7 +702,7 @@ The printed output could look like
|
|
| 690 |
```
|
| 691 |
DatasetDict({
|
| 692 |
train: Dataset({
|
| 693 |
-
features: ['
|
| 694 |
num_rows: 7214
|
| 695 |
})
|
| 696 |
})
|
|
|
|
| 644 |
|
| 645 |
```python
|
| 646 |
# Load the dataset into a pandas DataFrame
|
|
|
|
| 647 |
import pandas as pd
|
| 648 |
df_compas = pd.read_csv("https://github.com/propublica/compas-analysis/raw/master/compas-scores-two-years.csv")
|
| 649 |
|
| 650 |
from datasets import Dataset, DatasetDict, Features, Value, ClassLabel
|
| 651 |
|
| 652 |
# Define continuous (numerical) and categorical columns
|
| 653 |
+
categorical_columns = {
|
| 654 |
"sex", "age_cat", "race", "c_charge_degree", "c_charge_desc", "is_recid",
|
| 655 |
"r_charge_degree", "violent_recid", "is_violent_recid", "vr_charge_degree",
|
| 656 |
"type_of_assessment", "score_text", "v_type_of_assessment", "v_score_text",
|
| 657 |
"event", "two_year_recid"
|
| 658 |
+
}
|
| 659 |
+
|
| 660 |
+
string_columns = {'c_case_number',
|
| 661 |
+
'first',
|
| 662 |
+
'last',
|
| 663 |
+
'name',
|
| 664 |
+
'r_case_number',
|
| 665 |
+
'r_charge_desc',
|
| 666 |
+
'violent_recid',
|
| 667 |
+
'vr_case_number',
|
| 668 |
+
'vr_charge_desc',
|
| 669 |
+
'c_jail_in', 'c_jail_out'
|
| 670 |
+
}
|
| 671 |
+
|
| 672 |
+
date_columns = {'compas_screening_date',
|
| 673 |
+
'c_offense_date',
|
| 674 |
+
'c_arrest_date',
|
| 675 |
+
'r_offense_date',
|
| 676 |
+
'vr_offense_date',
|
| 677 |
+
'screening_date',
|
| 678 |
+
'v_screening_date','dob', 'r_jail_in', 'r_jail_out', 'in_custody', 'out_custody'}
|
| 679 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 680 |
|
| 681 |
# Convert categorical columns to category type and store mappings
|
| 682 |
category_mappings = {}
|
|
|
|
| 685 |
|
| 686 |
# Define Hugging Face dataset schema
|
| 687 |
hf_features = Features({
|
| 688 |
+
col: Value("date32") if col in date_columns else Value("string") if col in string_columns else ClassLabel(names=category_mappings[col]) if col in categorical_columns else Value("int64") for col in df_compas.columns
|
|
|
|
| 689 |
})
|
| 690 |
|
| 691 |
# Create a dataset dictionary
|
|
|
|
| 702 |
```
|
| 703 |
DatasetDict({
|
| 704 |
train: Dataset({
|
| 705 |
+
features: ['id', 'name', 'first', 'last', 'compas_screening_date', 'sex', 'dob', 'age', 'age_cat', 'race', 'juv_fel_count', 'decile_score', 'juv_misd_count', 'juv_other_count', 'priors_count', 'days_b_screening_arrest', 'c_jail_in', 'c_jail_out', 'c_case_number', 'c_offense_date', 'c_arrest_date', 'c_days_from_compas', 'c_charge_degree', 'c_charge_desc', 'is_recid', 'r_case_number', 'r_charge_degree', 'r_days_from_arrest', 'r_offense_date', 'r_charge_desc', 'r_jail_in', 'r_jail_out', 'violent_recid', 'is_violent_recid', 'vr_case_number', 'vr_charge_degree', 'vr_offense_date', 'vr_charge_desc', 'type_of_assessment', 'decile_score.1', 'score_text', 'screening_date', 'v_type_of_assessment', 'v_decile_score', 'v_score_text', 'v_screening_date', 'in_custody', 'out_custody', 'priors_count.1', 'start', 'end', 'event', 'two_year_recid'],
|
| 706 |
num_rows: 7214
|
| 707 |
})
|
| 708 |
})
|