diff --git a/doc/source/examples/cfproto_cat_adult_ohe.ipynb b/doc/source/examples/cfproto_cat_adult_ohe.ipynb index 0e00a1894..145c1bd9a 100644 --- a/doc/source/examples/cfproto_cat_adult_ohe.ipynb +++ b/doc/source/examples/cfproto_cat_adult_ohe.ipynb @@ -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]" ] }, { @@ -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)" ] }, @@ -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)" ] @@ -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]))"