2017年8月24日木曜日

PCA:素晴らしい解説

分散共分散行列、固有値・固有ベクトル からの続き。

前回「日本語の記事を積極的に紹介」と書いたように、初めは日本語の記事を読んだ。期待以上の良い記事もあったが、結局のところ、偶然見つけた今回の英文記事には負ける。
私にとって、日本語の(日本人による)記事が(英文の記事と比較して)「情報量不足」なのは明らか。そうなってしまう理由は、自明なことだと思うが、それはここでは大きく脱線するので書かない。

一応日本語訳を記した(意図的に訳さなかったのもある)が、私が理解しやすい「意訳」。強調表記した箇所、私が興味深いと思ったところ。

Having been in the social sciences for a couple of weeks it seems like a large amount of quantitative analysis relies on Principal Component Analysis (PCA). This is usually referred to in tandem with eigenvalues, eigenvectors and lots of numbers. So what’s going on? Is this just mathematical jargon to get the non-maths scholars to stop asking questions? Maybe, but it’s also a useful tool to use when you have to look at data. This post will give a very broad overview of PCA, describing eigenvectors and eigenvalues (which you need to know about to understand it) and showing how you can reduce the dimensions of data using PCA. As I said it’s a neat tool to use in information theory, and even though the maths is a bit complicated, you only need to get a broad idea of what’s going on to be able to use it effectively. 
社会科学において、量的分析は主成分分析(PCA)に大いに依存している。PCA と密接に関係するのは固有値、固有ベクトル、大量の数。数学的に理解するには難しいが、データ分析には有用。この記事では PCA を概観、(是非とも理解すべき)固有ベクトルと固有値を解説、そして PCA を使った次元低減方法を紹介する。数学的には少々複雑だが、効果的に使えばデータの幅広い理解に繋がる。
There’s quite a bit of stuff to process in this post, but i’ve got rid of as much maths as possible and put in lots of pictures. 
この記事では、数学的なことを可能な限り除き、図を多用した。

What is Principal Component Analysis? 
First of all Principal Component Analysis is a good name. It does what it says on the tin. PCA finds the principal components of data. 
Principal Component Analysis「主成分分析」は良い名称で、その名の通りのことをする。つまり、データの「主要な成分を見つける」こと。
It is often useful to measure data in terms of its principal components rather than on a normal x-y axis. So what are principal components then? They’re the underlying structure in the data. They are the directions where there is the most variance, the directions where the data is most spread out. This is easiest to explain by way of example. Here’s some triangles in the shape of an oval: 
主成分に沿ってデータを評価することは、通常の x-y 軸に沿った評価よりも有益な場合がある。主成分とは何かと言えば、データの基本的な構造である。それは、最もデータが分散している向き。次の図は、楕円の形で三角形が散らばっている様子:
Imagine that the triangles are points of data. To find the direction where there is most variance, find the straight line where the data is most spread out when projected onto it. A vertical straight line with the points projected on to it will look like this: 
この三角形をデータと見なして、最も分散が大きい向きを探す。つまり、データから直線に写像して、最も散らばりが大きくなる直線を探す。次は、水平に引いた場合の写像の様子:
The data isn’t very spread out here, therefore it doesn’t have a large variance. It is probably not the principal component. 
データの散らばりはそれほど大きくなく、これは恐らく主成分ではない。 
A horizontal line are with lines projected on will look like this: 
次は、水平な線での写像:
On this line the data is way more spread out, it has a large variance. In fact there isn’t a straight line you can draw that has a larger variance than a horizontal one. A horizontal line is therefore the principal component in this example. 
実際この線が、データの分散を最も大きくする。つまり、この例では水平の線が主成分となる。
Luckily we can use maths to find the principal component rather than drawing lines and unevenly shaped triangles. This is where eigenvectors and eigenvalues come in. 
実際、主成分を見つけるのに、このように線を引くのではなく、数学的に見つける。固有ベクトルと固有値の出番となる。

図の ev1 とは、第一番目の eigenvector/eigenvalue の意味。

Eigenvectors and Eigenvalues 
When we get a set of data points, like the triangles above, we can deconstruct the set into eigenvectors and eigenvalues. Eigenvectors and values exist in pairs: every eigenvector has a corresponding eigenvalue. An eigenvector is a direction, in the example above the eigenvector was the direction of the line (vertical, horizontal, 45 degrees etc.) . An eigenvalue is a number, telling you how much variance there is in the data in that direction, in the example above the eigenvalue is a number telling us how spread out the data is on the line. The eigenvector with the highest eigenvalue is therefore the principal component. 
データセットから固有ベクトルと固有値を求める。固有ベクトルと固有値はペアで、固有ベクトルには対応する固有値がある。固有ベクトルとは向きで、先の例では直線の向きとなる(水平、垂直、45 度線、など)。固有値とは、その向きでデータの分散の具合いを示す数字で、先の例では直線上でデータの散らばり具合を固有値が表す。よって、最大の固有値の固有ベクトルが主成分ということ。
Okay, so even though in the last example I could point my line in any direction, it turns out there are not many eigenvectors/values in a data set. In fact the amount of eigenvectors/values that exist equals the number of dimensions the data set has. Say i’m measuring age and hours on the internet. there are 2 variables, it’s a 2 dimensional data set, therefore there are 2 eigenvectors/values. If i’m measuring age, hours on internet and hours on mobile phone there’s 3 variables, 3-D data set, so 3 eigenvectors/values. The reason for this is that eigenvectors put the data into a new set of dimensions, and these new dimensions have to be equal to the original amount of dimensions. This sounds complicated, but again an example should make it clear. 
固有値/ベクトルの数は、一つのデータセットに多くはない。実際、固有値/ベクトルの数は、データセットの次元の数と一致する。例えば、年齢、インターネット利用時間の二つの変数をもつデータセットの場合、二つの固有値/ベクトルのペアがある。これに「携帯電話の利用時間」を加えた三変数なら、ペアは三つとなる。The reason for this is that eigenvectors put the data into a new set of dimensions, and these new dimensions have to be equal to the original amount of dimensions. 複雑に聞こえるが、例で示す。
Here’s a graph with the oval:
At the moment the oval is on an x-y axis. x could be age and y hours on the internet. These are the two dimensions that my data set is currently being measured in. Now remember that the principal component of the oval was a line splitting it longways: 
x が年齢、y がインターネット利用時間。この楕円の主成分の線は次の通り:
It turns out the other eigenvector (remember there are only two of them as it’s a 2-D problem) is perpendicular to the principal component. As we said, the eigenvectors have to be able to span the whole x-y area, in order to do this (most effectively), the two directions need to be orthogonal (i.e. 90 degrees) to one another. This why the x and y axis are orthogonal to each other in the first place. It would be really awkward if the y axis was at 45 degrees to the x axis. So the second eigenvector would look like this: 
もう一つの固有ベクトルは、主成分に対して垂直。
The eigenvectors have given us a much more useful axis to frame the data in. We can now re-frame the data in these new dimensions. It would look like this: 
固有ベクトルは、データをより有意義に分ける軸で、次のように軸を変更できる:
Note that nothing has been done to the data itself. We’re just looking at it from a different angle. So getting the eigenvectors gets you from one set of axes to another. These axes are much more intuitive to the shape of the data now. These directions are where there is most variation, and that is where there is more information (think about this the reverse way round. If there was no variation in the data [e.g. everything was equal to 1] there would be no information, it’s a very boring statistic – in this scenario the eigenvalue for that dimension would equal zero, because there is no variation). 
特筆すべきは、データには何もしていないこと。単に、データを違う向きで眺めただけ。この軸により、データの様子が明確になる。最も分散の大きい向きは、より多くの情報を含む(データに散らばりがないと、例えば全てが 1 の場合、そこには情報はない。この場合、分散がないので、その次元の固有値はゼロ)。
But what do these eigenvectors represent in real life? The old axes were well defined (age and hours on internet, or any 2 things that you’ve explicitly measured), whereas the new ones are not. This is where you need to think. There is often a good reason why these axes represent the data better, but maths won’t tell you why, that’s for you to work out.
How does PCA and eigenvectors help in the actual analysis of data? Well there’s quite a few uses, but a main one is dimension reduction. 
実際のデータ分析で、PCA と固有ベクトルの利用は多岐にわたるが、中でも主要なのが次元低減。 

Dimension Reduction
PCA can be used to reduce the dimensions of a data set. Dimension reduction is analogous to being philosophically reductionist: It reduces the data down into it’s basic components, stripping away any unnecessary parts. 
PCA はデータの次元低減に用いられる。次元低減は、基本的な要素を残して、不要な部分を除く。 
Let’s say you are measuring three things: age, hours on internet and hours on mobile. There are 3 variables so it is a 3D data set. 3 dimensions is an x,y and z graph, It measure width, depth and height (like the dimensions in the real world). Now imagine that the data forms into an oval like the ones above, but that this oval is on a plane. i.e. all the data points lie on a piece of paper within this 3D graph (having width and depth, but no height). Like this: 
ここでは、三つのことを計測:年齢、インターネット利用時間、携帯電話の利用時間。x, y, z の三次元グラフで、現実世界のように幅、深さ、高さを測る。データは先のように楕円を形成しているが、今回はその楕円は平面にある。つまり、全データは三次元グラフにある紙切れの上にある(幅と深さはあるが、高さがない)。図にするとこんな感じ:
「なぜ高さが無いのか?」に悩んだが、一応の解釈として
Hours on mobile は、全くもって Principal Component ではないから
よって、この後の ev3 は、第三の固有ベクトルで、その固有値は「ゼロ」。
訂正:Apr 25, 2018

When we find the 3 eigenvectors/values of the data set (remember 3D problem = 3 eigenvectors), 2 of the eigenvectors will have large eigenvalues, and one of the eigenvectors will have an eigenvalue of zero. The first two eigenvectors will show the width and depth of the data, but because there is no height on the data (it is on a piece of paper) the third eigenvalue will be zero. On the picture below ev1 is the first eigenvector (the one with the biggest eigenvalue, the principal component), ev2 is the second eigenvector (which has a non-zero eigenvalue) and ev3 is the third eigenvector, which has an eigenvalue of zero. 
最初の二つの固有ベクトルが、データの幅と深さを表すが、(紙の上にある)データには高さがないので、第三の固有ベクトルはゼロ。図で ev1 は第一の固有ベクトル(固有値が最大で、これが主成分)、ev1 が第二の固有ベクトル(固有値はゼロではない)、ev3 が第三の固有ベクトルで固有値はゼロ。
We can now rearrange our axes to be along the eigenvectors, rather than age, hours on internet and hours on mobile. However we know that the ev3, the third eigenvector, is pretty useless. Therefore instead of representing the data in 3 dimensions, we can get rid of the useless direction and only represent it in 2 dimensions, like before: 
こうやって、年齢、インターネットや携帯電話の利用時間ではなく、固有ベクトルにしたがった軸の再構成が可能になる。ただ、第三の固有ベクトルは不要なので削除して、三次元ではなく二次元でデータを表せる:
This is dimension reduction. We have reduced the problem from a 3D to a 2D problem, getting rid of a dimension. Reducing dimensions helps to simplify the data and makes it easier to visualize. 
これが次元低減で、ここでは三次元から二次元へ低減した。次元低減によりデータが単純化され、視覚化が容易になる。
Note that we can reduce dimensions even if there isn’t a zero eigenvalue. Imagine we did the example again, except instead of the oval being on a 2D plane, it had a tiny amount of height to it. There would still be 3 eigenvectors, however this time all the eigenvalues would not be zero. The values would be something like 10, 8 and 0.1. The eigenvectors corresponding to 10 and 8 are the dimensions where there is a lot of information, the eigenvector corresponding to 0.1 will not have much information at all, so we can therefore discard the third eigenvector again in order to make the data set more simple. 
ところで、固有値がゼロだけが次元低減の対象ではない。先の例で、データが二次元の平面上ではなく、そこに多少の高さがあるとする。この場合、第三の固有ベクトルは存在し、その固有値はゼロではない。この三つの固有値を 10, 8 , 0.1 とする。10, 8 に対応する固有ベクトルには多くの情報があるが、0.1 の固有ベクトルに情報はほとんどない。よって、ゼロではないが、この第三の固有ベクトルは削除してデータを単純化できる。

Example: the OxIS 2013 report 
The OxIS 2013 report asked around 2000 people a set of questions about their internet use. It then identified 4 principal components in the data. This is an example of dimension reduction. Let’s say they asked each person 50 questions. There are therefore 50 variables, making it a 50-dimension data set. There will then be 50 eigenvectors/values that will come out of that data set. Let’s say the eigenvalues of that data set were (in descending order): 50, 29, 17, 10, 2, 1, 1, 0.4, 0.2….. There are lots of eigenvalues, but there are only 4 which have big values – indicating along those four directions there is a lot of information. These are then identified as the four principal components of the data set (which in the report were labelled as enjoyable escape, instrumental efficiency, social facilitator and problem generator), the data set can then be reduced from 50 dimensions to only 4 by ignoring all the eigenvectors that have insignificant eigenvalues. 4 dimensions is much easier to work with than 50! So dimension reduction using PCA helped simplify this data set by finding the dominant dimensions within it. 
OXIS 2013 の報告では、約 2,000 人にインターネット利用に関するアンケート結果から、四つの主成分を特定した。これは、まさに次元低減。そこでは、50 個の質問がなされた(50 個の変数、50 次元のデータセット)。データセットから求めた 50 個の固有値/ベクトルの、降順の固有値は 50, 29, 17, 10, 2, 1, 1, 0.4, 0.2 ... 、大きな値は四つだけ。つまり、この四方向に多くの情報があり、このデータセットは四つの主成分で特定できるということ(その四つとは、enjoyable escape, instrumental efficiency, social facilitator, problem generator)。重要でない固有値の固有ベクトルを無視することで、50 次元からたったの 4 次元に低減した。PCA を利用した次元低減とは、データの主要な次元を見つけて、データを単純化する。

3ステップ(Iris データ)に続く。

0 件のコメント:

コメントを投稿