diff --git a/README.rst b/README.rst index 829cb7ad82298..67ffa8d9fc562 100644 --- a/README.rst +++ b/README.rst @@ -25,9 +25,10 @@ Dependencies ============ The required dependencies to build the software are python >= 2.5, -NumPy >= 1.1, SciPy and a working C++ compiler. +NumPy >= 1.1, SciPy >= 0.6 (although having at least 0.7 is highly +recommended and required by some modules) and a working C++ compiler. -To run the tests you will also need nosetests. +To run the tests you will also need nose >= 0.10. Install diff --git a/scikits/learn/cluster/tests/test_spectral.py b/scikits/learn/cluster/tests/test_spectral.py index 19765ec2fbce2..1c73c8410d081 100644 --- a/scikits/learn/cluster/tests/test_spectral.py +++ b/scikits/learn/cluster/tests/test_spectral.py @@ -4,7 +4,7 @@ """ import numpy as np -from numpy.testing import assert_equal, assert_ +from numpy.testing import assert_equal from scipy import sparse from .. import SpectralClustering @@ -49,5 +49,5 @@ def test_spectral_clustering_sparse(): if labels[0] == 0: labels = 1 - labels - assert_(np.mean(labels == [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) > .9) + assert np.mean(labels == [1, 1, 1, 1, 1, 0, 0, 0, 0, 0]) > .9 diff --git a/scikits/learn/features/image.py b/scikits/learn/features/image.py index 863812d9f0246..ebada423dc858 100644 --- a/scikits/learn/features/image.py +++ b/scikits/learn/features/image.py @@ -92,7 +92,7 @@ def img_to_graph(img, mask=None, graph = sparse.coo_matrix((np.hstack((weights, weights, img)), (np.hstack((i_idx, diag_idx)), np.hstack((j_idx, diag_idx)))), - shape=(n_voxels, n_voxels)) + (n_voxels, n_voxels)) if return_as is np.ndarray: return graph.todense() return return_as(graph) diff --git a/scikits/learn/features/tests/test_text.py b/scikits/learn/features/tests/test_text.py index 81e22838d757d..f70dcf7326a6d 100644 --- a/scikits/learn/features/tests/test_text.py +++ b/scikits/learn/features/tests/test_text.py @@ -130,6 +130,7 @@ def test_sparse_tf_idf(): def test_dense_sparse_idf_sanity(): + hv = HashingVectorizer(dim=100, probes=3) shv = SparseHashingVectorizer(dim=100, probes=3) diff --git a/scikits/learn/features/text.py b/scikits/learn/features/text.py index faad7967b783e..d354509be2b4d 100644 --- a/scikits/learn/features/text.py +++ b/scikits/learn/features/text.py @@ -391,6 +391,8 @@ class SparseHashingVectorizer(object): The logic is the same as HashingVectorizer but it is possible to use much larger dimension vectors without memory issues thanks to the usage of scipy.sparse datastructure to store the tf vectors. + + This function requires scipy 0.7 or higher. """ def __init__(self, dim=100000, probes=1, use_idf=True, diff --git a/scikits/learn/glm/sparse/tests/test_coordinate_descent.py b/scikits/learn/glm/sparse/tests/test_coordinate_descent.py index cb6b5d071670e..390c88c27e561 100644 --- a/scikits/learn/glm/sparse/tests/test_coordinate_descent.py +++ b/scikits/learn/glm/sparse/tests/test_coordinate_descent.py @@ -3,7 +3,6 @@ from numpy.testing import assert_array_almost_equal from numpy.testing import assert_almost_equal from numpy.testing import assert_equal -from numpy.testing import assert_ from scikits.learn.glm.sparse.coordinate_descent import Lasso as SparseLasso from scikits.learn.glm.sparse.coordinate_descent import ElasticNet as SparseENet @@ -27,8 +26,9 @@ def test_lasso_zero(): """Check that the sparse lasso can handle zero data without crashing""" X = sparse.csc_matrix((3, 1)) y = [0, 0, 0] + T = np.array([[1], [2], [3]]) clf = SparseLasso().fit(X, y) - pred = clf.predict([[1], [2], [3]]) + pred = clf.predict(T) assert_array_almost_equal(clf.coef_, [0]) assert_array_almost_equal(pred, [0, 0, 0]) assert_almost_equal(clf.dual_gap_, 0) @@ -37,9 +37,9 @@ def test_lasso_zero(): def test_enet_toy_list_input(): """Test ElasticNet for various parameters of alpha and rho with list X""" - X = [[-1], [0], [1]] + X = np.array([[-1], [0], [1]]) Y = [-1, 0, 1] # just a straight line - T = [[2], [3], [4]] # test sample + T = np.array([[2], [3], [4]]) # test sample # this should be the same as unregularized least squares clf = SparseENet(alpha=0, rho=1.0) @@ -134,18 +134,18 @@ def test_sparse_enet_not_as_toy_dataset(): s_clf = SparseENet(alpha=0.1, rho=0.8, fit_intercept=False) s_clf.fit(X_train, y_train, maxit=maxit, tol=1e-7) assert_almost_equal(s_clf.dual_gap_, 0, 4) - assert_(s_clf.score(X_test, y_test) > 0.85) + assert s_clf.score(X_test, y_test) > 0.85 # check the convergence is the same as the dense version d_clf = DenseENet(alpha=0.1, rho=0.8, fit_intercept=False) d_clf.fit(X_train, y_train, maxit=maxit, tol=1e-7) assert_almost_equal(d_clf.dual_gap_, 0, 4) - assert_(d_clf.score(X_test, y_test) > 0.85) + assert d_clf.score(X_test, y_test) > 0.85 assert_almost_equal(s_clf.coef_, d_clf.coef_, 5) # check that the coefs are sparse - assert_(np.sum(s_clf.coef_ != 0.0) < 2 * n_informative) + assert np.sum(s_clf.coef_ != 0.0) < 2 * n_informative def test_sparse_lasso_not_as_toy_dataset(): @@ -160,13 +160,13 @@ def test_sparse_lasso_not_as_toy_dataset(): s_clf = SparseLasso(alpha=0.1, fit_intercept=False) s_clf.fit(X_train, y_train, maxit=maxit, tol=1e-7) assert_almost_equal(s_clf.dual_gap_, 0, 4) - assert_(s_clf.score(X_test, y_test) > 0.85) + assert s_clf.score(X_test, y_test) > 0.85 # check the convergence is the same as the dense version d_clf = DenseLasso(alpha=0.1, fit_intercept=False) d_clf.fit(X_train, y_train, maxit=maxit, tol=1e-7) assert_almost_equal(d_clf.dual_gap_, 0, 4) - assert_(d_clf.score(X_test, y_test) > 0.85) + assert d_clf.score(X_test, y_test) > 0.85 # check that the coefs are sparse assert_equal(np.sum(s_clf.coef_ != 0.0), n_informative) diff --git a/scikits/learn/glm/tests/test_bayes.py b/scikits/learn/glm/tests/test_bayes.py index 11a3e2c8394c8..11e602b1c5fb6 100644 --- a/scikits/learn/glm/tests/test_bayes.py +++ b/scikits/learn/glm/tests/test_bayes.py @@ -6,17 +6,19 @@ import numpy as np from numpy.testing import assert_array_equal, \ - assert_array_almost_equal, decorators + assert_array_almost_equal + +import nose from ..bayes import BayesianRidge, ARDRegression from scikits.learn import datasets -@decorators.skipif(True, "XFailed test") def test_bayesian_on_diabetes(): """ Test BayesianRidge on diabetes """ + raise nose.SkipTest("XFailed Test") diabetes = datasets.load_diabetes() X, y = diabetes.data, diabetes.target diff --git a/scikits/learn/glm/tests/test_coordinate_descent.py b/scikits/learn/glm/tests/test_coordinate_descent.py index b651972b88fb5..852c653cc5ac2 100644 --- a/scikits/learn/glm/tests/test_coordinate_descent.py +++ b/scikits/learn/glm/tests/test_coordinate_descent.py @@ -4,7 +4,7 @@ import numpy as np -from numpy.testing import assert_array_almost_equal, assert_almost_equal, assert_ +from numpy.testing import assert_array_almost_equal, assert_almost_equal from ..coordinate_descent import Lasso, LassoCV, ElasticNet, ElasticNetCV @@ -113,7 +113,7 @@ def test_lasso_path(): # test set X_test = np.random.randn(n_samples, n_features) y_test = np.dot(X_test, w) - assert_(clf.score(X_test, y_test) > 0.85) + assert clf.score(X_test, y_test) > 0.85 def test_enet_path(): @@ -133,5 +133,5 @@ def test_enet_path(): # test set X_test = np.random.randn(n_samples, n_features) y_test = np.dot(X_test, w) - assert_(clf.score(X_test, y_test) > 0.85) + assert clf.score(X_test, y_test) > 0.85 diff --git a/scikits/learn/svm/tests/test_sparse.py b/scikits/learn/svm/tests/test_sparse.py index 62f64b3d28a07..1c53847fab38f 100644 --- a/scikits/learn/svm/tests/test_sparse.py +++ b/scikits/learn/svm/tests/test_sparse.py @@ -2,19 +2,21 @@ import scipy.sparse from scikits.learn import datasets, svm from numpy.testing import assert_array_almost_equal, \ - assert_array_equal, assert_equal, assert_raises + assert_array_equal, assert_equal + +from nose.tools import assert_raises # test sample 1 -X = [[-2, -1], [-1, -1], [-1, -2], [1, 1], [1, 2], [2, 1]] +X = np.array([[-2, -1], [-1, -1], [-1, -2], [1, 1], [1, 2], [2, 1]]) Y = [1, 1, 1, 2, 2, 2] -T = [[-1, -1], [2, 2], [3, 2]] +T = np.array([[-1, -1], [2, 2], [3, 2]]) true_result = [1, 2, 2] # test sample 2 -X2 = [[0, 0, 0], [1, 1, 1], [2, 0, 0, ], - [0, 0, 2], [3, 3, 3]] +X2 = np.array([[0, 0, 0], [1, 1, 1], [2, 0, 0, ], + [0, 0, 2], [3, 3, 3]]) Y2 = [1, 2, 2, 2, 3] -T2 = [[-1, -1, -1], [1, 1, 1], [2, 2, 2]] +T2 = np.array([[-1, -1, -1], [1, 1, 1], [2, 2, 2]]) true_result2 = [1, 2, 3] diff --git a/scikits/learn/svm/tests/test_svm.py b/scikits/learn/svm/tests/test_svm.py index 72f64a7b3cb40..0232c0215d9e9 100644 --- a/scikits/learn/svm/tests/test_svm.py +++ b/scikits/learn/svm/tests/test_svm.py @@ -6,7 +6,8 @@ import numpy as np from numpy.testing import assert_array_equal, assert_array_almost_equal, \ - assert_almost_equal, assert_raises, assert_ + assert_almost_equal +from nose.tools import assert_raises from scikits.learn import svm, datasets @@ -262,5 +263,5 @@ def test_LinearSVC_iris(): Test that LinearSVC gives plausible predictions on the iris dataset """ clf = svm.LinearSVC().fit(iris.data, iris.target) - assert_ (np.mean(clf.predict(iris.data) == iris.target) > 0.95) + assert np.mean(clf.predict(iris.data) == iris.target) > 0.95 diff --git a/scikits/learn/tests/test_hmm.py b/scikits/learn/tests/test_hmm.py index a9180982af7c3..4b309ef2224d5 100644 --- a/scikits/learn/tests/test_hmm.py +++ b/scikits/learn/tests/test_hmm.py @@ -1,11 +1,12 @@ -from numpy.testing import (assert_array_equal, assert_array_almost_equal, - TestCase) -import numpy as np -from .. import hmm +import numpy as np +from numpy.testing import assert_array_equal, assert_array_almost_equal +from unittest import TestCase from .test_gmm import _generate_random_spd_matrix +from .. import hmm + SKIP_FAILING = True # skip failing tests diff --git a/scikits/learn/tests/test_logistic.py b/scikits/learn/tests/test_logistic.py index 7320494f56034..013ddb1cd8f06 100644 --- a/scikits/learn/tests/test_logistic.py +++ b/scikits/learn/tests/test_logistic.py @@ -1,6 +1,9 @@ import numpy as np -from numpy.testing import assert_array_equal, assert_raises, \ - assert_, assert_array_almost_equal, decorators + +from numpy.testing import assert_array_equal, \ + assert_array_almost_equal +import nose +from nose.tools import assert_raises from .. import logistic, datasets @@ -42,13 +45,13 @@ def test_predict_iris(): clf = logistic.LogisticRegression().fit(iris.data, iris.target) pred = clf.predict(iris.data) - assert_ ( np.mean(pred == iris.target) > .95 ) + assert np.mean(pred == iris.target) > .95 -@decorators.skipif(True, "XFailed test") def test_predict_proba(): """ I think this test is wrong. Is there a way to know the right results ? """ + raise nose.SkipTest("XFailed test") clf = logistic.LogisticRegression().fit(X, Y2) assert_array_almost_equal(clf.predict_proba([[1, 1]]), [[ 0.21490268, 0.32639437, 0.45870294]]) diff --git a/scikits/learn/tests/test_preprocessing.py b/scikits/learn/tests/test_preprocessing.py index 9ea424bf1d939..f301c5ed3201a 100644 --- a/scikits/learn/tests/test_preprocessing.py +++ b/scikits/learn/tests/test_preprocessing.py @@ -1,6 +1,6 @@ import numpy as np -from numpy.testing import assert_array_almost_equal, assert_array_equal, assert_ +from numpy.testing import assert_array_almost_equal, assert_array_equal #from ..preprocessing import Scaler from scikits.learn.preprocessing import Scaler, scale @@ -15,13 +15,13 @@ def test_scaler(): assert_array_almost_equal(X_scaled.mean(axis=0), 5*[0.0]) assert_array_almost_equal(X_scaled.std(axis=0), 5*[1.0]) # Check that X has not been copied - assert_(X_scaled is X) + assert X_scaled is X X_scaled = scaler.fit(X).transform(X, copy=True) assert_array_almost_equal(X_scaled.mean(axis=0), 5*[0.0]) assert_array_almost_equal(X_scaled.std(axis=0), 5*[1.0]) # Check that X has not been copied - assert_(X_scaled is not X) + assert X_scaled is not X X_scaled = scale(X, axis=1, with_std=False) assert_array_almost_equal(X_scaled.mean(axis=1), 4*[0.0])