Skip to content

Commit

Permalink
fix builds due to OneHotEncoder sparse parameter breaking change in s…
Browse files Browse the repository at this point in the history
…cikit-learn (#2539)
  • Loading branch information
imatiach-msft committed Feb 15, 2024
1 parent c647df1 commit a0e804b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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

0 comments on commit a0e804b

Please sign in to comment.