@@ -74,6 +74,20 @@ def predict(self, X):
74
74
return self .successful
75
75
76
76
77
+
78
+ class FitTransformSample (T ):
79
+ """Mock classifier
80
+ """
81
+
82
+ def fit (self , X , y , should_succeed = False ):
83
+ pass
84
+
85
+ def sample (X , y = None ):
86
+ return X , y
87
+
88
+ def transform (X , y = None ):
89
+ return X
90
+
77
91
def test_pipeline_init ():
78
92
# Test the various init parameters of the pipeline.
79
93
assert_raises (TypeError , Pipeline )
@@ -431,3 +445,32 @@ def test_pipeline_methods_anova_rus():
431
445
pipe .predict_proba (X )
432
446
pipe .predict_log_proba (X )
433
447
pipe .score (X , y )
448
+
449
+
450
+
451
+
452
+ def test_pipeline_with_step_that_implements_both_sample_and_transform ():
453
+ # Test the various methods of the pipeline (anova).
454
+ X , y = make_classification (n_classes = 2 , class_sep = 2 , weights = [0.1 , 0.9 ],
455
+ n_informative = 3 , n_redundant = 1 , flip_y = 0 ,
456
+ n_features = 20 , n_clusters_per_class = 1 ,
457
+ n_samples = 5000 , random_state = 0 )
458
+
459
+ clf = LogisticRegression ()
460
+ assert_raises (TypeError , Pipeline , [('step' , FitTransformSample ()), ('logistic' , clf )])
461
+ #assert_raises(TypeError, lambda x: [][0])
462
+
463
+
464
+ def test_pipeline_with_step_that_it_is_pipeline ():
465
+ # Test the various methods of the pipeline (anova).
466
+ X , y = make_classification (n_classes = 2 , class_sep = 2 , weights = [0.1 , 0.9 ],
467
+ n_informative = 3 , n_redundant = 1 , flip_y = 0 ,
468
+ n_features = 20 , n_clusters_per_class = 1 ,
469
+ n_samples = 5000 , random_state = 0 )
470
+ # Test with RandomUnderSampling + Anova + LogisticRegression
471
+ clf = LogisticRegression ()
472
+ rus = RandomUnderSampler (random_state = 0 )
473
+ filter1 = SelectKBest (f_classif , k = 2 )
474
+ pipe1 = Pipeline ([('rus' , rus ), ('anova' , filter1 )])
475
+ assert_raises (TypeError , Pipeline , [('pipe1' , pipe1 ), ('logistic' , clf )])
476
+
0 commit comments