Skip to content

Commit 9991e3e

Browse files
kedarghuleMats-SX
authored andcommitted
Started centrality algos notebook
1 parent f94a622 commit 9991e3e

File tree

1 file changed

+227
-0
lines changed

1 file changed

+227
-0
lines changed
Lines changed: 227 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,227 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Centrality Algorithms"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"<a target=\"_blank\" href=\"https://colab.research.google.com/github/neo4j/graph-data-science-client/blob/main/examples/centrality-algorithms.ipynb\">\n",
15+
" <img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/>\n",
16+
"</a>"
17+
]
18+
},
19+
{
20+
"cell_type": "markdown",
21+
"metadata": {},
22+
"source": [
23+
"This Jupyter notebook is hosted [here](https://github.com/neo4j/graph-data-science-client/blob/main/examples/centrality-algorithms.ipynb) in the Neo4j Graph Data Science Client Github repository.\n",
24+
"\n",
25+
"Centrality algorithms are used to understand the role or influence of particular nodes in a graph. The notebook shows the application of centrality algorithms using the `graphdatascience` library on the Airline travel reachability network dataset that can be downloaded [here](https://snap.stanford.edu/data/reachability.html).\n",
26+
"\n",
27+
"< TALK ABOUT TASKS >\n",
28+
"\n",
29+
"### Setup\n",
30+
"\n",
31+
"We start by importing our dependencies and setting up our GDS client connection to the database."
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": 2,
37+
"metadata": {},
38+
"outputs": [],
39+
"source": [
40+
"# Install necessary dependencies\n",
41+
"#%pip install graphdatascience pandas"
42+
]
43+
},
44+
{
45+
"cell_type": "code",
46+
"execution_count": 3,
47+
"metadata": {},
48+
"outputs": [
49+
{
50+
"name": "stderr",
51+
"output_type": "stream",
52+
"text": [
53+
"C:\\Users\\kedar\\anaconda3\\envs\\graph_stuff\\lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
54+
" from .autonotebook import tqdm as notebook_tqdm\n"
55+
]
56+
}
57+
],
58+
"source": [
59+
"from graphdatascience import GraphDataScience\n",
60+
"import pandas as pd\n",
61+
"import os"
62+
]
63+
},
64+
{
65+
"cell_type": "code",
66+
"execution_count": null,
67+
"metadata": {},
68+
"outputs": [],
69+
"source": [
70+
"# NEO4J_URI = os.environ.get(\"NEO4J_URI\", \"bolt://localhost:7687\")\n",
71+
"# NEO4J_AUTH = None\n",
72+
"# if os.environ.get(\"NEO4J_USER\") and os.environ.get(\"NEO4J_PASSWORD\"):\n",
73+
"# NEO4J_AUTH = (\n",
74+
"# os.environ.get(\"NEO4J_USER\"),\n",
75+
"# os.environ.get(\"NEO4J_PASSWORD\"),\n",
76+
"# )\n",
77+
"\n",
78+
"# gds = GraphDataScience(NEO4J_URI, auth=NEO4J_AUTH)\n",
79+
"\n",
80+
"# # Replace with the actual connection URI and credentials\n",
81+
"NEO4J_CONNECTION_URI = \"bolt://XXXXXXXXXXXXX\n",
82+
"NEO4J_USERNAME = \"neo4j\"\n",
83+
"NEO4J_PASSWORD = \"XXXXXXXXXXXXX\"\n",
84+
"\n",
85+
"# Client instantiation\n",
86+
"gds = GraphDataScience(\n",
87+
" NEO4J_CONNECTION_URI,\n",
88+
" auth=(NEO4J_USERNAME, NEO4J_PASSWORD)\n",
89+
")\n"
90+
]
91+
},
92+
{
93+
"cell_type": "markdown",
94+
"metadata": {},
95+
"source": [
96+
"### Importing the dataset\n",
97+
"\n",
98+
"We import the dataset as a pandas dataframe first. "
99+
]
100+
},
101+
{
102+
"cell_type": "code",
103+
"execution_count": 6,
104+
"metadata": {},
105+
"outputs": [
106+
{
107+
"data": {
108+
"text/html": [
109+
"<div>\n",
110+
"<style scoped>\n",
111+
" .dataframe tbody tr th:only-of-type {\n",
112+
" vertical-align: middle;\n",
113+
" }\n",
114+
"\n",
115+
" .dataframe tbody tr th {\n",
116+
" vertical-align: top;\n",
117+
" }\n",
118+
"\n",
119+
" .dataframe thead th {\n",
120+
" text-align: right;\n",
121+
" }\n",
122+
"</style>\n",
123+
"<table border=\"1\" class=\"dataframe\">\n",
124+
" <thead>\n",
125+
" <tr style=\"text-align: right;\">\n",
126+
" <th></th>\n",
127+
" <th>node_id</th>\n",
128+
" <th>name</th>\n",
129+
" <th>metro_pop</th>\n",
130+
" <th>latitude</th>\n",
131+
" <th>longitude</th>\n",
132+
" </tr>\n",
133+
" </thead>\n",
134+
" <tbody>\n",
135+
" <tr>\n",
136+
" <th>0</th>\n",
137+
" <td>0</td>\n",
138+
" <td>Abbotsford, BC</td>\n",
139+
" <td>133497.0</td>\n",
140+
" <td>49.051575</td>\n",
141+
" <td>-122.328849</td>\n",
142+
" </tr>\n",
143+
" <tr>\n",
144+
" <th>1</th>\n",
145+
" <td>1</td>\n",
146+
" <td>Aberdeen, SD</td>\n",
147+
" <td>40878.0</td>\n",
148+
" <td>45.459090</td>\n",
149+
" <td>-98.487324</td>\n",
150+
" </tr>\n",
151+
" <tr>\n",
152+
" <th>2</th>\n",
153+
" <td>2</td>\n",
154+
" <td>Abilene, TX</td>\n",
155+
" <td>166416.0</td>\n",
156+
" <td>32.449175</td>\n",
157+
" <td>-99.741424</td>\n",
158+
" </tr>\n",
159+
" <tr>\n",
160+
" <th>3</th>\n",
161+
" <td>3</td>\n",
162+
" <td>Akron/Canton, OH</td>\n",
163+
" <td>701456.0</td>\n",
164+
" <td>40.797810</td>\n",
165+
" <td>-81.371567</td>\n",
166+
" </tr>\n",
167+
" <tr>\n",
168+
" <th>4</th>\n",
169+
" <td>4</td>\n",
170+
" <td>Alamosa, CO</td>\n",
171+
" <td>9433.0</td>\n",
172+
" <td>37.468180</td>\n",
173+
" <td>-105.873599</td>\n",
174+
" </tr>\n",
175+
" </tbody>\n",
176+
"</table>\n",
177+
"</div>"
178+
],
179+
"text/plain": [
180+
" node_id name metro_pop latitude longitude\n",
181+
"0 0 Abbotsford, BC 133497.0 49.051575 -122.328849\n",
182+
"1 1 Aberdeen, SD 40878.0 45.459090 -98.487324\n",
183+
"2 2 Abilene, TX 166416.0 32.449175 -99.741424\n",
184+
"3 3 Akron/Canton, OH 701456.0 40.797810 -81.371567\n",
185+
"4 4 Alamosa, CO 9433.0 37.468180 -105.873599"
186+
]
187+
},
188+
"execution_count": 6,
189+
"metadata": {},
190+
"output_type": "execute_result"
191+
}
192+
],
193+
"source": [
194+
"df = pd.read_csv('https://snap.stanford.edu/data/reachability-meta.csv.gz', compression='gzip')\n",
195+
"df.head()"
196+
]
197+
},
198+
{
199+
"cell_type": "code",
200+
"execution_count": null,
201+
"metadata": {},
202+
"outputs": [],
203+
"source": []
204+
}
205+
],
206+
"metadata": {
207+
"kernelspec": {
208+
"display_name": "Python 3 (ipykernel)",
209+
"language": "python",
210+
"name": "python3"
211+
},
212+
"language_info": {
213+
"codemirror_mode": {
214+
"name": "ipython",
215+
"version": 3
216+
},
217+
"file_extension": ".py",
218+
"mimetype": "text/x-python",
219+
"name": "python",
220+
"nbconvert_exporter": "python",
221+
"pygments_lexer": "ipython3",
222+
"version": "3.10.11"
223+
}
224+
},
225+
"nbformat": 4,
226+
"nbformat_minor": 2
227+
}

0 commit comments

Comments
 (0)