Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict output height of PCA model representation #195

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/src/pca.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ pcacov
pcasvd
```

**Note:** By default, the model displayed with additional statistics (e.g. loadings, variance, etc.).
Depending on a screens size this output may be limited. Use `show(stdout, "text/plain", M)` to produce
a full model output.

## Kernel Principal Component Analysis

[Kernel Principal Component Analysis](https://en.wikipedia.org/wiki/Kernel_principal_component_analysis>) (kernel PCA)
Expand Down
10 changes: 10 additions & 0 deletions src/pca.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,16 @@ function show(io::IO, M::PCA)
end

function show(io::IO, ::MIME"text/plain", M::PCA)
screenheight = if !(get(io, :limit, false)::Bool)
typemax(Int)
else
displaysize(io)[1]-4
end

idim, odim = size(M)
print(io, "PCA(indim = $idim, outdim = $odim, principalratio = $(r2(M)))")
screenheight > idim+4 || return

ldgs = loadings(M)
rot = diag(ldgs' * ldgs)
ldgs = ldgs[:, sortperm(rot, rev=true)]
Expand All @@ -154,6 +162,8 @@ function show(io::IO, ::MIME"text/plain", M::PCA)
print(io, "\n\nPattern matrix (unstandardized loadings):\n")
cft = CoefTable(ldgs, string.("PC", 1:odim), string.("", 1:idim))
print(io, cft)
screenheight > idim+15 || return

print(io, "\n\n")
print(io, "Importance of components:\n")
λ = eigvals(M)
Expand Down