Skip to content
Snippets Groups Projects
Commit 5add50c5 authored by Olivier Grisel's avatar Olivier Grisel
Browse files

cosmit on PCA module

parent dd71aceb
No related branches found
No related tags found
No related merge requests found
......@@ -190,8 +190,7 @@ class PCA(BaseEstimator):
return self
def transform(self, X):
""" Apply the dimension reduction learned on the train data.
"""
"""Apply the dimension reduction learned on the train data."""
Xr = X - self.mean_
Xr = np.dot(Xr, self.components_)
return Xr
......
......@@ -9,10 +9,9 @@ iris = datasets.load_iris()
X = iris.data
def test_pca():
"""
PCA
"""
"""PCA on dense arrays"""
pca = PCA(n_comp=2)
X_r = pca.fit(X).transform(X)
np.testing.assert_equal(X_r.shape[1], 2)
......@@ -24,8 +23,7 @@ def test_pca():
def test_pca_check_projection():
"""test that the projection of data is correct
"""
"""Test that the projection of data is correct"""
n, p = 100, 3
X = randn(n, p) * .1
X[:10] += np.array([3, 4, 5])
......@@ -38,8 +36,7 @@ def test_pca_check_projection():
def test_fast_pca_check_projection():
"""test that the projection of data is correct
"""
"""Test that the projection of data is correct"""
n, p = 100, 3
X = randn(n, p) * .1
X[:10] += np.array([3, 4, 5])
......@@ -52,8 +49,7 @@ def test_fast_pca_check_projection():
def test_pca_dim():
"""
"""
"""Check automated dimensionality setting"""
n, p = 100, 5
X = randn(n, p) * .1
X[:10] += np.array([3, 4, 5, 1, 2])
......@@ -63,11 +59,13 @@ def test_pca_dim():
def test_infer_dim_1():
"""
"""TODO: explain what this is testing
Or at least use explicit variable names...
"""
n, p = 1000, 5
X = randn(n, p)*0.1 + randn(n, 1)*np.array([3, 4, 5, 1, 2]) + np.array(
[1, 0, 7, 4, 6])
X = randn(n, p) * .1 + randn(n, 1) * np.array([3, 4, 5, 1, 2]) \
+ np.array([1, 0, 7, 4, 6])
pca = PCA(n_comp=p)
pca.fit(X)
spect = pca.explained_variance_
......@@ -79,7 +77,9 @@ def test_infer_dim_1():
def test_infer_dim_2():
"""
"""TODO: explain what this is testing
Or at least use explicit variable names...
"""
n, p = 1000, 5
X = randn(n, p) * .1
......@@ -106,8 +106,7 @@ def test_infer_dim_3():
def test_probabilistic_pca_1():
"""test that probabilistic PCA yields a readonable score
"""
"""Test that probabilistic PCA yields a reasonable score"""
n, p = 1000, 3
X = randn(n, p)*.1 + np.array([3, 4, 5])
ppca = ProbabilisticPCA(n_comp=2)
......@@ -118,8 +117,7 @@ def test_probabilistic_pca_1():
def test_probabilistic_pca_2():
"""test that probabilistic PCA correctly separated different datasets
"""
"""Test that probabilistic PCA correctly separated different datasets"""
n, p = 100, 3
X = randn(n, p) * .1 + np.array([3, 4, 5])
ppca = ProbabilisticPCA(n_comp=2)
......@@ -144,8 +142,7 @@ def test_probabilistic_pca_3():
def test_probabilistic_pca_4():
"""Check that ppca select the right model
"""
"""Check that ppca select the right model"""
n, p = 200, 3
Xl = randn(n, p) + randn(n, 1)*np.array([3, 4, 5]) + np.array([1, 0, 7])
Xt = randn(n, p) + randn(n, 1)*np.array([3, 4, 5]) + np.array([1, 0, 7])
......@@ -161,3 +158,4 @@ def test_probabilistic_pca_4():
if __name__ == '__main__':
import nose
nose.run(argv=['', __file__])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment