Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: Samuel Hoffman <hoffman.sc@gmail.com>
  • Loading branch information
hoffmansc committed Feb 20, 2024
1 parent ab7e52a commit 0552881
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def LFR_optim_objective(x, X, y, priv):
x0 = rng.random(w_size + self.n_prototypes*n_feat)
bounds = [(0, 1)]*w_size + [(None, None)]*self.n_prototypes*n_feat
res = optim.minimize(LFR_optim_objective, x0=x0, method='L-BFGS-B',
args=(torch.tensor(X.to_numpy()), torch.as_tensor(y), priv),
args=(torch.tensor(X.to_numpy(dtype=x0.dtype)), torch.as_tensor(y), priv),
jac=True, bounds=bounds, options={'gtol': self.tol,
'maxiter': self.max_iter})

Expand Down
4 changes: 2 additions & 2 deletions aif360/sklearn/preprocessing/reweighing.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def fit_transform(self, X, y, sample_weight=None):
"""
X, y, sample_weight = check_inputs(X, y, sample_weight)

sample_weight_t = np.empty_like(sample_weight)
sample_weight_t = np.empty_like(sample_weight, dtype=float)
groups, self.prot_attr_ = check_groups(X, self.prot_attr)
# TODO: maintain categorical ordering
self.groups_ = np.unique(groups)
Expand All @@ -88,7 +88,7 @@ def N_(i): return sample_weight[i].sum()
for j, c in enumerate(self.classes_):
g_and_c = (groups == g) & (y == c)
if np.any(g_and_c):
W_gc = N_(groups == g) * N_(y == c) / (N * N_(g_and_c))
W_gc = N_(groups == g) / N * N_(y == c) / N_(g_and_c)
sample_weight_t[g_and_c] = W_gc * sample_weight[g_and_c]
self.reweigh_factors_[i, j] = W_gc
return X, sample_weight_t
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@
],
"source": [
"ohe = make_column_transformer(\n",
" (OneHotEncoder(sparse=False), X_train.dtypes == 'category'),\n",
" (OneHotEncoder(sparse_output=False), X_train.dtypes == 'category'),\n",
" remainder='passthrough', verbose_feature_names_out=False)\n",
"X_train = pd.DataFrame(ohe.fit_transform(X_train), columns=ohe.get_feature_names_out(), index=X_train.index)\n",
"X_test = pd.DataFrame(ohe.transform(X_test), columns=ohe.get_feature_names_out(), index=X_test.index)\n",
Expand Down Expand Up @@ -784,8 +784,8 @@
],
"source": [
"np.random.seed(0) #for reproducibility\n",
"exp_grad_red = ExponentiatedGradientReduction(prot_attr=prot_attr_cols, \n",
" estimator=estimator, \n",
"exp_grad_red = ExponentiatedGradientReduction(prot_attr=prot_attr_cols,\n",
" estimator=estimator,\n",
" constraints=\"EqualizedOdds\",\n",
" drop_prot_attr=False)\n",
"exp_grad_red.fit(X_train, y_train)\n",
Expand Down Expand Up @@ -916,11 +916,11 @@
}
],
"source": [
"import fairlearn.reductions as red \n",
"import fairlearn.reductions as red\n",
"\n",
"np.random.seed(0) #need for reproducibility\n",
"exp_grad_red2 = ExponentiatedGradientReduction(prot_attr=prot_attr_cols, \n",
" estimator=estimator, \n",
"exp_grad_red2 = ExponentiatedGradientReduction(prot_attr=prot_attr_cols,\n",
" estimator=estimator,\n",
" constraints=red.EqualizedOdds(),\n",
" drop_prot_attr=False)\n",
"exp_grad_red2.fit(X_train, y_train)\n",
Expand Down
2 changes: 1 addition & 1 deletion tests/sklearn/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_german_matches_old():
old = old.apply(lambda c: c.factorize()[0] if not is_numeric_dtype(c) else c)

assert_frame_equal(X.reset_index(drop=True), old.reset_index(drop=True),
check_like=True)
check_like=True, check_dtype=False)

def test_fetch_bank():
"""Tests Bank Marketing dataset shapes with various options."""
Expand Down

0 comments on commit 0552881

Please sign in to comment.