Skip to content

Commit a932dfe

Browse files
committed
Fix show method for PCA
It should call the three argument show method for CoefTable
1 parent e80818c commit a932dfe

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/pca.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function show(io::IO, ::MIME"text/plain", M::PCA)
153153
ldgs = ldgs * diagm(0 => ldgs_signs[:])
154154
print(io, "\n\nPattern matrix (unstandardized loadings):\n")
155155
cft = CoefTable(ldgs, string.("PC", 1:odim), string.("", 1:idim))
156-
print(io, cft)
156+
show(io, MIME"text/plain"(), cft)
157157
print(io, "\n\n")
158158
print(io, "Importance of components:\n")
159159
λ = eigvals(M)
@@ -164,7 +164,7 @@ function show(io::IO, ::MIME"text/plain", M::PCA)
164164
"Proportion explained", "Cumulative proportion"]
165165
cft = CoefTable(vcat', prp', cumsum(prp)', prpv', cumsum(prpv)'),
166166
string.("PC", 1:odim), names)
167-
print(io, cft)
167+
show(io, MIME"text/plain"(), cft)
168168
end
169169

170170
#### PCA Training

test/pca.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,30 @@ import SparseArrays
4343
@test reconstruct(M, Y[:,1]) P * Y[:,1]
4444
@test reconstruct(M, Y) P * Y
4545

46+
@test repr("text/plain", M) == """
47+
PCA(indim = 5, outdim = 3, principalratio = 0.8)
48+
49+
Pattern matrix (unstandardized loadings):
50+
─────────────────────────────────
51+
PC1 PC2 PC3
52+
─────────────────────────────────
53+
1 -0.236399 0.706558 1.21106
54+
2 1.27426 0.047799 0.212282
55+
3 0.990598 -1.22718 0.882179
56+
4 -1.51861 -0.725771 0.631665
57+
5 0.181386 1.21069 0.557706
58+
─────────────────────────────────
59+
60+
Importance of components:
61+
───────────────────────────────────────────────────
62+
PC1 PC2 PC3
63+
───────────────────────────────────────────────────
64+
SS Loadings (Eigenvalues) 5.0 4.0 3.0
65+
Variance explained 0.333333 0.266667 0.2
66+
Cumulative variance 0.333333 0.6 0.8
67+
Proportion explained 0.416667 0.333333 0.25
68+
Cumulative proportion 0.416667 0.75 1.0
69+
───────────────────────────────────────────────────"""
4670

4771
## PCA with non-zero mean
4872

0 commit comments

Comments
 (0)