Skip to content

Commit a4bb32e

Browse files
authored
Merge pull request #20 from Leona-LYT/main
modified `sen_idx` and add _sklearn_mixin.py
2 parents 8d1763c + 41fc805 commit a4bb32e

File tree

6 files changed

+492
-16
lines changed

6 files changed

+492
-16
lines changed

doc/source/examples/.ipynb_checkpoints/FairSVM-checkpoint.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
"X = scaler.fit_transform(X)\n",
5757
"\n",
5858
"## we take the first column of X as sensetive features, and tol is 0.1\n",
59-
"X_sen = X[:,0]\n",
59+
"sen_idx = [0]\n",
6060
"tol_sen = 0.1"
6161
]
6262
},
@@ -102,7 +102,7 @@
102102
"\n",
103103
"fclf = plqERM_Ridge(loss={'name': 'svm'},\n",
104104
" constraint=[{'name': 'fair',\n",
105-
" 'X_sen': X_sen,\n",
105+
" 'sen_idx': sen_idx,\n",
106106
" 'tol_sen': tol_sen}],\n",
107107
" C=1.0,\n",
108108
" max_iter=50000)\n",
@@ -142,8 +142,8 @@
142142
"svm_perf = len(y[score*y > 0])/n\n",
143143
"fsvm_perf = len(y[fscore*y > 0])/n\n",
144144
"\n",
145-
"svm_corr = score.dot(X_sen) / n\n",
146-
"fsvm_corr = fscore.dot(X_sen) / n\n",
145+
"svm_corr = score.dot(X[:,sen_idx]) / n\n",
146+
"fsvm_corr = fscore.dot(X[:,sen_idx]) / n\n",
147147
"\n",
148148
"# Create a pandas DataFrame to store the results\n",
149149
"results = pd.DataFrame({\n",

doc/source/examples/FairSVM.ipynb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@
3535
]
3636
},
3737
{
38-
"metadata": {},
3938
"cell_type": "markdown",
40-
"source": "",
41-
"id": "7bf9272115591bbf"
39+
"id": "7bf9272115591bbf",
40+
"metadata": {},
41+
"source": []
4242
},
4343
{
4444
"cell_type": "code",
@@ -61,7 +61,7 @@
6161
"X = scaler.fit_transform(X)\n",
6262
"\n",
6363
"## we take the first column of X as sensetive features, and tol is 0.1\n",
64-
"X_sen = X[:,0]\n",
64+
"sen_idx = [0]\n",
6565
"tol_sen = 0.1"
6666
]
6767
},
@@ -107,7 +107,7 @@
107107
"\n",
108108
"fclf = plqERM_Ridge(loss={'name': 'svm'},\n",
109109
" constraint=[{'name': 'fair',\n",
110-
" 'X_sen': X_sen,\n",
110+
" 'sen_idx': sen_idx,\n",
111111
" 'tol_sen': tol_sen}],\n",
112112
" C=1.0,\n",
113113
" max_iter=50000)\n",
@@ -205,7 +205,7 @@
205205
]
206206
}
207207
],
208-
"metadata": {
208+
"metadata": {
209209
"colab": {
210210
"provenance": []
211211
},
@@ -219,4 +219,4 @@
219219
},
220220
"nbformat": 4,
221221
"nbformat_minor": 0
222-
}
222+
}

doc/source/examples/Path_solution.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@
176176
"outputs": [],
177177
"source": [
178178
"## we take the first column of X as sensetive features, and tol is 0.1\n",
179-
"X_sen = X[:,0]\n",
179+
"sen_idx = [0]\n",
180180
"tol_sen = 0.1\n",
181181
"# define constraint\n",
182-
"constraint=[{'name': 'fair', 'X_sen': X_sen,'tol_sen': tol_sen}]\n",
182+
"constraint=[{'name': 'fair', 'sen_idx': sen_idx,'tol_sen': tol_sen}]\n",
183183
"# define loss function\n",
184184
"loss = {'name': 'SVM'}\n",
185185
"# define value of Cs\n",

doc/source/getting_started.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ With `rehline`, you can easily add a `fairness constraint` to your ERM.
126126
from scipy.stats import pearsonr
127127
# Define a Huber estimator with fairness constraint
128128
clf = plqERM_Ridge(loss={'name': 'huber', 'tau': 0.5},
129-
constraint=[{'name': 'fair', 'X_sen': X_train[:, 0], 'tol_sen': 0.1}],
129+
constraint=[{'name': 'fair', 'sen_idx': [0], 'tol_sen': 0.1}],
130130
C=1.0,
131131
max_iter=10000)
132132
clf.fit(X=X_train, y=y_train)

doc/source/tutorials/constraint.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ Usage
2828

2929
* - **fair**
3030
- | ``name``: 'fair' or 'fairness'
31-
| ``X_sen``: 2d array [n x p] for sensitive attributes
31+
| ``sen_idx``: a list contains column indices for sensitive attributes
3232
| ``tol_sen``: 1d array [p] of tolerance for fairness
33-
- | ``constraint=[{'name': 'fair', 'X_sen': X_sen, 'tol_sen': tol_sen}]``
33+
- | ``constraint=[{'name': 'fair', 'sen_idx': sen_idx, 'tol_sen': tol_sen}]``
3434

3535
* - **custom**
3636
- | ``name``: 'custom'

0 commit comments

Comments
 (0)