File size: 2,643 Bytes
fcf6191
 
6849df4
 
 
a7490ff
6849df4
 
8477b23
 
 
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
8477b23
 
a7490ff
 
 
 
6849df4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a7490ff
6849df4
 
 
 
 
 
 
 
 
 
 
 
 
8477b23
6849df4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
---
license: mit
tags:
- tabular-classification
- sklearn
- imodels
datasets:
- imodels/compas-recidivism
widget:
  structuredData:
    age:
      - 40.0
      - 25.0
      - 36.0
      - 23.0
      - 29.0
    priors_count:
      - 0.0
      - 1.0
      - 11.0
      - 1.0
      - 0.0
    days_b_screening_arrest:
      - -1.0
      - -1.0
      - -1.0
      - -1.0
      - 0.0
    c_jail_time:
      - 0.0
      - 1.0
      - 2.0
      - 0.0
      - -1.0
    juv_fel_count:
      - 0.0
      - 0.0
      - 0.0
      - 0.0
      - 0.0
    juv_other_count:
      - 0.0
      - 0.0
      - 0.0
      - 0.0
      - 0.0
    juv_misd_count:
      - 0.0
      - 0.0
      - 0.0
      - 1.0
      - 0.0
    c_charge_degree:F:
      - 0.0
      - 1.0
      - 0.0
      - 0.0
      - 0.0
    c_charge_degree:M:
      - 1.0
      - 0.0
      - 1.0
      - 1.0
      - 1.0
    race:African-American:
      - 0.0
      - 0.0
      - 0.0
      - 0.0
      - 0.0
    race:Asian:
      - 0.0
      - 0.0
      - 0.0
      - 0.0
      - 0.0
    race:Caucasian:
      - 1.0
      - 0.0
      - 1.0
      - 1.0
      - 1.0
    race:Hispanic:
      - 0.0
      - 0.0
      - 0.0
      - 0.0
      - 0.0
    race:Native_American:
      - 0.0
      - 0.0
      - 0.0
      - 0.0
      - 0.0
    race:Other:
      - 0.0
      - 1.0
      - 0.0
      - 0.0
      - 0.0
    age_cat:25_-_45:
      - 1.0
      - 1.0
      - 1.0
      - 0.0
      - 1.0
    age_cat:Greater_than_45:
      - 0.0
      - 0.0
      - 0.0
      - 0.0
      - 0.0
    age_cat:Less_than_25:
      - 0.0
      - 0.0
      - 0.0
      - 1.0
      - 0.0
    sex:Female:
      - 0.0
      - 0.0
      - 0.0
      - 0.0
      - 0.0
    sex:Male:
      - 1.0
      - 1.0
      - 1.0
      - 1.0
      - 1.0
---


### Load the data

```python
from datasets import load_dataset
import imodels
import numpy as np
from sklearn.model_selection import GridSearchCV
import joblib

dataset = load_dataset("imodels/compas-recidivism")
df = pd.DataFrame(dataset['train'])
X_train = df.drop(columns=['is_recid'])
y_train = df['is_recid'].values

df_test = pd.DataFrame(dataset['test'])
X_test = df.drop(columns=['is_recid'])
y_test = df['is_recid'].values
```

### Load the model

```python
from huggingface_hub import hf_hub_url, cached_download
import joblib
import pandas as pd

REPO_ID = "imodels/figs-compas-recidivism"
FILENAME = "sklearn_model.joblib"

model = joblib.load(cached_download(
    hf_hub_url(REPO_ID, FILENAME)
))

# model is a `imodels.FIGSClassifier`
```

### Make prediction

```
preds = model.predict(X_test)
print('accuracy', np.mean(preds==y_test))
# accuracy 0.6759165485112416
```