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

Adding sklearn 0.24 support #1016

Merged
merged 61 commits into from
Feb 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
b45f6f2
Adding importable helper functions
Neeratyoy Oct 29, 2020
8e7ea0b
Changing import of cat, cont
Neeratyoy Oct 29, 2020
102a084
Merge branch 'develop' into fix_773
Neeratyoy Oct 29, 2020
18a2dba
Better docstrings
Neeratyoy Oct 30, 2020
381c267
Adding unit test to check ColumnTransformer
Neeratyoy Oct 30, 2020
5dbff2e
Refinements from @mfeurer
Neeratyoy Nov 2, 2020
fc4ec73
Editing example to support both NumPy and Pandas
Neeratyoy Nov 2, 2020
8d5cad9
Merge branch 'develop' into fix_773
Neeratyoy Nov 3, 2020
3d66404
Merge branch 'develop' into fix_773
Neeratyoy Nov 4, 2020
90c8de6
Unit test fix to mark for deletion
Neeratyoy Nov 4, 2020
e0af15e
Making some unit tests work
Neeratyoy Nov 10, 2020
14aa11d
Waiting for dataset to be processed
Neeratyoy Nov 16, 2020
31d48d8
Minor test collection fix
Neeratyoy Nov 16, 2020
431447c
Template to handle missing tasks
Neeratyoy Nov 30, 2020
cc3199e
Accounting for more missing tasks:
Neeratyoy Nov 30, 2020
8a29668
Fixing some more unit tests
Neeratyoy Nov 30, 2020
405e03c
Simplifying check_task_existence
Neeratyoy Nov 30, 2020
caf4f46
black changes
Neeratyoy Dec 4, 2020
b308e71
Minor formatting
Neeratyoy Dec 8, 2020
436a9fe
Handling task exists check
Neeratyoy Dec 9, 2020
ddd8b04
Testing edited check task func
Neeratyoy Dec 14, 2020
74ae622
Merge branch 'fix_unit_tests' of https://github.com/openml/openml-pyt…
Neeratyoy Dec 14, 2020
50ce90e
Flake fix
Neeratyoy Dec 15, 2020
aea2832
Updating with fixed unit tests from PR #1000
Neeratyoy Dec 15, 2020
56cd639
More retries on connection error
Neeratyoy Dec 16, 2020
8e8ea2e
Adding max_retries to config default
Neeratyoy Dec 17, 2020
d518beb
Update database retry unit test
Neeratyoy Dec 17, 2020
37d9f6b
Print to debug hash exception
Neeratyoy Dec 17, 2020
9bd4892
Fixing checksum unit test
Neeratyoy Dec 17, 2020
dc41b5d
Retry on _download_text_file
Neeratyoy Dec 18, 2020
396cb8d
Update datasets_tutorial.py
mfeurer Dec 21, 2020
8f380de
Update custom_flow_tutorial.py
mfeurer Dec 21, 2020
bc1745e
Update test_study_functions.py
mfeurer Dec 21, 2020
d95b5e6
Update test_dataset_functions.py
mfeurer Dec 21, 2020
d58ca5a
Merge branch 'fix_unit_tests' into fix_773
Neeratyoy Dec 21, 2020
91c6cf5
more retries, but also more time between retries
mfeurer Dec 21, 2020
b43a0e0
Merge branch 'fix_unit_tests' of https://github.com/openml/openml-pyt…
Neeratyoy Dec 21, 2020
a9430b3
allow for even more retries on get calls
mfeurer Dec 21, 2020
e9cfba8
Catching failed get task
Neeratyoy Dec 21, 2020
c13f6ce
Merge branch 'fix_unit_tests' of https://github.com/openml/openml-pyt…
Neeratyoy Dec 21, 2020
3d7abc2
undo stupid change
mfeurer Dec 21, 2020
94576b1
Merge branch 'fix_unit_tests' of https://github.com/openml/openml-pyt…
Neeratyoy Dec 21, 2020
b5e1242
fix one more test
mfeurer Dec 21, 2020
d764aad
Merge branch 'fix_unit_tests' into fix_773
Neeratyoy Dec 21, 2020
f5e4a3e
Refactoring md5 hash check inside _send_request
Neeratyoy Dec 21, 2020
c065dfc
Merge branch 'fix_unit_tests' into fix_773
Neeratyoy Dec 21, 2020
07ce722
Fixing a fairly common unit test fail
Neeratyoy Dec 22, 2020
82e1b72
Reverting loose check on unit test
Neeratyoy Dec 23, 2020
936c252
Merge branch 'fix_unit_tests' into fix_773
Neeratyoy Dec 23, 2020
fc8b464
Merge branch 'develop' into fix_773
PGijsbers Dec 24, 2020
7ef965b
Updating examples to run on sklearn 0.24
Jan 8, 2021
8f693e4
Spawning tests for sklearn 0.24
Jan 8, 2021
9198489
Adding numpy import
Jan 8, 2021
46ab043
Fixing integer type check to allow np.integer
Neeratyoy Jan 22, 2021
c892b6b
Making unit tests run on sklearn 0.24
Neeratyoy Jan 22, 2021
ac173aa
black fix
Neeratyoy Jan 25, 2021
1be82c3
Trying to loosen check on unit test as fix
Neeratyoy Jan 25, 2021
902cd3f
Updating with PR #982
Neeratyoy Jan 26, 2021
0e44a0b
Merge branch 'develop' into sklearn24-support
Neeratyoy Jan 28, 2021
2fd4849
simplify examples
mfeurer Jan 28, 2021
0ae7075
disable test for old python version
mfeurer Jan 28, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/ubuntu-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
scikit-learn: [0.21.2, 0.22.2, 0.23.1]
scikit-learn: [0.21.2, 0.22.2, 0.23.1, 0.24]
exclude: # no scikit-learn 0.21.2 release for Python 3.8
- python-version: 3.8
scikit-learn: 0.21.2
Expand Down
48 changes: 20 additions & 28 deletions examples/30_extended/flows_and_runs_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# License: BSD 3-Clause

import openml
import numpy as np
from sklearn import compose, ensemble, impute, neighbors, preprocessing, pipeline, tree

############################################################################
Expand Down Expand Up @@ -54,7 +53,7 @@
task = openml.tasks.get_task(403)

# Build any classifier or pipeline
clf = tree.ExtraTreeClassifier()
clf = tree.DecisionTreeClassifier()

# Run the flow
run = openml.runs.run_model_on_task(clf, task)
Expand Down Expand Up @@ -83,7 +82,10 @@
# ############################
#
# When you need to handle 'dirty' data, build pipelines to model then automatically.
task = openml.tasks.get_task(1)
# To demonstrate this using the dataset `credit-a <https://test.openml.org/d/16>`_ via
# `task <https://test.openml.org/t/96>`_ as it contains both numerical and categorical
# variables and missing values in both.
task = openml.tasks.get_task(96)

# OpenML helper functions for sklearn can be plugged in directly for complicated pipelines
from openml.extensions.sklearn import cat, cont
Expand All @@ -96,20 +98,14 @@
[
(
"categorical",
pipeline.Pipeline(
[
("Imputer", impute.SimpleImputer(strategy="most_frequent")),
(
"Encoder",
preprocessing.OneHotEncoder(
sparse=False, handle_unknown="ignore"
),
),
]
),
preprocessing.OneHotEncoder(sparse=False, handle_unknown="ignore"),
cat, # returns the categorical feature indices
),
("continuous", "passthrough", cont), # returns the numeric feature indices
(
"continuous",
impute.SimpleImputer(strategy="median"),
cont,
), # returns the numeric feature indices
]
),
),
Expand Down Expand Up @@ -146,20 +142,14 @@
[
(
"categorical",
pipeline.Pipeline(
[
("Imputer", impute.SimpleImputer(strategy="most_frequent")),
(
"Encoder",
preprocessing.OneHotEncoder(
sparse=False, handle_unknown="ignore"
),
),
]
),
preprocessing.OneHotEncoder(sparse=False, handle_unknown="ignore"),
categorical_feature_indices,
),
("continuous", "passthrough", numeric_feature_indices),
(
"continuous",
impute.SimpleImputer(strategy="median"),
numeric_feature_indices,
),
]
),
),
Expand All @@ -182,7 +172,9 @@
task = openml.tasks.get_task(6)

# The following lines can then be executed offline:
run = openml.runs.run_model_on_task(pipe, task, avoid_duplicate_runs=False, upload_flow=False)
run = openml.runs.run_model_on_task(
pipe, task, avoid_duplicate_runs=False, upload_flow=False, dataset_format="array",
)

# The run may be stored offline, and the flow will be stored along with it:
run.to_filesystem(directory="myrun")
Expand Down
9 changes: 3 additions & 6 deletions examples/30_extended/run_setup_tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,9 @@
# easy as you want it to be


cat_imp = make_pipeline(
SimpleImputer(strategy="most_frequent"),
OneHotEncoder(handle_unknown="ignore", sparse=False),
TruncatedSVD(),
)
ct = ColumnTransformer([("cat", cat_imp, cat), ("cont", "passthrough", cont)])
cat_imp = make_pipeline(OneHotEncoder(handle_unknown="ignore", sparse=False), TruncatedSVD(),)
cont_imp = SimpleImputer(strategy="median")
ct = ColumnTransformer([("cat", cat_imp, cat), ("cont", cont_imp, cont)])
model_original = Pipeline(steps=[("transform", ct), ("estimator", RandomForestClassifier()),])

# Let's change some hyperparameters. Of course, in any good application we
Expand Down
10 changes: 3 additions & 7 deletions examples/40_paper/2018_neurips_perrone_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,14 @@ def list_categorical_attributes(flow_type="svm"):
cat_cols = list_categorical_attributes(flow_type=flow_type)
num_cols = list(set(X.columns) - set(cat_cols))

# Missing value imputers
cat_imputer = SimpleImputer(missing_values=np.nan, strategy="constant", fill_value="None")
# Missing value imputers for numeric columns
num_imputer = SimpleImputer(missing_values=np.nan, strategy="constant", fill_value=-1)

# Creating the one-hot encoder
# Creating the one-hot encoder for numerical representation of categorical columns
enc = OneHotEncoder(handle_unknown="ignore")

# Pipeline to handle categorical column transformations
cat_transforms = Pipeline(steps=[("impute", cat_imputer), ("encode", enc)])

# Combining column transformers
ct = ColumnTransformer([("cat", cat_transforms, cat_cols), ("num", num_imputer, num_cols)])
ct = ColumnTransformer([("cat", enc, cat_cols), ("num", num_imputer, num_cols)])

# Creating the full pipeline with the surrogate model
clf = RandomForestRegressor(n_estimators=50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ def test_serialize_model(self):
if LooseVersion(sklearn.__version__) >= "0.22":
fixture_parameters.update({"ccp_alpha": "0.0"})
fixture_parameters.move_to_end("ccp_alpha", last=False)
if LooseVersion(sklearn.__version__) >= "0.24":
del fixture_parameters["presort"]

structure_fixture = {"sklearn.tree.{}.DecisionTreeClassifier".format(tree_name): []}

Expand Down Expand Up @@ -1317,12 +1319,18 @@ def test__get_fn_arguments_with_defaults(self):
(sklearn.tree.DecisionTreeClassifier.__init__, 14),
(sklearn.pipeline.Pipeline.__init__, 2),
]
else:
elif sklearn_version < "0.24":
fns = [
(sklearn.ensemble.RandomForestRegressor.__init__, 18),
(sklearn.tree.DecisionTreeClassifier.__init__, 14),
(sklearn.pipeline.Pipeline.__init__, 2),
]
else:
fns = [
(sklearn.ensemble.RandomForestRegressor.__init__, 18),
(sklearn.tree.DecisionTreeClassifier.__init__, 13),
(sklearn.pipeline.Pipeline.__init__, 2),
]

for fn, num_params_with_defaults in fns:
defaults, defaultless = self.extension._get_fn_arguments_with_defaults(fn)
Expand Down Expand Up @@ -1523,7 +1531,7 @@ def test_obtain_parameter_values(self):
"bootstrap": [True, False],
"criterion": ["gini", "entropy"],
},
cv=sklearn.model_selection.StratifiedKFold(n_splits=2, random_state=1),
cv=sklearn.model_selection.StratifiedKFold(n_splits=2, random_state=1, shuffle=True),
n_iter=5,
)
flow = self.extension.model_to_flow(model)
Expand Down
12 changes: 10 additions & 2 deletions tests/test_flows/test_flow_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,16 @@ def test_get_flow_reinstantiate_model_wrong_version(self):
# Note that CI does not test against 0.19.1.
openml.config.server = self.production_server
_, sklearn_major, _ = LooseVersion(sklearn.__version__).version[:3]
flow = 8175
expected = "Trying to deserialize a model with dependency" " sklearn==0.19.1 not satisfied."
if sklearn_major > 23:
flow = 18587 # 18687, 18725 --- flows building random forest on >= 0.23
flow_sklearn_version = "0.23.1"
else:
flow = 8175
flow_sklearn_version = "0.19.1"
expected = (
"Trying to deserialize a model with dependency "
"sklearn=={} not satisfied.".format(flow_sklearn_version)
)
self.assertRaisesRegex(
ValueError, expected, openml.flows.get_flow, flow_id=flow, reinstantiate=True
)
Expand Down
13 changes: 6 additions & 7 deletions tests/test_study/test_study_examples.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# License: BSD 3-Clause

from openml.testing import TestBase, SimpleImputer, CustomImputer
from openml.testing import TestBase
from openml.extensions.sklearn import cat, cont

import sklearn
Expand All @@ -13,8 +13,8 @@ class TestStudyFunctions(TestBase):
"""Test the example code of Bischl et al. (2018)"""

@unittest.skipIf(
LooseVersion(sklearn.__version__) < "0.20",
reason="columntransformer introduction in 0.20.0",
LooseVersion(sklearn.__version__) < "0.24",
reason="columntransformer introduction in 0.24.0",
)
def test_Figure1a(self):
"""Test listing in Figure 1a on a single task and the old OpenML100 study.
Expand All @@ -39,15 +39,14 @@ def test_Figure1a(self):
import openml
import sklearn.metrics
import sklearn.tree
from sklearn.impute import SimpleImputer
from sklearn.pipeline import Pipeline, make_pipeline
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import OneHotEncoder, StandardScaler

benchmark_suite = openml.study.get_study("OpenML100", "tasks") # obtain the benchmark suite
cat_imp = make_pipeline(
SimpleImputer(strategy="most_frequent"), OneHotEncoder(handle_unknown="ignore")
)
cont_imp = make_pipeline(CustomImputer(), StandardScaler())
cat_imp = OneHotEncoder(handle_unknown="ignore")
cont_imp = make_pipeline(SimpleImputer(strategy="median"), StandardScaler())
ct = ColumnTransformer([("cat", cat_imp, cat), ("cont", cont_imp, cont)])
clf = Pipeline(
steps=[("preprocess", ct), ("estimator", sklearn.tree.DecisionTreeClassifier())]
Expand Down