Skip to content

Commit

Permalink
Fixed cfproto adult OHE example. Replaced OHE sparse with OHE dense a…
Browse files Browse the repository at this point in the history
…nd fixed display function.
  • Loading branch information
RobertSamoilescu committed Sep 9, 2022
1 parent e95e66b commit b252075
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions doc/source/examples/cfproto_cat_adult_ohe.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@
"X_num = X[:, -4:].astype(np.float32, copy=False)\n",
"xmin, xmax = X_num.min(axis=0), X_num.max(axis=0)\n",
"rng = (-1., 1.)\n",
"X_num_scaled = (X_num - xmin) / (xmax - xmin) * (rng[1] - rng[0]) + rng[0]\n",
"X_num_scaled_train = X_num_scaled[:idx, :]\n",
"X_num_scaled_test = X_num_scaled[idx+1:, :]"
"X_num_scaled = (X_num - xmin) / (xmax - xmin) * (rng[1] - rng[0]) + rng[0]"
]
},
{
Expand All @@ -284,8 +282,7 @@
"outputs": [],
"source": [
"X_cat = X[:, :-4].copy()\n",
"ohe = OneHotEncoder(categories='auto')\n",
"ohe.fit(X_cat)\n",
"ohe = OneHotEncoder(categories='auto', sparse=False).fit(X_cat)\n",
"X_cat_ohe = ohe.transform(X_cat)"
]
},
Expand All @@ -310,7 +307,7 @@
}
],
"source": [
"X = np.c_[X_cat_ohe.todense(), X_num_scaled].astype(np.float32, copy=False)\n",
"X = np.c_[X_cat_ohe, X_num_scaled].astype(np.float32, copy=False)\n",
"X_train, X_test = X[:idx, :], X[idx+1:, :]\n",
"print(X_train.shape, X_test.shape)"
]
Expand Down Expand Up @@ -601,8 +598,8 @@
" print('\\nNumerical:')\n",
" delta_num = X_cf_ord[0, -4:] - X_orig_ord[0, -4:]\n",
" n_keys = len(list(cat_vars_ord.keys()))\n",
" for i in range(delta_num.shape[1]):\n",
" if np.abs(delta_num[0, i]) > eps:\n",
" for i in range(delta_num.shape[0]):\n",
" if np.abs(delta_num[i]) > eps:\n",
" print('{}: {:.2f} --> {:.2f}'.format(feature_names[i+n_keys],\n",
" X_orig_ord[0,i+n_keys],\n",
" X_cf_ord[0,i+n_keys]))"
Expand Down

0 comments on commit b252075

Please sign in to comment.