From e30876537869ee603aade9b2c265f3add0f2894b Mon Sep 17 00:00:00 2001 From: Alexandre Gramfort <alexandre.gramfort@inria.fr> Date: Tue, 16 Nov 2010 19:38:40 +0100 Subject: [PATCH] ENH : adding test in pipeline + increase coverage --- scikits/learn/tests/test_pipeline.py | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/scikits/learn/tests/test_pipeline.py b/scikits/learn/tests/test_pipeline.py index edec37420c..f846a58567 100644 --- a/scikits/learn/tests/test_pipeline.py +++ b/scikits/learn/tests/test_pipeline.py @@ -4,22 +4,31 @@ Test the pipeline module. from nose.tools import assert_raises, assert_equal, assert_false +import numpy as np + from ..base import BaseEstimator, clone from ..pipeline import Pipeline from ..svm import SVC +from ..glm import LogisticRegression from ..feature_selection import SelectKBest, f_classif +from ..datasets import load_iris + class IncorrectT(BaseEstimator): """Small class to test parameter dispatching. """ + def __init__(self, a=None, b=None): self.a = a self.b = b + class T(IncorrectT): + def fit(self, X, y): return self + def test_pipeline_init(): """ Test the various init parameters of the pipeline. """ @@ -67,3 +76,24 @@ def test_pipeline_init(): params2.pop('svc') params2.pop('anova') assert_equal(params, params2) + + +def test_pipeline_methods(): + """ Test the various methods of the pipeline. + """ + iris = load_iris() + X = iris.data + y = iris.target + # Test with Anova+SVC + clf = LogisticRegression() + filter1 = SelectKBest(f_classif, k=2) + pipe = Pipeline([('anova', filter1), ('svc', clf)]) + pipe.fit(X, y) + pipe.predict(X) + pipe.predict_proba(X) + pipe.predict_log_proba(X) + pipe.score(X, y) + support_ = pipe.get_support() + assert np.sum(support_) == 2 + coef_ = pipe.coef_ + assert np.size(coef_) == 4 -- GitLab