From 59db7f02f76c5481a2f7d02289c6afc834d847e8 Mon Sep 17 00:00:00 2001
From: Fabian Pedregosa <fabian.pedregosa@inria.fr>
Date: Fri, 25 Jun 2010 17:59:01 -0500
Subject: [PATCH] Initialize with a fixed seed tests in feature_select

---
 .../tests/test_feature_select.py              | 29 ++++++++++---------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/scikits/learn/feature_selection/tests/test_feature_select.py b/scikits/learn/feature_selection/tests/test_feature_select.py
index 53177ad38e..6341785462 100644
--- a/scikits/learn/feature_selection/tests/test_feature_select.py
+++ b/scikits/learn/feature_selection/tests/test_feature_select.py
@@ -9,6 +9,7 @@ from numpy.testing import assert_array_equal, \
                           assert_raises
 import scikits.learn.datasets.samples_generator as sg
 
+seed = np.random.RandomState(0)
 
 def test_F_test_classif():
     """
@@ -16,7 +17,7 @@ def test_F_test_classif():
     on a simple simulated classification problem
     """
     X, Y = sg.test_dataset_classif(n_samples=50, n_features=20, k=5,
-                                           seed=None)
+                                           seed=seed)
     F, pv = us.f_classif(X, Y)
     assert(F>0).all()
     assert(pv>0).all()
@@ -29,8 +30,9 @@ def test_F_test_reg():
     Test whether the F test yields meaningful results
     on a simple simulated regression problem
     """
+    np.random.seed(0)
     X, Y = sg.test_dataset_classif(n_samples=50, n_features=20, k=5,
-                                           seed=None)
+                                           seed=seed)
     F, pv = us.f_regression(X, Y)
     assert(F>0).all()
     assert(pv>0).all()
@@ -44,13 +46,13 @@ def test_F_test_multi_class():
     on a simple simulated classification problem
     """
     X, Y = sg.test_dataset_classif(n_samples=50, n_features=20, k=5,
-                                           seed=None,param=[1,1,1])
+                                           seed=seed,param=[1,1,1])
     F, pv = us.f_classif(X, Y)
     assert(F>0).all()
     assert(pv>0).all()
     assert(pv<1).all()
     assert(pv[:5]<0.05).all()
-    assert(pv[5:]>1.e-4).all()
+    assert(pv[5:]>1.e-5).all()
 
 def test_univ_fs_percentile_classif():
     """
@@ -58,8 +60,9 @@ def test_univ_fs_percentile_classif():
     gets the correct items in a simple classification problem
     with the percentile heuristic
     """
+    np.random.seed(0)
     X, Y = sg.test_dataset_classif(n_samples=50, n_features=20, k=5,
-                                           seed=None)
+                                           seed=seed)
     univariate_filter = us.SelectPercentile(us.f_classif)
     X_r = univariate_filter.fit(X, Y).transform(X, percentile=25)
     support = univariate_filter.support(percentile=25)
@@ -74,7 +77,7 @@ def test_univ_fs_kbest_classif():
     with the k best heuristic
     """
     X, Y = sg.test_dataset_classif(n_samples=50, n_features=20, k=5,
-                                           seed=None)
+                                           seed=seed)
     univariate_filter = us.SelectKBest(us.f_classif)
     X_r = univariate_filter.fit(X, Y).transform(X, k=5)
     support = univariate_filter.support(k=5)
@@ -89,7 +92,7 @@ def test_univ_fs_fpr_classif():
     with the fpr heuristic
     """
     X, Y = sg.test_dataset_classif(n_samples=50, n_features=20, k=5,
-                                           seed=None)
+                                           seed=seed)
     univariate_filter = us.SelectFpr(us.f_classif)
     X_r = univariate_filter.fit(X, Y).transform(X, alpha=0.0001)
     support = univariate_filter.support(alpha=0.0001)
@@ -119,7 +122,7 @@ def test_univ_fs_fwe_classif():
     with the fpr heuristic
     """
     X, Y = sg.test_dataset_classif(n_samples=50, n_features=20, k=5,
-                                           seed=None)
+                                           seed=seed)
     univariate_filter = us.SelectFwe(us.f_classif)
     X_r = univariate_filter.fit(X, Y).transform(X, alpha=0.01)
     support = univariate_filter.support(alpha=0.01)
@@ -140,7 +143,7 @@ def test_univ_fs_percentile_regression():
     with the percentile heuristic
     """
     X, Y = sg.test_dataset_reg(n_samples=50, n_features=20, k=5,
-                                           seed=None)
+                                           seed=seed)
     univariate_filter = us.SelectPercentile(us.f_regression)
     X_r = univariate_filter.fit(X, Y).transform(X, percentile=25)
     support = univariate_filter.support(percentile=25)
@@ -154,7 +157,7 @@ def test_univ_fs_full_percentile_regression():
     selects all features when '100%' is asked.
     """
     X, Y = sg.test_dataset_reg(n_samples=50, n_features=20, k=5,
-                                           seed=None)
+                                           seed=seed)
     univariate_filter = us.SelectPercentile(us.f_regression)
     X_r = univariate_filter.fit(X, Y).transform(X, percentile=100)
     support = univariate_filter.support(percentile=100)
@@ -168,7 +171,7 @@ def test_univ_fs_kbest_regression():
     with the k best heuristic
     """
     X, Y = sg.test_dataset_reg(n_samples=50, n_features=20, k=5,
-                                           seed=None)
+                                           seed=seed)
     univariate_filter = us.SelectKBest(us.f_regression)
     X_r = univariate_filter.fit(X, Y).transform(X, k=5)
     support = univariate_filter.support(k=5)
@@ -183,7 +186,7 @@ def test_univ_fs_fpr_regression():
     with the fpr heuristic
     """
     X, Y = sg.test_dataset_reg(n_samples=50, n_features=20, k=5,
-                                           seed=None)
+                                           seed=seed)
     univariate_filter = us.SelectFpr(us.f_regression)
     X_r = univariate_filter.fit(X, Y).transform(X, alpha=0.01)
     support = univariate_filter.support(alpha=0.01)
@@ -214,7 +217,7 @@ def test_univ_fs_fwe_regression():
     with the fpr heuristic
     """
     X, Y = sg.test_dataset_reg(n_samples=50, n_features=20, k=5,
-                                           seed=None)
+                                           seed=seed)
     univariate_filter = us.SelectFwe(us.f_regression)
     X_r = univariate_filter.fit(X, Y).transform(X, alpha=0.01)
     support = univariate_filter.support(alpha=0.01)
-- 
GitLab