|
554 | 554 | "print(result)" |
555 | 555 | ] |
556 | 556 | }, |
| 557 | + { |
| 558 | + "cell_type": "markdown", |
| 559 | + "metadata": {}, |
| 560 | + "source": [ |
| 561 | + "### Betweenness Centrality\n", |
| 562 | + "\n", |
| 563 | + "[Betweenness Centrality](https://neo4j.com/docs/graph-data-science/current/algorithms/betweenness-centrality/) quantifies the importance of a node as a bridge or intermediary in the network. It measures how often a node lies on the shortest path between other pairs of nodes. \n", |
| 564 | + "\n", |
| 565 | + "For our dataset, cities/airports with high betweenness centrality serve as crucial transfer points or connecting hubs between airports that might not have direct flights between them. They play a significant role in facilitating the flow of air travel and can be vital for overall network connectivity." |
| 566 | + ] |
| 567 | + }, |
557 | 568 | { |
558 | 569 | "cell_type": "code", |
559 | | - "execution_count": null, |
| 570 | + "execution_count": 14, |
560 | 571 | "metadata": {}, |
561 | | - "outputs": [], |
562 | | - "source": [] |
| 572 | + "outputs": [ |
| 573 | + { |
| 574 | + "name": "stderr", |
| 575 | + "output_type": "stream", |
| 576 | + "text": [ |
| 577 | + "Failed to write data to connection IPv4Address(('3.235.129.183', 7687)) (ResolvedIPv4Address(('3.235.129.183', 7687)))\n", |
| 578 | + "Failed to write data to connection IPv4Address(('3.235.129.183', 7687)) (ResolvedIPv4Address(('3.235.129.183', 7687)))\n", |
| 579 | + "BetweennessCentrality: 100%|██████████| 100.0/100 [00:04<00:00, 22.62%/s]\n" |
| 580 | + ] |
| 581 | + } |
| 582 | + ], |
| 583 | + "source": [ |
| 584 | + "betweenness_centrality_result = gds.betweenness.mutate(G, mutateProperty=\"betweennessCentrality\")" |
| 585 | + ] |
| 586 | + }, |
| 587 | + { |
| 588 | + "cell_type": "code", |
| 589 | + "execution_count": 15, |
| 590 | + "metadata": {}, |
| 591 | + "outputs": [ |
| 592 | + { |
| 593 | + "data": { |
| 594 | + "text/plain": [ |
| 595 | + "City [betweennessCentrality, eigenvectorCentrality]\n", |
| 596 | + "dtype: object" |
| 597 | + ] |
| 598 | + }, |
| 599 | + "execution_count": 15, |
| 600 | + "metadata": {}, |
| 601 | + "output_type": "execute_result" |
| 602 | + } |
| 603 | + ], |
| 604 | + "source": [ |
| 605 | + "# We can verify that the betweennessCentrality was mutated\n", |
| 606 | + "G.node_properties()" |
| 607 | + ] |
| 608 | + }, |
| 609 | + { |
| 610 | + "cell_type": "markdown", |
| 611 | + "metadata": {}, |
| 612 | + "source": [ |
| 613 | + "We can also see the distribution of the betweenness centrality measures using the below code. This will show us the minimum, maximum, mean and other statistical values for our centrality measure." |
| 614 | + ] |
| 615 | + }, |
| 616 | + { |
| 617 | + "cell_type": "code", |
| 618 | + "execution_count": 16, |
| 619 | + "metadata": {}, |
| 620 | + "outputs": [ |
| 621 | + { |
| 622 | + "data": { |
| 623 | + "text/plain": [ |
| 624 | + "{'p99': 3265.2968747615814,\n", |
| 625 | + " 'min': 0.04446244239807129,\n", |
| 626 | + " 'max': 3628.7656247615814,\n", |
| 627 | + " 'mean': 298.0898581821668,\n", |
| 628 | + " 'p90': 1006.8867185115814,\n", |
| 629 | + " 'p50': 21.20861792564392,\n", |
| 630 | + " 'p999': 3628.7656247615814,\n", |
| 631 | + " 'p95': 1823.7578122615814,\n", |
| 632 | + " 'p75': 184.29199194908142}" |
| 633 | + ] |
| 634 | + }, |
| 635 | + "execution_count": 16, |
| 636 | + "metadata": {}, |
| 637 | + "output_type": "execute_result" |
| 638 | + } |
| 639 | + ], |
| 640 | + "source": [ |
| 641 | + "betweenness_centrality_result.centralityDistribution" |
| 642 | + ] |
| 643 | + }, |
| 644 | + { |
| 645 | + "cell_type": "code", |
| 646 | + "execution_count": 17, |
| 647 | + "metadata": {}, |
| 648 | + "outputs": [ |
| 649 | + { |
| 650 | + "data": { |
| 651 | + "text/plain": [ |
| 652 | + "writeMillis 95\n", |
| 653 | + "graphName airline\n", |
| 654 | + "nodeProperties [betweennessCentrality]\n", |
| 655 | + "propertiesWritten 456\n", |
| 656 | + "Name: 0, dtype: object" |
| 657 | + ] |
| 658 | + }, |
| 659 | + "execution_count": 17, |
| 660 | + "metadata": {}, |
| 661 | + "output_type": "execute_result" |
| 662 | + } |
| 663 | + ], |
| 664 | + "source": [ |
| 665 | + "gds.graph.nodeProperties.write(G, [\"betweennessCentrality\"])" |
| 666 | + ] |
| 667 | + }, |
| 668 | + { |
| 669 | + "cell_type": "markdown", |
| 670 | + "metadata": {}, |
| 671 | + "source": [ |
| 672 | + "Using the results from betweenness centrality, we can now look up the top 20 cities with airports that serve as crucial transfer points or connecting hubs between airports that might not have direct flights between them." |
| 673 | + ] |
| 674 | + }, |
| 675 | + { |
| 676 | + "cell_type": "code", |
| 677 | + "execution_count": 18, |
| 678 | + "metadata": {}, |
| 679 | + "outputs": [ |
| 680 | + { |
| 681 | + "name": "stdout", |
| 682 | + "output_type": "stream", |
| 683 | + "text": [ |
| 684 | + " node_id name population betweennessCentrality\n", |
| 685 | + "0 246 Los Angeles, CA 12940000.0 3628.755650\n", |
| 686 | + "1 100 Denver, CO 2600000.0 3435.693657\n", |
| 687 | + "2 294 New York, NY 19020000.0 3297.750685\n", |
| 688 | + "3 416 Toronto, ON 6324000.0 3295.316691\n", |
| 689 | + "4 368 San Francisco, CA 4391000.0 3265.288064\n", |
| 690 | + "5 74 Chicago, IL 9505000.0 3250.731388\n", |
| 691 | + "6 230 Las Vegas, NV 1970000.0 3156.983626\n", |
| 692 | + "7 434 Washington, DC 5704000.0 3108.796793\n", |
| 693 | + "8 94 Dallas/Fort Worth, TX 6527000.0 3094.760797\n", |
| 694 | + "9 324 Phoenix, AZ 4263000.0 2815.294080\n", |
| 695 | + "10 383 Seattle/Tacoma, WA 3500000.0 2600.388338\n", |
| 696 | + "11 269 Minneapolis/St Paul, MN 3318000.0 2386.544069\n", |
| 697 | + "12 367 San Diego, CA 3140000.0 2225.911712\n", |
| 698 | + "13 178 Houston, TX 6087000.0 2206.757554\n", |
| 699 | + "14 308 Orlando, FL 2171000.0 2205.127484\n", |
| 700 | + "15 46 Boston, MA 4591000.0 2192.597357\n", |
| 701 | + "16 331 Portland, OR 2263000.0 2098.582191\n", |
| 702 | + "17 136 Ft. Lauderdale, FL 5670000.0 2047.102205\n", |
| 703 | + "18 323 Philadelphia, PA 5992000.0 2038.406177\n", |
| 704 | + "19 402 St. Louis, MO 2817000.0 1961.619874\n" |
| 705 | + ] |
| 706 | + } |
| 707 | + ], |
| 708 | + "source": [ |
| 709 | + "# Execute the Cypher query to retrieve the top 20 cities with betweenness centrality\n", |
| 710 | + "query = \"\"\"\n", |
| 711 | + "MATCH (n:City)\n", |
| 712 | + "RETURN n.node_id AS node_id, n.name AS name, n.population AS population, n.betweennessCentrality AS betweennessCentrality\n", |
| 713 | + "ORDER BY n.betweennessCentrality DESC\n", |
| 714 | + "LIMIT 20\n", |
| 715 | + "\"\"\"\n", |
| 716 | + "result = gds.run_cypher(query)\n", |
| 717 | + "\n", |
| 718 | + "# Display the result\n", |
| 719 | + "print(result)" |
| 720 | + ] |
563 | 721 | }, |
564 | 722 | { |
565 | 723 | "cell_type": "code", |
566 | 724 | "execution_count": null, |
567 | 725 | "metadata": {}, |
568 | 726 | "outputs": [], |
569 | | - "source": [] |
| 727 | + "source": [ |
| 728 | + "### Betweenness Centrality\n", |
| 729 | + "\n", |
| 730 | + "[Betweenness Centrality](https://neo4j.com/docs/graph-data-science/current/algorithms/betweenness-centrality/) quantifies the importance of a node as a bridge or intermediary in the network. It measures how often a node lies on the shortest path between other pairs of nodes. \n", |
| 731 | + "\n", |
| 732 | + "For our dataset, cities/airports with high betweenness centrality serve as crucial transfer points or connecting hubs between airports that might not have direct flights between them. They play a significant role in facilitating the flow of air travel and can be vital for overall network connectivity." |
| 733 | + ] |
570 | 734 | }, |
571 | 735 | { |
572 | 736 | "cell_type": "markdown", |
|
0 commit comments