層次聚類算法 算法_聚類算法簡介

層次聚類算法 算法

Take a look at the image below. It’s a collection of bugs and creepy-crawlies of different shapes and sizes. Take a moment to categorize them by similarity into a number of groups.

看看下面的圖片。 它是各種形狀和大小的錯誤和令人毛骨悚然的爬行動物的集合。 花一點時間按照相似性將它們分為多個組。

This isn’t a trick question. Start with grouping the spiders together.

這不是一個技巧性的問題。 首先將蜘蛛分組在一起。

Done? While there’s not necessarily a “correct” answer here, it’s most likely you split the bugs into four clusters. The spiders in one cluster, the pair of snails in another, the butterflies and moth into one, and the trio of wasps and bees into one more.

做完了嗎 雖然這里一定不是一個“正確”的答案,這是最有可能拆分的錯誤分為四個集群 。 蜘蛛在一個簇中,成對的蝸牛在另一個簇中,蝴蝶和飛蛾成一團,WaSP和蜜蜂三人成群。

That wasn’t too bad, was it? You could probably do the same with twice as many bugs, right? If you had a bit of time to spare — or a passion for entomology — you could probably even do the same with a hundred bugs.

還不錯吧? 您可能會用兩倍多的錯誤來做同樣的事情,對不對? 如果您有空余時間-或對昆蟲學充滿熱情-您甚至可以用一百個bug來做同樣的事情。

For a machine though, grouping ten objects into however many meaningful clusters is no small task, thanks to a mind-bending branch of maths called combinatorics, which tells us that are 115,975 different possible ways you could have grouped those ten insects together.

但是對于一臺機器來說,將十個對象分組到許多有意義的簇中并不是一件容易的事,這要歸功于一個名為combinatorics的彎彎曲曲的數學分支,該分支告訴我們,有115,975種不同的可能方式可以將這十個昆蟲分組在一起。

Had there been twenty bugs, there would have been over fifty trillion possible ways of clustering them.

如果有二十個錯誤,那么將有超過五十萬億種可能的方法將它們聚類。

With a hundred bugs — there’d be many times more solutions than there are particles in the known universe.

有一百個錯誤-解決方案的數量比已知宇宙中存在的粒子多很多倍。

How many times more? By my calculation, approximately five hundred million billion billion times more. In fact, there are more than four million billion googol solutions (what’s a googol?).

還有多少倍? 根據我的計算,大約是五千億億倍 。 實際上,有超過四十億個googol解決方案( 什么是googol? )。

For just a hundred objects.

僅用于一百個對象。

Almost all of those solutions would be meaningless — yet from that unimaginable number of possible choices, you pretty quickly found one of the very few that clustered the bugs in a useful way.

幾乎所有這些解決方案都是毫無意義的-但是,從眾多難以想象的可能選擇中,您很快就找到了以有用的方式對錯誤進行聚類的少數幾個。

Us humans take it for granted how good we are categorizing and making sense of large volumes of data pretty quickly. Whether it’s a paragraph of text, or images on a screen, or a sequence of objects — humans are generally fairly efficient at making sense of whatever data the world throws at us.

我們人類理所當然地認為我們在分類和快速理解大量數據方面有多出色。 無論是一段文字,還是屏幕上的圖像,還是一系列對象,人類通常都能有效地理解世界向我們提供的任何數據。

Given that a key aspect of developing A.I. and machine learning is getting machines to quickly make sense of large sets of input data, what shortcuts are there available?

鑒于開發AI和機器學習的關鍵方面是使機器快速理解大量輸入數據,有哪些捷徑可用?

Here, you can read about three clustering algorithms that machines can use to quickly make sense of large datasets. This is by no means an exhaustive list — there are other algorithms out there — but they represent a good place to start!

在這里,您可以了解機器可以用來快速理解大型數據集的三種聚類算法。 這絕不是一個詳盡的清單-那里還有其他算法-但這是一個不錯的起點!

You’ll find for each a quick summary of when you might use them, a brief overview of how they work, and a more detailed, step-by-step worked example. I believe it helps to understand an algorithm by actually carrying out yourself.

您將找到每種使用時間的快速摘要,它們如何工作的簡要概述以及更詳細的分步工作示例。 我相信通過實際執行自己的算法有助于理解算法。

If you’re really keen, you’ll find the best way to do this is with pen and paper. Go ahead — nobody will judge!

如果您真的很熱衷 ,您會發現使用筆和紙是實現此目的的最佳方法。 繼續-沒有人會判斷!

K均值聚類 (K-means clustering)

在...時使用 (Use when...)

…you have an idea of how many groups you’re expecting to find a priori.

…您對希望找到先驗的小組有一個想法。

這個怎么運作 (How it works)

The algorithm randomly assigns each observation into one of k categories, then calculates the mean of each category. Next, it reassigns each observation to the category with the closest mean before recalculating the means. This step repeats over and over until no more reassignments are necessary.

該算法將每個觀察隨機分配到k個類別之一,然后計算每個類別的平均值 。 接下來,它將在重新計算均值之前將每個觀察值分配給具有最均值的類別。 重復這一步驟,直到不再需要重新分配為止。

工作實例 (Worked Example)

Take a group of 12 football (or ‘soccer’) players who have each scored a certain number of goals this season (say in the range 3–30). Let’s divide them into separate clusters — say three.

以一組12名足球(或“足球”)球員為例,他們每個賽季都進球數(例如3-30)。 讓我們將它們分為單獨的集群-說三個。

Step 1 requires us to randomly split the players into three groups and calculate the means of each.

步驟1要求我們將參與者隨機分為三組,并計算每組的均值。

Group 1Player A (5 goals),Player B (20 goals),Player C (11 goals)
Group Mean = (5 + 20 + 11) / 3 = 12 goalsGroup 2Player D (5 goals),Player E (3 goals),Player F (19 goals)
Group Mean = 9 goalsGroup 3Player G (30 goals),Player H (3 goals),Player I (15 goals)
Group Mean = 16 goals

Step 2: For each player, reassign them to the group with the closest mean. E.g., Player A (5 goals) is assigned to Group 2 (mean = 9). Then recalculate the group means.

步驟2:對于每位玩家,將他們重新分配給具有最接近均值的組。 例如,玩家A(5個進球)被分配給第2組(平均值= 9)。 然后重新計算組均值。

Group 1 (Old Mean = 12 goals)Player C (11 goals)
New Mean = 11 goalsGroup 2 (Old Mean = 9 goals)Player A (5 goals),Player D (5 goals),Player E (3 goals),Player H (3 goals)
New Mean = 4 goalsGroup 3 (Old Mean = 16 goals)Player G (30 goals),Player I (15 goals),Player B (20 goals),Player F (19 goals)
New Mean = 21 goals

Repeat Step 2 over and over until the group means no longer change. For this somewhat contrived example, this happens on the next iteration. Stop! You have now formed three clusters from the dataset!

一遍又一遍地重復步驟2,直到組的含義不再改變為止。 對于這個有些人為的例子,這發生在下一次迭代中。 停止! 現在,您已經從數據集中形成了三個聚類!

Group 1 (Old Mean = 11 goals)Player C (11 goals),Player I (15 goals)
Final Mean = 13 goalsGroup 2 (Old Mean = 4 goals)Player A (5 goals),Player D (5 goals),Player E (3 goals),Player H (3 goals)
Final Mean = 4 goalsGroup 3 (Old Mean = 21 goals)Player G (30 goals),Player B (20 goals),Player F (19 goals)
Final Mean = 23 goals

With this example, the clusters could correspond to the players’ positions on the field — such as defenders, midfielders and attackers.

在這個例子中,集群可以對應于球員在場上的位置,例如防守者,中場球員和進攻者。

K-means works here because we could have reasonably expected the data to fall naturally into these three categories.

K均值之所以在這里起作用,是因為我們可以合理地預期數據自然會落入這三類。

In this way, given data on a range of performance statistics, a machine could do a reasonable job of estimating the positions of players from any team sport — useful for sports analytics, and indeed any other purpose where classification of a dataset into predefined groups can provide relevant insights.

這樣,給定一系列性能統計數據,一臺機器就可以合理地估算出任何團隊運動項目中球員的位置,這對運動分析非常有用,并且在將數據集分類為預定義組的其他任何目的上都非常有用提供相關見解。

更細的細節 (Finer details)

There are several variations on the algorithm described here. The initial method of ‘seeding’ the clusters can be done in one of several ways.

這里描述的算法有幾種變體。 可以通過以下幾種方式之一來完成“播種”群集的初始方法。

Here, we randomly assigned every player into a group, then calculated the group means. This causes the initial group means to tend towards being similar to one another, which ensures greater repeatability.

在這里,我們將每個玩家隨機分配到一個組中,然后計算組均值。 這導致初始組手段趨于彼此相似,從而確保了更大的可重復性。

An alternative is to seed the clusters with just one player each, then start assigning players to the nearest cluster. The returned clusters are more sensitive to the initial seeding step, reducing repeatability in highly variable datasets.

另一種選擇是給每個只有一個玩家的集群播種,然后開始將玩家分配到最近的集群。 返回的簇對初始播種步驟更加敏感,從而降低了高度可變的數據集中的可重復性。

However, this approach may reduce the number of iterations required to complete the algorithm, as the groups will take less time to diverge.

但是,這種方法可能會減少完成算法所需的迭代次數,因為組將花費更少的時間進行分離。

An obvious limitation to K-means clustering is that you have to provide a priori assumptions about how many clusters you’re expecting to find.

K均值聚類的一個明顯限制是,您必須提供關于要找到多少個聚類的先驗假設。

There are methods to assess the fit of a particular set of clusters. For example, the Within-Cluster Sum-of-Squares is a measure of the variance within each cluster.

有一些方法可以評估特定集群集的擬合度。 例如,集群內平方和是每個集群內方差的度量。

The ‘better’ the clusters, the lower the overall WCSS.

群集越“好”,則總體WCSS越低。

層次聚類 (Hierarchical clustering)

在...時使用 (Use when...)

…you wish to uncover the underlying relationships between your observations.

…您希望揭示觀察結果之間的潛在關系。

這個怎么運作 (How it works)

A distance matrix is computed, where the value of cell (i, j) is a distance metric between observations i and j.

計算距離矩陣,其中像元( i,j)的值是觀測值ij之間的距離度量。

Then, pair the closest two observations and calculate their average. Form a new distance matrix, merging the paired observations into a single object.

然后,將最接近的兩個觀測值配對并計算它們的平均值。 形成一個新的距離矩陣,將成對的觀測值合并為一個對象。

From this distance matrix, pair up the closest two observations and calculate their average. Repeat until all observations are grouped together.

從這個距離矩陣中,配對最接近的兩個觀測值并計算它們的平均值。 重復直到將所有觀察結果分組在一起。

工作的例子 (Worked example)

Here’s a super-simplified dataset about a selection of whale and dolphin species. As a trained biologist, I can assure you we normally use much more detailed datasets for things like reconstructing phylogeny.

這是有關鯨和海豚物種選擇的超級簡化數據集。 作為一名訓練有素的生物學家,我可以向您保證,我們通常使用更詳細的數據集來重建系統發育 。

For now though, we’ll just look at the typical body lengths for these six species. We’ll be using just two repeated steps.

現在,我們只看這六個物種的典型體長。 我們將僅使用兩個重復步驟。

Species          Initials  Length(m)
Bottlenose Dolphin     BD        3.0
Risso's Dolphin        RD        3.6
Pilot Whale            PW        6.5
Killer Whale           KW        7.5
Humpback Whale         HW       15.0
Fin Whale              FW       20.0

Step 1: compute a distance matrix between each species. Here, we’ll use the Euclidean distance — how far apart are the data points?

步驟1:計算每個物種之間的距離矩陣。 在這里,我們將使用歐幾里得距離 -數據點相距多遠?

Read this exactly as you would a distance chart in a road atlas. The difference in length between any pair of species can be looked up by reading the value at the intersection of the relevant row and column.

就像在道路地圖集上繪制距離圖一樣,仔細閱讀本章。 可以通過讀取相關行和列相交處的值來查找任意一對物種之間的長度差異。

BD   RD   PW   KW   HW
RD  0.6                    
PW  3.5  2.9               
KW  4.5  3.9  1.0          
HW 12.0 11.4  8.5  7.5     
FW 17.0 16.4 13.5 12.5  5.0

Step 2: Pair up the two closest species. Here, this will be the Bottlenose & Risso’s Dolphins, with an average length of 3.3m.

步驟2:配對兩個最接近的物種。 在這里,這將是寬吻海豚和海豚的海豚,平均長度為3.3m。

Repeat Step 1 by recalculating the distance matrix, but this time merge the Bottlenose & Risso’s Dolphins into a single object with length 3.3m.

通過重新計算距離矩陣來重復步驟1,但是這次將寬吻瓶和里索的海豚合并為一個長度為3.3m的單個對象。

[BD, RD]   PW   KW   HW
PW       3.2               
KW       4.2   1.0          
HW      11.7   8.5  7.5     
FW      16.7  13.5 12.5  5.0

Next, repeat Step 2 with this new distance matrix. Here, the smallest distance is between the Pilot & Killer Whales, so we pair them up and take their average — which gives us 7.0m.

接下來 ,使用這個新的距離矩陣重復步驟2。 在這里,飛行員與虎鯨之間的距離最小,因此我們將它們配對并取它們的平均值,即為7.0m。

Then, we repeat Step 1 — recalculate the distance matrix, but now we’ve merged the Pilot & Killer Whales into a single object of length 7.0m.

然后 ,我們重復步驟1-重新計算距離矩陣,但是現在我們將“飛行員與殺人鯨”合并為一個長度為7.0m的對象。

[BD, RD] [PW, KW]   HW[PW, KW]      3.7              HW           11.7      8.0     FW           16.7     13.0   5.0

Next, repeat Step 2 with this distance matrix. The smallest distance (3.7m) is between the two merged objects — so now merge them into an even bigger object, and take the average (which is 5.2m).

接下來 ,使用此距離矩陣重復步驟2。 最小的距離(3.7m)在兩個合并的對象之間-現在將它們合并成更大的對象,并取平均值(即5.2m)。

Then, repeat Step 1 and compute a new distance matrix, having merged the Bottlenose & Risso’s Dolphins with the Pilot & Killer Whales.

然后 ,重復步驟1并計算新的距離矩陣,將寬吻鼻和里索的海豚與飛行員和虎鯨合并。

[[BD, RD] , [PW, KW]]    HW
HW                   9.8    
FW                  14.8   5.0

Next, repeat Step 2. The smallest distance (5.0m) is between the Humpback & Fin Whales, so merge them into a single object, and take the average (17.5m).

接下來 ,重復步驟2。座頭鯨和鰭鯨之間的最小距離(5.0m),因此將它們合并為一個對象,并取其平均值(17.5m)。

Then, it’s back to Step 1 — compute the distance matrix, having merged the Humpback & Fin Whales.

然后 ,返回到步驟1-合并了座頭鯨和鰭鯨,計算距離矩陣。

[[BD, RD] , [PW, KW]]
[HW, FW]                  12.3

Finally, repeat Step 2 — there is only one distance (12.3m) in this matrix, so pair everything into one big object. Now you can stop! Look at the final merged object:

最后,重復步驟2-這個矩陣只有一個距離(12.3m),因此將所有東西配對成一個大物體。 現在您可以停止! 查看最終的合并對象:

[[[BD, RD],[PW, KW]],[HW, FW]]

It has a nested structure (think JSON), which allows it to be drawn up as a tree-like graph, or 'dendrogram'.

它具有嵌套結構(例如JSON ),可以將其繪制為樹狀圖或“樹狀圖”。

It reads in much the same way a family tree might. The nearer two observations are on the tree, the more similar or closely-related they are taken to be.

它的讀取方式與家譜的讀取方式幾乎相同。 樹上的兩個觀測值越接近,它們被認為越相似或緊密相關。

The structure of the dendrogram gives insight into how the dataset is structured.

樹狀圖的結構使您可以深入了解數據集的結構。

In this example, there are two main branches, with Humpback Whale and Fin Whale on one side, and the Bottlenose Dolphin/Risso’s Dolphin and Pilot Whale/Killer Whale on the other.

在此示例中,有兩個主要分支,一側是座頭鯨和鰭鯨,另一側是寬吻海豚/里索的海豚和領航鯨/殺人鯨。

In evolutionary biology, much larger datasets with many more specimens and measurements are used in this way to infer taxonomic relationships between them.

在進化生物學中,以這種方式使用具有更多標本和測量值的更大的數據集來推斷它們之間的分類學關系。

Outside of biology, hierarchical clustering has applications in data mining and machine learning contexts.

在生物學之外,層次聚類在數據挖掘和機器學習環境中具有應用。

The cool thing is that this approach requires no assumptions about the number of clusters you’re looking for.

有趣的是,這種方法無需假設您要尋找的群集數量。

You can split the returned dendrogram into clusters by “cutting” the tree at a given height. This height can be chosen in a number of ways, depending on the resolution at which you wish to cluster the data.

您可以通過以指定高度“切割”樹來將返回的樹狀圖拆分為簇。 可以通過多種方式選擇此高度,具體取決于您希望對數據進行聚類的分辨率。

For instance, looking at the dendrogram above, if we draw a horizontal line at height = 10, we’d intersect the two main branches, splitting the dendrogram into two sub-graphs. If we cut at height = 2, we’d be splitting the dendrogram into three clusters.

例如,查看上面的樹狀圖,如果我們在height = 10處繪制一條水平線,我們將與兩個主要分支相交,將樹狀圖分為兩個子圖。 如果我們在高度= 2處進行切割,我們會將樹狀圖分成三個簇。

更細的細節 (Finer details)

There are essentially three aspects in which hierarchical clustering algorithms can vary to the one given here.

從本質上講,層次聚類算法可以在三個方面與此處給出的算法有所不同。

Most fundamental is the approach — here, we have used an agglomerative process, whereby we start with individual data points and iteratively cluster them together until we’re left with one large cluster.

最基本的方法是這種方法-在這里,我們使用了一個凝聚過程,即從單個數據點開始,然后將它們迭代地聚類在一起,直到剩下一個大的聚類。

An alternative (but more computationally intensive) approach is to start with one giant cluster, and then proceed to divide the data into smaller and smaller clusters until you’re left with isolated data points.

另一種替代方法(但計算量更大)是從一個巨型群集開始,然后將數據分成越來越小的群集,直到剩下孤立的數據點為止。

There are also a range of methods that can be used to calculate the distance matrices. For many purposes, the Euclidean distance (think Pythagoras’ Theorem) will suffice, but there are alternatives that may be more applicable in some circumstances.

還有多種方法可用于計算距離矩陣。 對于許多目的,歐幾里德距離(認為畢達哥拉斯定理)就足夠了,但是有些替代方法可能在某些情況下更適用。

Finally, the linkage criterion can also vary. Clusters are linked according to how close they are to one another, but the way in which we define ‘close’ is flexible.

最后, 鏈接標準也可以變化。 群集根據彼此之間的接近程度進行鏈接,但是我們定義“關閉”的方式很靈活。

In the example above, we measured the distances between the means (or ‘centroids’) of each group and paired up the nearest groups. However, you may want to use a different definition.

在上面的示例中,我們測量了每個組的均值(或“質心”)之間的距離,并將最接近的組配對。 但是,您可能要使用其他定義。

For example, each cluster is made up of several discrete points. You could define the distance between two clusters to be the minimum (or maximum) distance between any of their points — as illustrated in the figure below.

例如,每個群集由幾個離散點組成。 您可以將兩個聚類之間的距離定義為它們的任意點之間的最小(或最大)距離,如下圖所示。

There are still other ways of defining the linkage criterion, which may be suitable in different contexts.

還有其他定義鏈接標準的方式,可能適用于不同的上下文。

圖社區檢測 (Graph Community Detection)

使用時 (Use when)

…you have data that can be represented as a network, or ‘graph’.

…您擁有可以表示為網絡或“圖形”的數據。

這個怎么運作 (How it works)

A graph community is very generally defined as a subset of vertices which are more connected to each other than with the rest of the network.

通常將圖社區定義為頂點的子集,這些頂點彼此之間的聯系比與網絡其余部分的聯系更多。

Various algorithms exist to identify communities, based upon more specific definitions. Algorithms include, but are not limited to: Edge Betweenness, Modularity-Maximsation, Walktrap, Clique Percolation, Leading Eigenvector…

基于更具體的定義,存在各種算法來標識社區。 算法包括但不限于:邊緣中間性,模塊化最大化,Walktrap,集團滲透,前導特征向量…

工作的例子 (Worked example)

Graph theory, or the mathematical study of networks, is a fascinating branch of mathematics that lets us model complex systems as an abstract collection of ‘dots’ (or vertices) connected by ‘lines’ (or edges).

圖論或網絡的數學研究是數學的一個引人入勝的分支,它使我們可以將復雜的系統建模為由“線”(或 )連接的“點”(或頂點 )的抽象集合。

Perhaps the most intuitive case-studies are social networks.

也許最直觀的案例研究是社交網絡。

Here, the vertices represent people, and edges connect vertices who are friends/followers. However, any system can be modelled as a network if you can justify a method to meaningfully connect different components.

在這里,頂點代表人,邊連接作為朋友/跟隨者的頂點。 但是,如果可以證明一種方法有意義地連接不同的組件,則可以將任何系統建模為網絡。

Among the more innovative applications of graph theory to clustering include feature extraction from image data, and analysing gene regulatory networks.

圖論在聚類中的更多創新應用包括從圖像數據中提取特征以及分析基因調控網絡。

As an entry-level example, take a look at this quickly put-together graph. It shows the eight websites I most recently visited, linked according to whether their respective Wikipedia articles link out to one another.

作為入門級示例,請看一下此快速匯總的圖表。 它顯示了我最近訪問的八個網站,這些網站根據各自的Wikipedia文章是否相互鏈接而鏈接在一起。

You could assemble this data manually, but for larger-scale projects, it’s much quicker to write a Python script to do the same. Here’s one I wrote earlier.

您可以手動組裝此數據,但是對于大型項目,編寫Python腳本來完成此操作要快得多。 這是我之前寫的 。

The vertices are colored according to their community membership, and sized according to their centrality. See how Google and Twitter are the most central?

頂點根據其社區成員資格進行著色,并根據其中心性進行大小調整。 看看Google和Twitter是最核心的嗎?

Also, the clusters make pretty good sense in the real-world (always an important performance indicator).

此外,集群在現實世界中非常有意義(始終是重要的性能指標)。

The yellow vertices are generally reference/look-up sites; the blue vertices are all used for online publishing (of articles, tweets, or code); and the red vertices include YouTube, which was of course founded by former PayPal employees. Not bad deductions for a machine.

黃色頂點通常是參考/查找站點; 藍色頂點全部用于在線發布(文章,推文或代碼的發布); 紅色頂點包括YouTube,它當然是由前PayPal員工創立的。 對機器的扣減還不錯。

Aside from being a useful way to visualize large systems, the real power of networks comes from their mathematical analysis. Let’s start by translating our nice picture of the network into a more mathematical format. Below is the adjacency matrix of the network.

除了是可視化大型系統的有用方法之外,網絡的真正功能還在于它們的數學分析。 讓我們首先將網絡的漂亮圖片轉換成更數學的格式。 下面是網絡的鄰接矩陣

GH Gl  M  P  Q  T  W  Y
GitHub    0  1  0  0  0  1  0  0  
Google    1  0  1  1  1  1  1  1
Medium    0  1  0  0  0  1  0  0
PayPal    0  1  0  0  0  1  0  1
Quora     0  1  0  0  0  1  1  0
Twitter   1  1  1  1  1  0  0  1
Wikipedia 0  1  0  0  1  0  0  0
YouTube   0  1  0  1  0  1  0  0

The value at the intersection of each row and column records whether there is an edge between that pair of vertices.

每行和列的交點處的值記錄該對頂點之間是否存在邊。

For instance, there is an edge between Medium and Twitter (surprise, surprise!), so the value where their rows/columns intersect is 1. Similarly, there is no edge between Medium and PayPal, so the intersection of their rows/columns returns 0.

例如,Medium和Twitter之間有一條邊(驚訝,令人驚訝!),因此它們的行/列相交的值是1。類似地,Medium和PayPal之間沒有邊,因此它們的行/列的交點返回0。

Encoded within the adjacency matrix are all the properties of this network — it gives us the key to start unlocking all manner of valuable insights.

該網絡的所有屬性都編碼在鄰接矩陣中-它為我們提供了開始解鎖各種有價值的見解的關鍵。

For a start, summing any column (or row) gives you the degree of each vertex — i.e., how many others it is connected to. This is commonly denoted with the letter k.

首先,求和任何列(或行)的總和即可得出每個頂點的度數 ,即它與多少個頂點相連。 通常用字母k表示。

Likewise, summing the degrees of every vertex and dividing by two gives you L, the number of edges (or ‘links’) in the network. The number of rows/columns gives us N, the number of vertices (or ‘nodes’) in the network.

同樣,將每個頂點的度數相加并除以2可得到L ,即網絡中邊(或“鏈接”)的數量。 行數/列數為N ,即網絡中的頂點數(或“節點”)。

Knowing just k, L, N and the value of each cell in the adjacency matrix A lets us calculate the modularity of any given clustering of the network.

只需知道kL,N和鄰接矩陣A中每個像元的值,就可以計算模塊化 網絡的任何給定群集。

Say we’ve clustered the network into a number of communities. We can use the modularity score to assess the ‘quality’ of this clustering.

假設我們已將網絡聚集到多個社區中。 我們可以使用模塊化評分來評估該聚類的“質量”。

A higher score will show we’ve split the network into ‘accurate’ communities, whereas a low score suggests our clusters are more random than insightful. The image below illustrates this.

較高的分數將表明我們已將網絡劃分為“準確的”社區,而較低的分數表明我們的集群比有見地的更為隨機。 下圖說明了這一點。

Modularity can be calculated using the formula below:

模塊化可以使用以下公式計算:

That’s a fair amount of math, but we can break it down bit by bit and it’ll make more sense.

這是相當多的數學運算,但是我們可以一點一點地分解它,這將更有意義。

M is of course what we’re calculating — modularity.

M當然是我們正在計算的-模塊化。

1/2L tells us to divide everything that follows by 2L, i.e., twice the number of edges in the network. So far, so good.

1/2 L告訴我們將其后的所有內容除以2 L ,即網絡中邊數的兩倍。 到目前為止,一切都很好。

The Σ symbol tells us we’re summing up everything to the right, and lets us iterate over every row and column in the adjacency matrix A.

Σ符號告訴我們我們在右邊匯總所有內容,并讓我們遍歷鄰接矩陣A中的每一行和每一列。

For those unfamiliar with sum notation, the i, j = 1 and the N work much like nested for-loops in programming. In Python, you’d write it as follows:

對于那些不熟悉總和表示法的人, i,j = 1N的工作方式很像編程中的嵌套for循環。 在Python中,您可以這樣編寫:

sum = 0
for i in range(1,N):for j in range(1,N):ans = #stuff with i and j as indices sum += ans

So what is #stuff with i and j in more detail?

那么, #stuff with i and j是什么呢?

Well, the bit in brackets tells us to subtract ( k_i k_j ) / 2L from A_ij.

好吧,方括號中的位告訴我們從A_ij減去( k_i k_j)/ 2L

A_ij is simply the value in the adjacency matrix at row i, column j.

A_ij僅是第i j列的鄰接矩陣中的值。

The values of k_i and k_j are the degrees of each vertex — found by adding up the entries in row i and column j respectively. Multiplying these together and dividing by 2L gives us the expected number of edges between vertices i and j if the network were randomly shuffled up.

k_ik_j的值是每個頂點的度數-通過分別將第i行和第j列中的條目相加得出。 如果將網絡隨機改組,則將它們相乘并除以2 L可得到頂點ij之間的預期邊數。

Overall, the term in the brackets reveals the difference between the network’s real structure and the expected structure it would have if randomly reassembled.

總體而言,方括號中的術語揭示了網絡的實際結構與如果隨機重組將具有的預期結構之間的差異。

Playing around with the values shows that it returns its highest value when A_ij = 1, and ( k_i k_j ) / 2L is low. This means we see a higher value if there is an ‘unexpected’ edge between vertices i and j.

數值的計算表明,當A_ij = 1且( k_i k_j)/ 2L為低時,它將返回其最大值。 這意味著如果在頂點ij之間存在“意外”邊緣,則我們看到一個更高的值

Finally, we multiply the bracketed term by whatever the last few symbols refer to.

最后,我們將括號中的術語乘以最后幾個符號所指的內容。

The ?c_i, c_j is the fancy-sounding but totally harmless Kronecker-delta function. Here it is, explained in Python:

?c _i, c _j是聽起來很花哨但完全無害的Kronecker-delta函數。 在Python中進行了解釋:

def kroneckerDelta(ci, cj):if ci == cj:return 1else:return 0kroneckerDelta("A","A")
#returns 1kroneckerDelta("A","B")
#returns 0

Yes — it really is that simple. The Kronecker-delta function takes two arguments, and returns 1 if they are identical, otherwise, zero.

是的-真的就是這么簡單。 Kronecker-delta函數采用兩個參數,如果相同則返回1,否則返回零。

This means that if vertices i and j have been put in the same cluster, then ?c_i, c_j = 1. Otherwise, if they are in different clusters, the function returns zero.

這意味著,如果將頂點ij放在同一簇中,則?c _i, c _j = 1 。 否則,如果它們位于不同的群集中,則該函數將返回零。

As we are multiplying the bracketed term by this Kronecker-delta function, we find that for the nested sum Σ, the outcome is highest when there are lots of ‘unexpected’ edges connecting vertices assigned to the same cluster.

當我們將括號中的項乘以該Kronecker-delta函數時,我們發現對于嵌套的總和Σ ,當有很多“意外”邊緣連接分配給同一聚類的頂點時,結果最高。

As such, modularity is a measure of how well-clustered the graph is into separate communities.

因此,模塊化是衡量圖表在不同社區中的聚集程度的一種度量。

Dividing by 2L bounds the upper value of modularity at 1. Modularity scores near to or below zero indicate the current clustering of the network is really no use. The higher the modularity, the better the clustering of the network into separate communities.

除以2L會將模塊性的上限定為1。接近或低于零的模塊性分數表明該網絡的當前集群實際上沒有用。 模塊化程度越高,將網絡更好地聚集到單獨的社區中就越好。

By maximising modularity, we can find the best way of clustering the network.

通過最大程度地提高模塊化,我們可以找到群集網絡的最佳方法。

Notice that we have to pre-define how the graph is clustered to find out how ‘good’ that clustering actually is.

注意,我們必須預先定義圖的聚類方式,以找出聚類的實際效果。

Unfortunately, employing brute force to try out every possible way of clustering the graph to find which has the highest modularity score would be computationally impossible beyond a very limited sample size.

不幸的是,在非常有限的樣本量之外,采用蠻力嘗試對圖進行聚類以找到具有最高模塊化得分的所有可能方法,在計算上都是不可能的。

Combinatorics tells us that for a network of just eight vertices, there are 4140 different ways of clustering them. A network twice the size would have over ten billion possible ways of clustering the vertices.

組合法告訴我們,對于只有八個頂點的網絡,有4140種不同的方法將它們聚類。 兩倍大小的網絡將有超過一百億種可能的頂點聚類方法。

Doubling the network again (to a very modest 32 vertices) would give 128 septillion possible ways, and a network of eighty vertices would be cluster-able in more ways than there are atoms in the observable universe.

將網絡再次加倍(到非常適度的32個頂點)將提供128億種可能的方式,并且與可觀察的宇宙中存在的原子相比,具有80個頂點的網絡將以更多的方式可集群。

Instead, we have to turn to a heuristic method that does a reasonably good job at estimating the clusters that will produce the highest modularity score, without trying out every single possibility.

取而代之的是,我們必須轉向一種啟發式方法,該方法在估計將產生最高模塊性得分的集群方面做得相當好,而無需嘗試每種可能性。

This is an algorithm called Fast-Greedy Modularity-Maximization, and it’s somewhat analogous to the agglomerative hierarchical clustering algorithm describe above. Instead of merging according to distance, ‘Mod-Max’ merges communities according to changes in modularity.

這是一種稱為快速貪婪模塊化最大化的算法它有點類似于上面描述的聚集層次聚類算法。 'Mod-Max'并非根據距離進行合并,而是根據模塊化的變化來合并社區。

Here’s how it goes:

這是怎么回事:

Begin by initially assigning every vertex to its own community, and calculating the modularity of the whole network, M.

首先將每個頂點分配給它自己的社區,然后計算整個網絡的模塊化M。

Step 1 requires that for each community pair linked by at least a single edge, the algorithm calculates the resultant change in modularity ΔM if the two communities were merged into one.

步驟1要求,對于至少由一條邊鏈接的每個社區對,如果將兩個社區合并為一個社區,該算法將計算模塊性ΔM的最終變化。

Step 2 then takes the pair of communities that produce the biggest increase in ΔM, which are then merged. Calculate the new modularity M for this clustering, and keep a record of it.

然后, 步驟2選取產生最大ΔM的一對社區,然后將其合并。 計算該集群的新模塊性M ,并對其進行記錄。

Repeat steps 1 and 2 — each time merging the pair of communities for which doing so produces the biggest gain in ΔM, then recording the new clustering pattern and its associated modularity score M.

重復步驟1和2-每次合并一對社區,這樣做會在ΔM中產生最大的收益然后記錄新的聚類模式及其相關的模塊化評分M。

Stop when all the vertices are grouped into one giant cluster. Now the algorithm checks the records it kept as it went along, and identifies the clustering pattern that returned the highest value of M. This is the returned community structure.

所有頂點分組為一個大簇時停止 。 現在,該算法檢查其保留的記錄,并確定返回最大M值的聚類模式。 這是返回的社區結構。

更細的細節 (Finer details)

Whew! That was computationally intensive, at least for us humans.

ew! 這是計算密集型的,至少對于我們人類而言。

Graph theory is a rich source of computationally challenging, often NP-hard problems — yet it also has incredible potential to provide valuable insights into complex systems and datasets.

圖論是計算難題(通常是NP難題)的豐富來源,但它也具有令人難以置信的潛力,可以為復雜的系統和數據集提供有價值的見解。

Just ask Larry Page, whose eponymous PageRank algorithm — which helped propel Google from start-up to basically world domination in less than a generation — was based entirely in graph theory.

只需問問拉里·佩奇(Larry Page),他的同名PageRank算法完全基于圖論,該算法在不到一代人的時間里就將Google從新興企業推向了世界統治。

Community detection is a major focus of current research in graph theory, and there are plenty of alternatives to Modularity-Maximization, which while useful, does have some drawbacks.

社區檢測是當前圖論研究的主要重點,模塊化最大化有許多替代方案,盡管它們很有用,但確實存在一些缺點。

For a start, its agglomerative approach often sees small, well-defined communities swallowed up into larger ones. This is known as the resolution limit — the algorithm will not find communities below a certain size.

首先,它的聚集方法通常會看到小型的,定義明確的社區被吞并為較大的社區。 這稱為分辨率限制 -算法將找不到小于特定大小的社區。

Another challenge is that rather than having one distinct, easy-to-reach global peak, the Mod-Max approach actually tends to produce a wide ‘plateau’ of many similar high modularity scores — making it somewhat difficult to truly identify the absolute maximum score.

另一個挑戰是,Mod-Max方法并沒有產生一個清晰易懂的全球峰值,而是趨向于產生許多相似的高模塊評分的寬廣的“平臺”,這使得真正識別絕對最大評分有些困難。

Other algorithms use different ways to define and approach community detection.

其他算法使用不同的方式來定義和處理社區檢測。

Edge-Betweenness is a divisive algorithm, starting with all vertices grouped in one giant cluster. It proceeds to iteratively remove the least ‘important’ edges in the network, until all vertices are left isolated. This produces a hierarchical structure, with similar vertices closer together in the hierarchy.

Edge-Betweenness是一種分割算法,從將所有頂點分組到一個巨型簇中開始。 進行迭代地刪除網絡中最不重要的邊緣,直到所有頂點都保持隔離。 這將產生一個層次結構,相似的頂點在層次結構中靠得更近。

Another algorithm is Clique Percolation, which takes into account possible overlap between graph communities.

另一個算法是Clique Percolation ,它考慮了圖社區之間可能的重疊。

Yet another set of algorithms are based on random-walks across the graph, and then there are spectral clustering methods which start delving into the eigendecomposition of the adjacency matrix and other matrices derived therefrom. These ideas are used in feature extraction in, for example, areas such as computer vision.

另一組算法是基于整個圖的隨機游動 ,然后是頻譜聚類方法,它們開始研究鄰接矩陣和從中得出的其他矩陣的特征分解。 這些想法用于例如計算機視覺等領域的特征提取。

It’d be well beyond the scope of this article to give each algorithm its own in-depth worked example. Suffice to say that this is an active area of research, providing powerful methods to make sense of data that even a generation ago would have been extremely difficult to process.

為每個算法提供自己的深入工作示例將遠遠超出本文的范圍。 可以說這是一個活躍的研究領域,它提供了強大的方法來理解數據,即使是一代人以前也很難處理這些數據。

結論 (Conclusion)

Hopefully this article has informed and inspired you to better understand how machines can make sense of data. The future is a rapidly changing place, and many of those changes will be driven by what technology becomes capable of in the next generation or two.

希望本文能為您提供啟發并啟發您更好地了解機器如何理解數據。 未來是一個瞬息萬變的地方,其中許多變化將取決于下一代技術的能力。

As outlined in the introduction, machine learning is an extraordinarily ambitious field of research, in which massively complex problems require solving in as accurate and as efficient a way possible. Tasks that come naturally to us humans require innovative solutions when taken on by machines.

正如導言中概述的那樣,機器學習是一個非常宏大的研究領域,其中龐大的復雜問題需要以盡可能準確和有效的方式來解決。 對于人類來說,自然而然的任務需要由機器承擔的創新解決方案。

There’s still plenty of progress to be made, and whoever contributes the next breakthrough idea will no doubt be generously rewarded. Maybe someone reading this article will be behind the next powerful algorithm?

仍有大量的進步,無論誰貢獻下一個突破性的想法,無疑都會得到豐厚的回報。 也許有人讀這篇文章會成為下一個強大算法的幕后推手?

All great ideas have to start somewhere!

所有好主意都必須從某個地方開始!

翻譯自: https://www.freecodecamp.org/news/how-machines-make-sense-of-big-data-an-introduction-to-clustering-algorithms-4bd97d4fbaba/

層次聚類算法 算法

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/396007.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/396007.shtml
英文地址,請注明出處:http://en.pswp.cn/news/396007.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

.h .dll .lib

.h為對一個函數的聲明引用,include就是聲明某個文件里的函數(內只有聲明函數被引用了),編譯時使用 .lib為鏈接時用的,存放的是對于DLL里函數的位置信息等,這樣不必把所有dll里函數都加載到內存里&#xff0…

《機器人學經典教程》——2.2 控制論

本節書摘來異步社區《機器人學經典教程》一書中的第2章,第2.2節,作者:【美】Maja J. Matari?(馬婭?馬塔里奇),更多章節內容可以訪問云棲社區“異步社區”公眾號查看。 2.2 控制論 隨著控制理論的不斷發展…

嗶哩嗶哩網站前端源碼_分享一個仿制嗶哩嗶哩鏡子網站源碼

我老婆非常喜歡看嗶哩嗶哩,前些天她興奮地和我說嗶哩嗶哩網站有個隱藏的彩蛋,傳送門http://www.ilidilid.com/,我看了下,相當于把鏡子中的網站樣子弄出來了。于是,我尋思著,把自己的博客也弄個這樣的彩蛋&a…

promise-async-await

通常而言,這3個關鍵字 都是用來「優雅」的處理ajax異步請求的 //es6的時候promise誕生,很好的解決了嵌套回調地獄,改良方案為鏈式回調。// es2017的時候誕生了async、await,這下異步直接沒有回調了,像同步一樣爽//沒有…

第一沖刺階段博客檢查

我們檢查的團隊是:紅鳥 ①團隊博客: 該團隊將所有的站立會議均寫到了4月28日的一篇博客中,并且其中任務看板和燃盡圖不全。 ②團隊成員個人博客: 1>張曉晨: 沒有每天個人工作總結。 2>王曉思: 從4.19…

netcore 編譯 html,Asp.Net Core中的@ Html.Action

小編典典更新:從2.2.2版本開始,HttpContextAccessor將上下文保留在一個對象中(據說是為了防止請求之間的混淆),這會影響當前解決方案…因此,您需要為IHttpContextAccessor(舊版本)提供以下實現并進行注冊作為一個單例:…

《CCIE路由和交換認證考試指南(第5版) (第1卷)》——1.6節虛擬交換系統

本節書摘來自異步社區《CCIE路由和交換認證考試指南(第5版) (第1卷)》一書中的第1章,第1.6節虛擬交換系統,作者 【美】Narbik Kocharians(那比克 科查理安) , 【斯洛伐克】Peter Pal…

機器學習 美股_我如何使用機器學習來探索英美文學之間的差異

機器學習 美股by Sofia Godovykh索非亞戈多維克(Sofia Godovykh) 我如何使用機器學習來探索英美文學之間的差異 (How I used machine learning to explore the differences between British and American literature) As I delved further into English literature to further…

遠程執行漏洞修復方案_請馬上修復!SaltStack遠程命令執行漏洞

【漏洞預警】SaltStack遠程命令執行漏洞(CVE-2020-11651、CVE-2020-11652)2020年5月3日,阿里云應急響應中心監測到近日國外某安全團隊披露了SaltStack存在認證繞過致命令執行漏洞以及目錄遍歷漏洞。漏洞描述SaltStack是基于Python開發的一套C/S架構配置管理工具。國…

kafka部分重要參數配置-broker端參數

broker端參數主要在config/server.properties目錄下設置: 啟動命令:nohup ./kafka-server-start.sh -daemon ../config/server.properties & broker.id參數:Kafka使用唯一的一個整數來標識每個broker,全局唯一,默認…

JS正則表達式大全(整理詳細且實用)

JS正則表達式大全(整理詳細且實用) 作者: 字體:[增加 減小] 類型:轉載 時間:2013-11-14 我要評論 JS正則表達式大全(整理詳細且實用)。需要的朋友可以過來參考下,希望對大家有所幫助正則表達式中的特殊字符 字符 含意…

html設置模塊寬度為200像素,css 寬度(CSS width)

DIV CSS寬度width樣式屬性CSS 寬度是指通過CSS 樣式設置對應div寬度,以下我們了解傳統html寬度、寬度自適應百分比、固定寬度等寬度知識。傳統Html 寬度屬性單詞:width 如width"300";CSS 寬度屬性單詞:width 如width:300px;一、Wid…

我從Stack Overflow對64,000名開發人員的大規模調查中學到的東西

Today Stack Overflow released the results of their 2017 survey of more than 64,000 developers.今天,Stack Overflow發布了他們對64,000多名開發人員的2017年調查結果。 Just like in 2016, I’ve combed through these results and summarized them for you.…

《Node應用程序構建——使用MongoDB和Backbone》一第 1 章 介紹與總覽1.1 打造一個社交網絡...

本節書摘來自異步社區《Node應用程序構建——使用MongoDB和Backbone》一書中的第1章,第1.1節,作者【美】Mike Wilson,更多章節內容可以訪問云棲社區“異步社區”公眾號查看 第 1 章 介紹與總覽 Node應用程序構建——使用MongoDB和Backbone互…

jquery 樣式獲取設置值_jQuery獲取樣式中的背景顏色屬性值/顏色值

天使用jQuery獲取樣式中的background-color的值時發現在獲取到的顏色值在IE中與Chrome、Firefox顯示的格式不一樣,IE中是以HEX格式顯示#ffff00,而Chrome、Firefox中則是以GRB格式顯示rgb(255,0,0),由于需要將顏色值存儲到數據庫中&#xff0c…

計算機專業做產品,非計算機專業如何做產品經理?

《硅谷產品實戰》學習筆記 32課這節課中講了計算機專業背景對產品經理的幫助:第一印象;判斷項目復雜度;了解技術可否實現,有何限制?對于沒有計算機專業背景的產品如何彌補專業不足?關于如何判斷項目復雜度在…

_UICreateCGImageFromIOSurface 使用API

上傳的時候,蘋果發送郵件 Non-public API usage: The app references non-public symbols in DUO-LINK 4: _UICreateCGImageFromIOSurfaceIf method names in your source code match the private Apple APIs listed above, altering your method names will help …

匹配一個字符串的開頭和結尾_我如何構建一個應用程序來展示精彩小說的開頭和結尾

匹配一個字符串的開頭和結尾I know sentences. In my decade as a print journalist, I’ve written hundreds of articles for dozens of publications. I’ve dished out more sentences than Judge Judy. But I didn’t study writing or journalism, at least not formally…

python 社區網絡轉化_python-將numpy打開網格轉換為坐標

方法1使用np.meshgrid,然后堆疊-r,c np.meshgrid(*m)out np.column_stack((r.ravel(F), c.ravel(F) ))方法2或者,使用np.array()然后進行轉置,重塑-np.array(np.meshgrid(*m)).T.reshape(-1,len(m))對于np.ix_中使用的通用數組數目的通用情況,這里是需要進行的修改-p np.r_[…

《思科數據中心I/O整合》一2.11 活動-活動連接(Active-Active)

本節書摘來自異步社區《思科數據中心I/O整合》一書中的第2章,第2.11節,作者【美】Silvano Gai , Claudio DeSanti,更多章節內容可以訪問云棲社區“異步社區”公眾號查看 2.11 活動-活動連接(Active-Active) 思科數據中…