<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yusuf Baktir, Ph.D. on Medium]]></title>
        <description><![CDATA[Stories by Yusuf Baktir, Ph.D. on Medium]]></description>
        <link>https://medium.com/@baktiryusuf?source=rss-647ee0e897b9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xKF7eMmkPCUcIGsqv8qOmg.png</url>
            <title>Stories by Yusuf Baktir, Ph.D. on Medium</title>
            <link>https://medium.com/@baktiryusuf?source=rss-647ee0e897b9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 20:26:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@baktiryusuf/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[nxneo4j: NetworkX-API for Neo4j — A new chapter]]></title>
            <link>https://medium.com/neo4j/nxneo4j-networkx-api-for-neo4j-a-new-chapter-9fc65ddab222?source=rss-647ee0e897b9------2</link>
            <guid isPermaLink="false">https://medium.com/p/9fc65ddab222</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[graph]]></category>
            <category><![CDATA[networkx]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[neo4j]]></category>
            <dc:creator><![CDATA[Yusuf Baktir, Ph.D.]]></dc:creator>
            <pubDate>Wed, 02 Sep 2020 20:00:07 GMT</pubDate>
            <atom:updated>2020-09-02T20:00:07.895Z</atom:updated>
            <content:encoded><![CDATA[<h3>nxneo4j: NetworkX-API for Neo4j — A new chapter</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MAYvQkafAsbLpBeWA2wVwg.jpeg" /><figcaption>Photo: <a href="https://unsplash.com/photos/BW0vK-FA3eg">Clint Adair</a></figcaption></figure><p>Recently, I have had the opportunity to work with nxneo4j and I am excited to share it with the world!</p><h3>What is nxneo4j?</h3><p>nxneo4j is a python library that enables you to use networkX type of commands to interact with Neo4j.</p><p>Neo4j is the most common graph database. NetworkX is the most commonly used graph library. Combining the two brings us the nxneo4j!</p><p>Neo4j has the following advantages:</p><ul><li>Neo4j is a database which means it persists the data. You can create the data once and run graph algorithms as many times as you want. In networkX, you need to construct the graph every time you want to run it.</li><li>Neo4j graph algorithms are scalable and production-ready. Neo4j algorithms are written in Java and performance tested. NetworkX is a single node implementation of a graph written in Python.</li><li>The response time is much faster in Neo4j.</li><li>Neo4j supports graph embeddings in the form of Node Embeddings, Random Projections, and Graph Sage. These are not available in nxneo4j yet but it will be available in the future versions.</li></ul><p>So, why not use Neo4j?</p><p>nxneo4j is designed to help users interact with Neo4j quickly and easily. It uses the famous networkX API. You will use your well-accustomed scripts and but the scripts will run against Neo4j. Cool!</p><blockquote>Just to be clear, Mark Needham had already created the nxneo4j and you might have used it in the past. This version updates the entire library for Neo4j 4.x and new Graph Data Science library since the older Graph Algoritm library is not supported with Neo4j 4.x. More importantly, it significantly improves the core functionality with property support, node and edge views, remove node features etc. So, this is more a like “A new chapter” or “Welcome back” for the library and it will have continuous support.</blockquote><p>If you are like me and prefer Jupyter Notebooks instead, here is the link:</p><p><a href="https://github.com/ybaktir/networkx-neo4j/blob/master/examples/nxneo4j_tutorial_latest.ipynb">https://github.com/ybaktir/networkx-neo4j/blob/master/examples/nxneo4j_tutorial_latest.ipynb</a></p><h3>Prerequisite 1: Neo4j itself</h3><p>You need to have an active Neo4j 4.x running. Make sure you have Neo4j 4 and above. You have four options here:</p><ol><li>Neo4j Desktop: It is a free desktop application that runs locally on your computer. It is super easy to install. Follow the instructions on this page: <a href="https://neo4j.com/download/">https://neo4j.com/download/</a></li><li>Neo4j Sandbox: This is a free temporary Neo4j instance and it is the fastest way to get started with Neo4j. So fast that, you can have your Neo4j instance running under 60 seconds. Just use the following link: <a href="https://neo4j.com/sandbox/">https://neo4j.com/sandbox/</a></li><li>Neo4j Aura: This a pay-as-go cloud service. You can start as low as $0.09/hour. This is most suitable for long term projects where you don’t have to worry about the infrastructure. In case you want to give it a try: <a href="https://neo4j.com/aura/">https://neo4j.com/aura/</a></li><li>Your enterprise Neo4j instance. You know it when you have it. Otherwise, you can ask your architect to run an instance for you. Be careful during the experimentation.</li></ol><h3>Prerequisite 2: APOC and GDS plugins</h3><p>In Neo4j Desktop, you can easily install them like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ueZT-zGoEanJGhgCloykfQ.jpeg" /><figcaption>Image by the Author</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bJ3O1ERv7DsuZZ8c2oE4-Q.jpeg" /><figcaption>Image by the Author</figcaption></figure><p>The libraries come pre-installed in the Sandbox and Aura.</p><h3>Connect to Neo4j</h3><p>No matter which option you choose, you need to connect to the Neo4j. The library to use is “neo4j”</p><pre>pip install neo4j</pre><p>Then, connect to the Neo4j instance.</p><pre>from neo4j import GraphDatabase</pre><pre>uri      = &quot;bolt://localhost&quot; # in Neo4j Desktop<br>                              # custom URL for Sandbox or Aura<br>user     = &quot;neo4j&quot;            # your user name <br>                              # default is always &quot;neo4j&quot; <br>                              # unless you have changed it. <br>password = your_neo4j_password</pre><pre>driver = GraphDatabase.driver(uri=uri,auth=(uri,password))</pre><p>If everything went smoothly so far, you are ready to use nxneo4j!</p><h3>nxneo4j</h3><p>To get the most up to date version, install it directly from the Github page.</p><pre><a href="https://github.com/ybaktir/networkx-neo4j">pip install git+https://github.com/ybaktir/networkx-neo4j</a></pre><blockquote>This will install nxneo4j 0.0.3. The version 0.0.2 is available on pypi but it is not stable. 0.0.3 will be published on pypi soon. Until then, please use the above link.</blockquote><p>Then create the Graph instance:</p><pre>import nxneo4j as nx</pre><pre>G = nx.Graph(driver)   # undirected graph<br>G = nx.DiGraph(driver) # directed graph</pre><p>Let’s add some data:</p><pre>G.add_node(1)                   #single node</pre><pre>G.add_nodes_from([2,3,4])       #multiple nodes</pre><pre>G.add_edge(1,2)                 #single edge</pre><pre>G.add_edges_from([(2,3),(3,4)]) #multiple edges</pre><p>Check nodes and edges:</p><pre>&gt;&gt;&gt; list(G.nodes())<br>[1, 2, 3, 4]</pre><pre>&gt;&gt;&gt; list(G.edges())<br>[(1, 2), (2, 3), (3, 4)]</pre><p>To add nodes and edges with features:</p><pre>G.add_node(&#39;Mike&#39;,gender=&#39;M&#39;,age=17)<br>G.add_edge(&#39;Mike&#39;,&#39;Jenny&#39;,type=&#39;friends&#39;,weight=3)</pre><p>Check individual nodes data:</p><pre>&gt;&gt;&gt; G.nodes[‘Mike’]<br>{&#39;gender&#39;: &#39;M&#39;, &#39;age&#39;: 17}</pre><pre>&gt;&gt;&gt; G.nodes[&#39;Mike&#39;][&#39;gender&#39;]<br>&#39;M&#39;</pre><p>Check all nodes and edges data:</p><pre>&gt;&gt;&gt; list(G.nodes(data=True))<br>[(1, {}),<br> (2, {}),<br> (3, {}),<br> (4, {}),<br> (&#39;Mike&#39;, {&#39;gender&#39;: &#39;M&#39;, &#39;age&#39;: 17}),<br> (&#39;Jenny&#39;, {})]</pre><pre>&gt;&gt;&gt; list(G.edges(data=True))<br>[(1, 2, {}),<br> (2, 3, {}),<br> (3, 4, {}),<br> (&#39;Mike&#39;, &#39;Jenny&#39;, {&#39;type&#39;: &#39;friends&#39;, &#39;weight&#39;: 3})]</pre><p>Visualize with like the following:</p><pre>&gt;&gt;&gt; nx.draw(G)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TfnaPqPOr9dm8JiPzwztTQ.png" /><figcaption>Image by the Author</figcaption></figure><p>To delete all the data</p><pre>G.delete_all()</pre><h3>Config file</h3><p>Neo4j has some additional requirements for data storage. In Neo4j, the relationships have to have a relationship label. The labels of the nodes are highly recommended. Since the NetworkX syntax has no room for label modification, we store this knowledge in the “config” file.</p><p>The config file is a python dictionary, and the default config file has the following statements:</p><pre>{<br>&#39;node_label&#39;: &#39;Node&#39;,<br>&#39;relationship_type&#39;: &#39;CONNECTED&#39;,<br>&#39;identifier_property&#39;: &#39;id&#39;<br>}</pre><p>You can easily change this dictionary and create an instance with new modifications. For example:</p><pre>config = {<br>&#39;node_label&#39;: &#39;Person&#39;,<br>&#39;relationship_type&#39;: &#39;LOVES&#39;,<br>&#39;identifier_property&#39;: &#39;name&#39;<br>}</pre><pre>G = nx.Graph(driver, config=config)</pre><p>You can also change the default values after the instance creation:</p><pre>G.direction = &#39;UNDIRECTED&#39; #for Undirected Graph<br>G.direction = &#39;NATURAL&#39;    #for Directed Graph</pre><pre>G.identifier_property = ‘name’<br>G.relationship_type = ‘LOVES’<br>G.node_label = ‘Person’</pre><p>To check the config file:</p><pre>&gt;&gt;&gt; G.base_params()<br>{&#39;direction&#39;: &#39;NATURAL&#39;,<br> &#39;node_label&#39;: &#39;Person&#39;,<br> &#39;relationship_type&#39;: &#39;LOVES&#39;,<br> &#39;identifier_property&#39;: &#39;name&#39;}</pre><h3>Built-in Data Sets</h3><p>nxneo4j has 3 built-in datasets:</p><ul><li>Game of Thrones</li><li>Twitter</li><li>Europe Road</li></ul><p><strong>1.Game of Thrones data</strong></p><p>Created by <a href="https://networkofthrones.wordpress.com/">Andrew Beveridge</a>, the data set contains the interactions between the characters across the first 7 seasons of the popular TV show.</p><p>There are 796 nodes and 3,796 relationships.</p><p>All nodes are the TV characters labeled “Character”. The relationship types are “INTERACTS1”, “INTERACTS2”, “INTERACTS3” and “INTERACTS45”</p><p>The only node property is “name”</p><p>The relationship properties are “book” and “weight”.</p><p>You can load it with the following command:</p><pre>G.load_got()</pre><p><strong>2. Europe Roads</strong></p><p>Created by <a href="http://lassewesth.blogspot.com/2018/07/the-international-e-road-network-and.html">Lasse Westh-Nielsen</a>, the data set contains the European cities and the distances between them.</p><p>There are 894 nodes and 2,499 relationships.</p><p>All nodes are labeled “Place” and the relationships types are all “EROAD”</p><p>Node properties are “name” and “countryCode”</p><p>Relationship properties are “distance”, “road_number” and “watercrossing”.</p><p>You can load the data with the following code:</p><pre>G.load_euroads()</pre><p><strong>3. Twitter</strong></p><p>Created by <a href="https://markhneedham.com/blog/">Mark Needham</a>, the data contains Twitter followers of the graph community.</p><p>There are 6526 nodes and 177,708 relationships.</p><p>All node labels are “User” and all relationship types are “FOLLOWS”</p><p>Node properties are “name”, “followers”, “bio”, “id”, “username”, “following”. Relationships don’t have any property. To get the data, run:</p><pre>G.load_twitter() </pre><h3><strong>Graph Data Science</strong></h3><p>It is algorithm time!</p><p>There are at least 47 builtin graph algorithms in Neo4j. nxneo4j will expand to cover all of them in the future versions. For now, the following networkX algorithms are supported:</p><ul><li>pagerank</li><li>betweenness_centrality</li><li>closeness_centrality</li><li>label_propagation</li><li>connected_components</li><li>clustering</li><li>triangles</li><li>shortest_path</li><li>shortest_weighted_path</li></ul><p>Let’s clear the data and load Game of Thrones data set:</p><pre>G.delete_all()<br>G.load_got()</pre><p>Visual inspection:</p><pre>nx.draw(G) # You can zoom in and interact with the nodes<br>           # when running on Jupyter Notebook</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YI-_E3qyHaYLAmmoTUNjXg.png" /><figcaption>Image by the Author</figcaption></figure><ol><li><strong>Centrality Algorithms:</strong></li></ol><p>Centrality algorithms help us understand the individual importance of each node.</p><pre>&gt;&gt;&gt; nx.pagerank(G)<br>{&#39;Addam-Marbrand&#39;: 0.3433842763728652,<br> &#39;Aegon-Frey-(son-of-Stevron)&#39;: 0.15000000000000002,<br> &#39;Aegon-I-Targaryen&#39;: 0.3708563211936468,<br> &#39;Aegon-Targaryen-(son-of-Rhaegar)&#39;: 0.15000000000000002,<br> &#39;Aegon-V-Targaryen&#39;: 0.15000000000000002,<br> &#39;Aemon-Targaryen-(Dragonknight)&#39;: 0.15000000000000002,<br> &#39;Aemon-Targaryen-(Maester-Aemon)&#39;: 1.1486743815905878,<br>... }</pre><pre>&gt;&gt;&gt; nx.betweenness_centrality(G)<br>{&#39;Addam-Marbrand&#39;: 0.0,<br> &#39;Aegon-Frey-(son-of-Stevron)&#39;: 0.0,<br> &#39;Aegon-I-Targaryen&#39;: 0.0,<br> &#39;Aegon-Targaryen-(son-of-Rhaegar)&#39;: 0.0,<br> &#39;Aegon-V-Targaryen&#39;: 0.0,<br> &#39;Aemon-Targaryen-(Dragonknight)&#39;: 0.0,<br> &#39;Aemon-Targaryen-(Maester-Aemon)&#39;: 186.58333333333334,<br>... }</pre><pre>&gt;&gt;&gt; nx.closeness_centrality(G)<br>{&#39;Addam-Marbrand&#39;: 0.3234782608695652,<br> &#39;Aegon-Frey-(son-of-Stevron)&#39;: 0.0,<br> &#39;Aegon-I-Targaryen&#39;: 0.3765182186234818,<br> &#39;Aegon-Targaryen-(son-of-Rhaegar)&#39;: 0.0,<br> &#39;Aegon-V-Targaryen&#39;: 0.0,<br> &#39;Aemon-Targaryen-(Dragonknight)&#39;: 0.0,<br> &#39;Aemon-Targaryen-(Maester-Aemon)&#39;: 0.33695652173913043,<br>... }</pre><p><strong>2. Community Detection Algorithms</strong></p><p>Community Detection algorithms show how nodes are clustered or partitioned.</p><pre>&gt;&gt;&gt; list(nx.label_propagation_communities(G))<br>[{&#39;Addam-Marbrand&#39;,<br>  &#39;Aegon-I-Targaryen&#39;,<br>  &#39;Aerys-II-Targaryen&#39;,<br>  &#39;Alyn&#39;,<br>  &#39;Arthur-Dayne&#39;,<br>... ]</pre><pre>&gt;&gt;&gt; list(nx.connected_components(G))<br>[{&#39;Raymun-Redbeard&#39;},<br> {&#39;Hugh-Hungerford&#39;},<br> {&#39;Lucifer-Long&#39;},<br> {&#39;Torghen-Flint&#39;},<br> {&#39;Godric-Borrell&#39;},<br>... ]</pre><pre>&gt;&gt;&gt; nx.number_connected_components(G)<br>610</pre><pre>&gt;&gt;&gt; nx.clustering(G)<br>{&#39;Colemon&#39;: 1.0,<br> &#39;Desmond&#39;: 1.0,<br> &#39;High-Septon-(fat_one)&#39;: 1.0,<br> &#39;Hodor&#39;: 1.0,<br> &#39;Hosteen-Frey&#39;: 1.0,<br>... }</pre><pre>&gt;&gt;&gt; nx.triangles(G)<br>{&#39;Addam-Marbrand&#39;: 0,<br> &#39;Aegon-Frey-(son-of-Stevron)&#39;: 0,<br> &#39;Aegon-I-Targaryen&#39;: 0,<br> &#39;Aegon-Targaryen-(son-of-Rhaegar)&#39;: 0,<br> &#39;Aegon-V-Targaryen&#39;: 0,<br>... }</pre><p><strong>3. Path Finding Algorithms</strong></p><p>Path Finding algorithms show the shortest path between two or more nodes.</p><pre>&gt;&gt;&gt; nx.shortest_path(G, source=&quot;Tyrion-Lannister&quot;, target=&quot;Hodor&quot;)<br>[&#39;Tyrion-Lannister&#39;, &#39;Luwin&#39;, &#39;Hodor&#39;]</pre><pre>&gt;&gt;&gt; nx.shortest_weighted_path(G, source=&quot;Tyrion-Lannister&quot;, target=&quot;Hodor&quot;,weight=&#39;weight&#39;)<br>[&#39;Tyrion-Lannister&#39;, &#39;Theon-Greyjoy&#39;, &#39;Wyman-Manderly&#39;, &#39;Hodor&#39;]</pre><h3>Resources:</h3><p><strong>Project Github Page:</strong></p><p><a href="https://github.com/neo4j-graph-analytics/networkx-neo4j">neo4j-graph-analytics/networkx-neo4j</a></p><p><strong>Jupyter Notebooks:</strong></p><p><a href="https://github.com/ybaktir/networkx-neo4j/blob/master/examples/nxneo4j_tutorial_latest.ipynb">https://github.com/ybaktir/networkx-neo4j/blob/master/examples/nxneo4j_tutorial_latest.ipynb</a></p><p><strong>Changelog:</strong></p><p><a href="https://github.com/ybaktir/networkx-neo4j/blob/master/CHANGELOG.md">https://github.com/ybaktir/networkx-neo4j/blob/master/CHANGELOG.md</a></p><h3>Credits:</h3><p>Mark Needham for creating the library.</p><p>David Jablonski for adding the functionalities while improving the core functionality.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9fc65ddab222" width="1" height="1" alt=""><hr><p><a href="https://medium.com/neo4j/nxneo4j-networkx-api-for-neo4j-a-new-chapter-9fc65ddab222">nxneo4j: NetworkX-API for Neo4j — A new chapter</a> was originally published in <a href="https://medium.com/neo4j">Neo4j Developer Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>