8000 [MRG] TST add test for pipeline in partial dependence by glemaitre · Pull Request #14079 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

[MRG] TST add test for pipeline in partial dependence #14079

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

Merged
merged 1 commit into from
Jun 13, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to < 8000 div class="select-menu-header"> Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions sklearn/inspection/tests/test_partial_dependence.py
< 8000 td class="blob-code blob-code-inner blob-code-hunk">@@ -22,7 +22,9 @@
Original file line number Diff line number Diff line change
Expand Up
from sklearn.datasets import make_classification, make_regression
from sklearn.cluster import KMeans
from sklearn.metrics import r2_score
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import PolynomialFeatures
from sklearn.preprocessing import StandardScaler
from sklearn.dummy import DummyClassifier
from sklearn.base import BaseEstimator, ClassifierMixin
from sklearn.utils.testing import assert_allclose
Expand Down Expand Up @@ -393,6 +395,31 @@ def test_partial_dependence_sample_weight():
assert np.corrcoef(pdp, values)[0, 1] > 0.99


def test_partial_dependence_pipeline():
# check that the partial dependence support pipeline
iris = load_iris()

scaler = StandardScaler()
clf = DummyClassifier(random_state=42)
pipe = make_pipeline(scaler, clf)

clf.fit(scaler.fit_transform(iris.data), iris.target)
pipe.fit(iris.data, iris.target)

features = 0
pdp_pipe, values_pipe = partial_dependence(
pipe, iris.data, features=[features]
)
pdp_clf, values_clf = partial_dependence(
clf, scaler.transform(iris.data), features=[features]
)
assert_allclose(pdp_pipe, pdp_clf)
assert_allclose(
values_pipe[0],
values_clf[0] * scaler.scale_[features] + scaler.mean_[features]
)


def test_plot_partial_dependence(pyplot):
# Test partial dependence plot function.
boston = load_boston()
Expand Down
0