Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tests failing due to int columns #513

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading