Skip to content

Commit 347c4a6

Browse files
hinchliffmfeurer
authored andcommitted
Update examples to remove deprecation warnings from scikit-learn (#729)
* WIP for #726 * changing imputer to remove warnings * cleanup * updating changelog
1 parent 72499a1 commit 347c4a6

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

doc/progress.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Changelog
1616
* ADD #687: Adds a function to retrieve the list of evaluation measures available.
1717
* ADD #695: A function to retrieve all the data quality measures available.
1818
* FIX #447: All files created by unit tests are deleted after the completion of all unit tests.
19+
* MAINT #726: Update examples to remove deprecation warnings from scikit-learn
1920

2021
0.9.0
2122
~~~~~

examples/flows_and_runs_tutorial.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import openml
99
from pprint import pprint
10-
from sklearn import ensemble, neighbors, preprocessing, pipeline, tree
10+
from sklearn import compose, ensemble, impute, neighbors, preprocessing, pipeline, tree
1111

1212
############################################################################
1313
# Train machine learning models
@@ -39,8 +39,9 @@
3939
target=dataset.default_target_attribute
4040
)
4141
print("Categorical features: {}".format(categorical_indicator))
42-
enc = preprocessing.OneHotEncoder(categorical_features=categorical_indicator)
43-
X = enc.fit_transform(X)
42+
transformer = compose.ColumnTransformer(
43+
[('one_hot_encoder', preprocessing.OneHotEncoder(categories='auto'), categorical_indicator)])
44+
X = transformer.fit_transform(X)
4445
clf.fit(X, y)
4546

4647
############################################################################
@@ -83,9 +84,9 @@
8384
# When you need to handle 'dirty' data, build pipelines to model then automatically.
8485
task = openml.tasks.get_task(115)
8586
pipe = pipeline.Pipeline(steps=[
86-
('Imputer', preprocessing.Imputer(strategy='median')),
87+
('Imputer', impute.SimpleImputer(strategy='median')),
8788
('OneHotEncoder', preprocessing.OneHotEncoder(sparse=False, handle_unknown='ignore')),
88-
('Classifier', ensemble.RandomForestClassifier())
89+
('Classifier', ensemble.RandomForestClassifier(n_estimators=10))
8990
])
9091

9192
run = openml.runs.run_model_on_task(pipe, task, avoid_duplicate_runs=False)

examples/sklearn/openml_run_example.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
An example of an automated machine learning experiment.
66
"""
77
import openml
8-
from sklearn import tree, preprocessing, pipeline
8+
from sklearn import impute, tree, pipeline
99

1010
############################################################################
1111
# .. warning:: This example uploads data. For that reason, this example
@@ -21,7 +21,7 @@
2121
# Define a scikit-learn pipeline
2222
clf = pipeline.Pipeline(
2323
steps=[
24-
('imputer', preprocessing.Imputer()),
24+
('imputer', impute.SimpleImputer()),
2525
('estimator', tree.DecisionTreeClassifier())
2626
]
2727
)

0 commit comments

Comments
 (0)