So yesterday I asked you all what you wanted to hear about from me this week, and one answer stood out from all the others: the SINGULAR VALUE DECOMPOSITION (SVD).



1/
The person who posted this tweet may or may not have known that in my normal life, while not curating the @WomenInStat account, I’m stanning hard for this matrix decomposition.


2/
TBH asking to hear about SVD caught me a bit off guard, because the SVD is *not* usually considered to be a “women’s issue”.

3/
But, many issues -- access to healthcare, re-opening schools, police brutality, etc. -- affect all people, but affect marginalized groups the most. And women (esp. Black, Indigenous, Women of Color, LGBTQ+) are a marginalized group in statistics.

4/
So, by that logic, I guess now is as good a time as any for some real talk about the SVD.

5/
So a lot of people think of the SVD as “just another matrix decomposition”.

But today I will argue that if you are in statistics or data science, it is the #1 matrix decomposition, and likely the only one you will ever need.

And believe me: you are going to need it.

6/
First of all, what does the SVD do? You give me an $n \times p$ matrix $X$, and I’ll give you back 3 matrices $U$, $D$, $V$. Without loss of generality let’s assume that $n \geq p$. Then $U$ is an $n \times p$ matrix, and $D$ and $V$ have dimension $p \times p$.

7/
$U$, $D$, $V$ “decompose” the matrix $X$ because $X=UDV^T$. Simple as that. But, what makes this decomposition special (and unique) is the particular set of properties of $U$, $D$, and $V$.

8/ Image
To begin, $U$ and $V$ are orthogonal matrices, which means that $U^T U = I$ and $V^T V = I$. (Also, if you’re keeping score at home, $V V^T = I$ as well. Don’t be fooled tho: $U U^T \neq I$ !!!!!!!)

9/ Image
In layperson’s terms, the columns of $U$ and $V$ are special: the squared elements of each column of $U$ and $V$ sums to 1, and also the inner product (dot product) btw each pair of columns in $U$ equals 0. And the inner product between each pair of columns of $V$ equals 0.

10/
And $D$ is diagonal with nonnegative and decreasing elements: $D_{11} \geq D_{22} \geq \ldots \geq D_{pp} \geq 0$.

11/ Image
Some terminology: the diagonal elements of D are the SINGULAR VALUES, and the columns of U and V are the LEFT and RIGHT SINGULAR VECTORS.

12/
First of all, let’s marvel that this decomposition is not only possible, but easily computable, & even unique (up to sign flips of columns of U & V). Like, why on earth should *every matrix X* be decomposable in this way?

Magic, that’s why.

13/
OK, so, its existence is magic.

But, is it also useful? Well, YES.

14/
Suppose you want to approximate X w/a pair of vectors: that is, a rank-1 approx. Well, the world’s best rank-1 approximation to X, in terms of residual sum of squares, is given by the first columns of U & V:
$X \approx D_{11} U_1 V_1^T$ is literally the best you can do!!

15/ Image
OK, but what if you want to approximate X using two pairs of vectors (a rank-2 approximation)?
Just calculate
$X \approx D_{11} U_1 V_1^T + D_{22} U_2 V_2^T$
and call it a day.

16/ Image
Want an even better approximation, using rank-K? You LITERALLY CAN’T BEAT THIS ONE
$X \approx D_{11} U_1 V_1^T + D_{22} U_2 V_2^T + \ldots + D_{KK} U_K V_K^T$
SO PLEASE DON’T BOTHER TRYING.

17/ Image
OK, so, the SVD gives me the best possible way to approximate any matrix. What is this good for??!!

18/
Ever heard of principal components analysis (PCA)? This is just the SVD (after centering columns of X to have mean 0). Columns of V are PC loading vectors. Columns of U (up to scaling) are PC score vectors.

Bam!!!

19/
How about if you want to impute missing values in your data matrix X?

Assuming that the elements of X are randomly missing (rather than, for instance, larger elements more likely to be missing), the SVD gives you an effective and easy way to impute those values!!

20/
First, fill in missing elements using (say) the column mean.

Then, compute SVD to get rank-K approx for (e.g.) K=3.

Replace the missing elements with the elements of rank-K approx.

Rinse and repeat until your answer stops changing.

Voila!! I am not making this up!!

21/
The SVD is like a matrix X-ray.

For instance:
* X^T X = V D^2 V^T
* (X^T X)^{-1} = V D^{-2} V^T
* X(X^T X)^{-1} X^T = U D^{-2} U^T.
Take a minute to breathe this in.

The 1st and 2nd have no U’s, and the 3rd (hat matrix from least squares) has no V’s or D’s!

Wowzers!

22/ Image
Now, you may ask “well what about the eigen decomp?”

Well I can dispense with that concern in 1 tweet.

A symmetric matrix A (the only type worth eigendecomposing, IMO) is just $A=X^T X$ for some X.

And $X^T X = V D^2 V^T$ (see prev. tweet).

SVD >> Eigendecomp.

QED

23/
Not convinced? Need me to spell it out for u?

Singular vectors are the eigenvectors of $A$, and singular values are the sqrt of the eigenvalues!!!

So, the SVD gives you the eigendecomp for free!!!

EIGENDECOMPOSITION JUST GOT OWNED BY THE SVD.

That’s how it’s done!!!!!

24/
The SVD is a great 1-stop shop for data analysis.

Need to know if X is multicollinear, before fitting least squares?

Check out the singular values. If D_{11}/D_{pp} is huge then least squares is a bad idea.

If D_{pp}=0 then bad news bears, X isn’t even invertible!!

25/
Want to know the rank of X? It’s just # of non-zero singular values!

Want the Moore-Penrose pseudoinverse (though plz be careful — there are better ways to approximate a matrix inverse)?

That's basically the rank-K approx from earlier, but w/ 1/DD_{k} instead of DD_k!

26/
And please don’t troll me with your comments about how you prefer the QR or LU decompositions.

I’m a working mom with 3 kids at home in the midst of a pandemic, I know you don’t mean it, and I literally don’t have time for this.

27/
And if you prefer a specialty matrix decomposition, like NMF, then I’ve got news for you: you got fooled, because that’s just a souped up SVD. Honest to god.

28/
If you remain convinced that the NMF or any other decomposition discovered in the past 80 years can hold a candle to the SVD, then I can get you a great price on a Tesla-branded vegan unicorn made out of CRISPR.

I’ll send it to you as soon as you give me all your Bitcoin.

29/
The SVD is super magical and there’s so much I’ve left unsaid.

While you can compute it using a single line of code in R or any other halfway decent programming language, it’s fun, easy, and safe to DIY w/ matrix multiplies!!!!

Check out this R code!! Wowzers!!!

30/ Image
I hope that this thread has helped to grow your appreciation for this magical decomposition.

The more you learn about the SVD, the more you will love it.

It will take you far on your statistics and data science journey. Godspeed.

31/31
A couple of typos worth correcting:

1) X(X^T X)^{-1} X^T = UU^T -- I had some extra D's floating around in there

2) To know if the matrix **X^T X** is invertible, you just have to check whether the smallest singular value is non-zero. (X itself has no inverse if n>p.)

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Women in Statistics and Data Science

Women in Statistics and Data Science Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @WomenInStat

Dec 14, 2021
You know how excited @daniela_witten gets about SVD? I have about the same thing with kernels. Except that I'm not sure I explain them as well as she does SVD. Still, you're getting a thread on kernels!
Maybe one way of putting it is that kernels are dot products on steroid. The dot product is already pretty cool.

1) It's easy to compute and you learn about it in high school math (at least I did, who knows what kids learn in high school now).
Take two p-dimensional vectors x = (x1, x2, ..., xp) and y = (y1, y2, ..., yp), their dot product <x|y> is simply the sum of the product of their coordinates:
<x|y> = x1 y1 + x2 y2 + ... + xp yp.
Read 31 tweets
Dec 14, 2021
Good morning everybody! Let's talk a bit about how I came to develop statistical / machine learning tools for genomics, healthcare and drug discovery.
I trained as an engineer at @IMTAtlantique, with a specialization in computer science. I didn't really enjoy statistics and graduated in 2005, back when AI belonged to scifi and nobody knew what machine learning was.
@IMTAtlantique What really interested me was bioinformatics - the idea that my training in maths and computer science could be put to use to help solve problems from the life sciences was very appealing! So I jumped at the opportunity to intern in a lab that was doing just that.
Read 14 tweets
Dec 13, 2021
OK, so a bit of background about me: I'm French (and tweeting from Paris), and I'm currently an associate professor at an engineering school called @MINES_ParisTech.
@MINES_ParisTech The research group I'm in (CBIO) has a partnership with @institut_curie, which is a cancer research institute. CBIO has four PIs, working on various topics related to, you've guessed it, statistics / machine learning & cancer.
@MINES_ParisTech @institut_curie My plan for the week is to talk more about my career path, my research topics, and my love of kernels. Of course I'll also talk about what we do at @WiMLDS_Paris, about open/reproducible science, and about teaching machine learning!
Read 5 tweets
Dec 4, 2021
I have organized multiple conferences over the years.

Tips to conference organizers to support women at your meeting

1- Actively consider gender and career stage balance in speakers.
2- Women and minorities may take a longer route to success, try to avoid ageist selection.
3- Provide lactation rooms (with equipment & milk storage). Pumps are heavy and a pain to carry around a meeting. The room should be close-by not a long walk away
4.- Small babies are welcome. Check there is a changing table accessible to dads & mums.
5.- Parents of young children are often postdocs, junior faculty who need and are grateful for childcare and/or travel scholarships.

6- Go Hybrid. Live stream & record talks. Its great if one is stuck in a lactation room, or watching remotely
Read 6 tweets
Dec 3, 2021
@Bioconductor provides genome annotation for thousands of species and its packages are used in almost every biological discipline including
Immunology
Oncology
Evolution and Phylogenetics
cheminformatics
comparative genomics
epigenetics
pharamacogenomics
systems biology
etc
@Bioconductor @Bioconductor is a repository for R packages. There are daily builds & checks of packages.

All packages submitted to Bioconductor are reviewed to check they are documented, have tutorials (vignettes) and pass R CMD Check and BiocCheck

Reviews are friendly and help developers
@Bioconductor @bioconductor is a community

The core team with the community create standard class structures for data. Developers create methods that use these, creating a connected framework were packages work together and provide entire analysis workflows

The Books bioconductor.org/books
Read 7 tweets
Dec 3, 2021
Lets chat @Bioconductor A thread on
- what is @Bioconductor
- Why use @Bioconductor
- How to get started and contribute to @Bioconductor
@Bioconductor @Bioconductor is an open source open development project in the #RStats language for genomics

It has approx 100K distinct downloads every month and is used globally

bioconductor.org/packages/stats…
@Bioconductor @Bioconductor updates are released twice a year in October and April

The current release @Bioconductor 3.14, consists of 2083 #RStats packages, 408 experiment data packages, 904 annotation packages, 29 workflows and 8 books.
Read 5 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us!

:(