# Pca question

**URL:** https://discourse.julialang.org/t/pca-question/63337
**Category:** Optimization (Mathematical)
**Created:** [June 21, 2021, 11:07pm UTC](https://discourse.julialang.org/t/pca-question/63337 "2021-06-21T23:07:51Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Kevin\_25](https://avatars.discourse-cdn.com/v4/letter/k/6bbea6/32.png) [@Kevin\_25](https://discourse.julialang.org/u/Kevin_25)
#### Post date: [June 21, 2021, 11:07pm UTC](https://discourse.julialang.org/t/pca-question/63337/1 "2021-06-21T23:07:51Z")

</div>

I was wondering if there is a command or a way to produce the result of the “explained\_variance\_ratio\_” command from scikitlearn in order to plot it.

Thanks.

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [June 22, 2021, 8:31pm UTC](https://discourse.julialang.org/t/pca-question/63337/2 "2021-06-22T20:31:58Z")

</div>

Hi @Kevin_25,

Since this is your first post, please read [Please read: make it easier to help you](https://discourse.julialang.org/t/please-read-make-it-easier-to-help-you/14757).

Unless I’m misunderstanding your question, you’ve stumbled onto a Julia forum instead of a Python/scikit-learn forum. I suggest you consult the scikit-learn documentation or ask on their forums.

---

<div class="post-metadata">

### Author: ![ElOceanografo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eloceanografo/32/624_2.png) [@ElOceanografo](https://discourse.julialang.org/u/ElOceanografo)
#### Post date: [June 22, 2021, 9:32pm UTC](https://discourse.julialang.org/t/pca-question/63337/3 "2021-06-22T21:32:19Z")

</div>

@Kevin_25, if you are talking about PCA as implemented in MultivariateStats.jl, you can get the proportion of total variance explained by each component like so:

```julia
using MultivariateStats
X = randn(10, 1000)
M = fit(PCA, X)
principalvars(M) / tvar(M)

```

See the documentation here: [Principal Component Analysis — MultivariateStats 0.1.0 documentation](https://multivariatestatsjl.readthedocs.io/en/stable/pca.html)

If you’re doing it “by hand,” you can get the same info like this:

```julia
using LinearAlgebra, Statistics
λ, Φ = eigen(cov(X, dims=2))
λ / sum(λ)

```

(Note that `eigen` returns the eigenvalues in ascending order.)
