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 builds due to OneHotEncoder sparse parameter breaking change in scikit-learn #2539

Merged
merged 1 commit into from
Feb 15, 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
4 changes: 4 additions & 0 deletions .github/workflows/CD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ jobs:
pip install -r requirements.txt
pip install -r requirements-dev.txt
working-directory: ${{ env.widgetDirectory }}
- name: Install rai_test_utils locally until next version is released
run: |
pip install -v -e .
working-directory: rai_test_utils
- name: pip freeze
run: pip freeze
- name: replace README for raiwidgets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
"outputs": [],
"source": [
"from raiutils.dataset import fetch_dataset\n",
"import sklearn\n",
"from packaging import version\n",
"from sklearn.pipeline import Pipeline\n",
"from sklearn.impute import SimpleImputer\n",
"from sklearn.preprocessing import StandardScaler, OneHotEncoder\n",
Expand All @@ -98,6 +100,12 @@
" y = dataset[[target_feature]]\n",
" return X, y\n",
"\n",
"# for older scikit-learn versions use sparse, for newer sparse_output:\n",
"if version.parse(sklearn.__version__) < version.parse('1.2'):\n",
" ohe_params = {\"sparse\": False}\n",
"else:\n",
" ohe_params = {\"sparse_output\": False}\n",
"\n",
"def create_classification_pipeline(X):\n",
" pipe_cfg = {\n",
" 'num_cols': X.dtypes[X.dtypes == 'int64'].index.values.tolist(),\n",
Expand All @@ -109,7 +117,7 @@
" ])\n",
" cat_pipe = Pipeline([\n",
" ('cat_imputer', SimpleImputer(strategy='constant', fill_value='?')),\n",
" ('cat_encoder', OneHotEncoder(handle_unknown='ignore', sparse=False))\n",
" ('cat_encoder', OneHotEncoder(handle_unknown='ignore', **ohe_params))\n",
" ])\n",
" feat_pipe = ColumnTransformer([\n",
" ('num_pipe', num_pipe, pipe_cfg['num_cols']),\n",
Expand Down
Loading