Skip to content

Commit 0464c03

Browse files
committed
add translated for "Analyzing the Graph of Thrones"
1 parent 4c8e700 commit 0464c03

3 files changed

Lines changed: 38 additions & 79 deletions

File tree

‎Python Weekly/Python Weekly Issue 250.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Armin Ronacher是Python软件生态圈的一个多产贡献者,他创造了诸
3030

3131
本文展示了如何使用Plotly和Python,在3D中绘制客户服务指标。
3232

33-
[分析权力游戏图表](http://www.lyonwj.com/2016/06/26/graph-of-thrones-neo4j-social-network-analysis/)
33+
[分析权力游戏图表](http://www.lyonwj.com/2016/06/26/graph-of-thrones-neo4j-social-network-analysis/) | [中文版](../Science and Data Analysis/分析权力游戏图表.md)
3434

3535
[使用Python探索NFL选秀](http://savvastjortjoglou.com/nfl-draft.html)
3636

‎Science and Data Analysis/README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,7 @@
3636
- [Python中一个简单的基于内容的推荐引擎](Python中一个简单的基于内容的推荐引擎.md)
3737

3838
- [在Python中实现你自己的推荐系统](./在Python中实现你自己的推荐系统.md)
39+
40+
- [分析权力游戏图表](./分析权力游戏图表.md)
41+
42+
帅爆了,用科学方法,分析权力游戏中错综复杂的人物关系。本文只实验了第三卷,看过之后,可以用其他卷来重现该实验~
Lines changed: 33 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -304,20 +304,13 @@
304304

305305
## 中介中心性(Betweenness Centrality)
306306

307-
一个网络中的一个节点的[中介中心性(Betweenness Centrality)](https://en.wikipedia.org/wiki/Betweenness_centrality) 是,the number of shortest paths between two other members in the
308-
network on which a given node appears. Betweenness centality is an important
309-
metric because it can be used to identify “brokers of information” in the
310-
network or nodes that connect disparate clusters.
307+
一个网络中的一个节点的[中介中心性(Betweenness Centrality)](https://en.wikipedia.org/wiki/Betweenness_centrality) 是,网络中所有的节点对之间通过该节点的最短路径数。中介中心性是一项重要的指标,因为它可以用于识别网络中的“信息代理”,或者那些连接不同集群的节点。
311308

312-
![](http://www.lyonwj.com/public/img/betweenness-centrality.png) **The red
313-
nodes have a high betweenness centrality and are connectors of clusters.
314-
[Image credit](https://www.linkedin.com/pulse/wtf-do-you-actually-know-who-
315-
influencers-walter-pike)**
309+
![](http://www.lyonwj.com/public/img/betweenness-centrality.png)
316310

317-
To calculate betweenness centrality we will use the new [Awesome Procedures
318-
for Neo4j 3.x or apoc library](https://github.com/neo4j-contrib/neo4j-apoc-
319-
procedures). Once we’ve installed apoc we can call any of the 170+ procedures
320-
from Cypher:
311+
**红色的节点具有较高的中介中心性,并且是集群的连接点。[图片来源](https://www.linkedin.com/pulse/wtf-do-you-actually-know-who-influencers-walter-pike)**
312+
313+
要计算中介中心性,我们将使用新的[用于Neo4j 3.x或apoc库的棒棒哒的程序](https://github.com/neo4j-contrib/neo4j-apoc-procedures). 一旦我们安装了apoc,我们就可以调用Cypher中170+个程序中的任意一个:
321314

322315
```python
323316

@@ -358,16 +351,11 @@ from Cypher:
358351

359352
## 接近中心性(Closeness centrality)
360353

361-
[接近中心性(Closeness centrality)](https://en.wikipedia.org/wiki/Centrality#Closeness_centrality) is
362-
the inverse of the average distance to all other characters in the network.
363-
Nodes with high closeness centality are often highly connected within clusters
364-
in the graph, but not necessarily highly connected outside of the cluster.
354+
[接近中心性(Closeness centrality)](https://en.wikipedia.org/wiki/Centrality#Closeness_centrality)是到网络中所有其他角色的平均距离的倒数。具有高接近中心性的节点通常在图中的集群之间被高度连接,但在集群外部不一定是高度连接的。
365355

366356
![](http://www.lyonwj.com/public/img/closeness-centrality.png)
367357

368-
**Nodes with
369-
high closeness centrality are connected to many other nodes in a network.
370-
[Image credit](https://www.linkedin.com/pulse/wtf-do-you-actually-know-who-influencers-walter-pike)**
358+
**具有高接近中心性的节点连接了网络中许多其他节点。[图片提供](https://www.linkedin.com/pulse/wtf-do-you-actually-know-who-influencers-walter-pike)**
371359

372360
```python
373361

@@ -407,20 +395,11 @@ high closeness centrality are connected to many other nodes in a network.
407395

408396
# 使用python-igraph
409397

410-
One of the things I love about Neo4j is how well it works with other tools,
411-
things like R and Python data science tools. We could continue to use apoc to
412-
run [PageRank](https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_pagerank_algorithm) and [community detection](https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_graph_algorithms) algorithms, but
413-
let’s switch to using [python-igraph](http://igraph.org/python/) to calculate
414-
some analyses. Python-igraph is a port of the R igraph graph analytics
415-
library. To install, just use `pip install python-igraph`.
398+
我爱关于Neo4j的事情之一是,它与其他工具,例如R和Python数据科学工具配合良好。我们可以继续使用apoc来运行[PageRank](https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_pagerank_algorithm)和[社区检测](https://neo4j-contrib.github.io/neo4j-apoc-procedures/#_graph_algorithms)算法,但是,让我们切换到使用[python-igraph](http://igraph.org/python/)来计算一些分析。Python-igraph移植自R的igraph图形分析库。仅需使用`pip install python-igraph`,即可安装它。
416399

417400
### 从Neo4j构建一个igraph实例
418401

419-
To use igraph on our graph of thrones data, the first thing we need to do is
420-
pull data out of Neo4j and build an igraph instnace in Python. We can do this
421-
using [py2neo](http://py2neo.org/), one of the Python drivers for Neo4j. We
422-
can pass the results object of a Py2neo query directly into the `TupleList`
423-
constructor of igraph to create an igraph instance:
402+
要在我们的权利游戏的数据图上使用igraph,所需要做的第一件事是从Neo4j中取出数据,然后在Python中构建一个igraph实例。我们可以使用[py2neo](http://py2neo.org/),用于Neo4j的Python驱动之一,来做到这点。我们可以将一个Py2neo查询的结果对象直接传到igraph的`TupleList`构造函数,以创建一个igraph实例:
424403

425404
```python
426405

@@ -436,24 +415,17 @@ constructor of igraph to create an igraph instance:
436415
ig = IGraph.TupleList(graph.run(query), weights=True)
437416
```
438417

439-
We now have an igraph object that we can use to run any of the graph
440-
algorithms implemented in igraph.
418+
现在,我们有了一个igraph对象,我们可以用它来运行任何igraph中实现的图算法了。
441419

442420
## PageRank
443421

444-
The first algorithm we’ll use in igraph is
445-
[PageRank](https://en.wikipedia.org/wiki/PageRank). PageRank is an algorithm
446-
originally used by Google to rank the importance of web pages and is a type of
447-
[eigenvector centrality](https://en.wikipedia.org/wiki/Centrality#Eigenvector_centrality).
422+
igraph中,我们要使用的第一个算法是[PageRank](https://en.wikipedia.org/wiki/PageRank)。PageRank是一种最初由Google用来对网页重要性进行排序的算法,它是一种[特征向量中心性(eigenvector centrality)](https://en.wikipedia.org/wiki/Centrality#Eigenvector_centrality)算法。
423+
424+
![](http://www.lyonwj.com/public/img/page-rank.png)
448425

449-
![](http://www.lyonwj.com/public/img/page-rank.png) **PageRank: The size of
450-
each node is proportional to the number and size of the other nodes pointing
451-
to it in the network. Image credit
452-
[wikipedia](https://commons.wikimedia.org/w/index.php?curid=2776582) CC-BY**
426+
**PageRank: 每个节点的大小正比于网络中指向它的其他节点的数目和大小。图片来源[wikipedia](https://commons.wikimedia.org/w/index.php?curid=2776582) CC-BY**
453427

454-
Here’s we’ll run Pagerank on our igraph instance, then write the results back
455-
to Neo4j, creating a `pagerank` property on our Character nodes to store the
456-
value we just calculated in igraph:
428+
这里,我们将在我们的igraph实例上运行Pagerank,然后将结果写回到Neo4j,在我们的角色节点上创建一个`pagerank`属性,以存储我们刚刚在igraph中计算的值:
457429

458430
```python
459431

@@ -473,8 +445,7 @@ value we just calculated in igraph:
473445
graph.run(write_clusters_query, nodes=pgvs)
474446
```
475447

476-
We can now query our graph in Neo4j to find the nodes with the highest
477-
PageRank score:
448+
现在,我们可以查询在Neo4j中的图,以找到具有最高PageRank得分的节点:
478449

479450
```python
480451

@@ -510,18 +481,15 @@ PageRank score:
510481

511482
```
512483

513-
### Community detection
484+
### 社区检测
514485

515-
![](http://www.lyonwj.com/public/img/community-1.png) **[Image credit](http://digitalinterface.blogspot.com/2013/05/community-detection-in-graphs.html)**
486+
![](http://www.lyonwj.com/public/img/community-1.png)
516487

517-
Community detection algorithms are used to find clusters in the graph. We’ll
518-
use the [walktrap method](http://arxiv.org/abs/physics/0512106) as implemented
519-
in igraph to find communities of characters that frequently interact within
520-
the community, but not much interaction occurs outside of the community.
488+
**[图片来源](http://digitalinterface.blogspot.com/2013/05/community-detection-in-graphs.html)**
521489

522-
We’ll run the walktrap community detection algorithm and then write the newly
523-
discovered community numbers back to Neo4j, with the community each Character
524-
belongs to represented by an integer:
490+
社区检测算法用以查找图中的集群。我们将使用igraph中实现的[walktrap方法](http://arxiv.org/abs/physics/0512106),来找到那些在社区之中频繁交互,但在社区之外不存在太多互动的角色的社区。
491+
492+
我们将运行walktrap社区检测算法,然后将新发现的社区数写回到Neo4j,其中,每个角色所属的社区用一个整数来表示:
525493

526494
```python
527495

@@ -541,8 +509,7 @@ belongs to represented by an integer:
541509
graph.run(write_clusters_query, nodes=nodes)
542510
```
543511

544-
We can then query Neo4j to see how many communities (or clusters) we ended up
545-
with and the members of each community:
512+
然后,我们可以查询Neo4j,看看最后我们有多少个社区(或者集群),以及每个社区中的成员:
546513

547514
```python
548515

@@ -584,25 +551,13 @@ with and the members of each community:
584551

585552
## 可视化 - 把它们放在一起
586553

587-
![](http://www.lyonwj.com/public/img/graph-of-thrones.png) **The graph of
588-
thrones. Node size is proportional to betweenness centrality, colors indicate
589-
the cluster of the node as determined by the walktrap method, and the edge
590-
thickness is proprtional to the number of interactions between two
591-
characters.**
554+
![](http://www.lyonwj.com/public/img/graph-of-thrones.png)
555+
556+
**权利的游戏之图。节点大小正比于中介中心性,颜色表示节点集群,由walktrap方法测定,而边缘厚度正比于两个角色之间的互动数。**
592557

593-
Now that we’ve computed these analytics for the graph, let’s create a
594-
visualization that allows us to make sense of the data.
558+
现在,我们已经计算出了该图的这些分析项,让我们创建一个可视化,使我们能够让这些数据有意义。
595559

596-
The Neo4j Browser is great for visualizing the results of Cypher queries, but
597-
if we want to embed our graph visualizations in another application we might
598-
want to use one of the many great Javascript libraries for graph
599-
visualizations. [Vis.js](http://visjs.org/) is one such library that allows
600-
for building interactive graph visualizations. To make the process of pulling
601-
data from Neo4j and building graph visualizations with vis.js I’ve been
602-
working on [neovis.js](https://github.com/johnymontana/neovis.js), which
603-
combines vis.js and the [Neo4j official Javascript driver](http://www.lyonwj.com/2016/06/26/graph-of-thrones-neo4j-social-network-analysis/). Neovis.js provides a simple API that allows for
604-
configuring the visualization. For example, the following Javascript is all
605-
that is necessary to produce the visualization above:
560+
Neo4j浏览器对于可视化Cypher查询的结果是棒棒哒,但如果我们想要在另一个应用中嵌入我们的图形可视化,我们可能需要使用许多用于图形可视化的伟大的Javascript库中的一个。[Vis.js](http://visjs.org/)就是这样的一个库,它允许我们构建互动式图形可视化。要进行从Neo4j抽取数据,并使用vis.js构建图形可视化的过程,我一直使用[neovis.js](https://github.com/johnymontana/neovis.js),它将vis.js和[Neo4j官方Javascript驱动](http://www.lyonwj.com/2016/06/26/graph-of-thrones-neo4j-social-network-analysis/)组合在一起。Neovis.js提供了一个简单的API,允许配置可视化。例如,下面的Javascript是生成上面的可视化所需的:
606561

607562
```python
608563

@@ -633,12 +588,12 @@ that is necessary to produce the visualization above:
633588
请注意,我们已经指定:
634589

635590
* 在可视化中,我们想要包含带标签`Character`的节点,使用合适的`name`作为其标题
636-
* Node size should be proportional to the value of their `betweenness` property
591+
* 节点大小应该正比于它们的`betweenness`属性
637592
* 在可视化中,我们想要包含`INTERACTS`关系
638-
* The thickness of the relationships should be proportional to the value of the `weight` property
639-
* The nodes should be colored according to the value of the propety `community` which identifies the clusters in the network
640-
* To pull the data from a Neo4j server on `localhost`
641-
* To display the visualization in a DOM element with the id `viz`
593+
* 关系的厚度应该正比于`weight`属性值
594+
* 节点应该根据`community`属性值来着色,该属性标识网络中的集群
595+
* 从`localhost`上的一个Neo4j服务器中抽取数据
596+
* 在一个id为`viz`的DOM元素中展示可视化
642597

643598
Neovis.js需要从Neo4j拉取数据,并且基于我们的最低配置创建可视化。
644599

0 commit comments

Comments
 (0)