Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scikit-learn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ian Johnson
scikit-learn
Commits
5add50c5
Commit
5add50c5
authored
14 years ago
by
Olivier Grisel
Browse files
Options
Downloads
Patches
Plain Diff
cosmit on PCA module
parent
dd71aceb
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
scikits/learn/pca.py
+1
-2
1 addition, 2 deletions
scikits/learn/pca.py
scikits/learn/tests/test_pca.py
+22
-24
22 additions, 24 deletions
scikits/learn/tests/test_pca.py
with
23 additions
and
26 deletions
scikits/learn/pca.py
+
1
−
2
View file @
5add50c5
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
scikits/learn/tests/test_pca.py
+
22
−
24
View file @
5add50c5
...
...
@@ -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__
])
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment