neo4j percentage of attribute for social network

Georg Heiler

How can I calculate the percentage of an attribute for all the connections of a social network? In this particular sample I would want to calculate the fraudulence of a user by assessing its interactions (call, sms):

CREATE (Alice:Person {id:'a', fraud:1})
CREATE (Bob:Person {id:'b', fraud:0})
CREATE (Charlie:Person {id:'c', fraud:0})
CREATE (David:Person {id:'d', fraud:0})
CREATE (Esther:Person {id:'e', fraud:0})
CREATE (Fanny:Person {id:'f', fraud:0})
CREATE (Gabby:Person {id:'g', fraud:0})
CREATE (Fraudster:Person {id:'h', fraud:1})


CREATE
  (Alice)-[:CALL]->(Bob),
  (Bob)-[:SMS]->(Charlie),
  (Charlie)-[:SMS]->(Bob),
  (Fanny)-[:SMS]->(Charlie),
  (Esther)-[:SMS]->(Fanny),
  (Esther)-[:CALL]->(David),
  (David)-[:CALL]->(Alice),
  (David)-[:SMS]->(Esther),
  (Alice)-[:CALL]->(Esther),
  (Alice)-[:CALL]->(Fanny),
  (Fanny)-[:CALL]->(Fraudster)

When trying to query like:

MATCH (a)-->(b)
WHERE b.fraud = 1
RETURN (count() / ( MATCH (a) -->(b) RETURN count() ) * 100)

I see the following error:

Invalid input '>': expected 0..9, '.', UnsignedHexInteger, UnsignedOctalInteger or UnsignedDecimalInteger (line 3, column 33 (offset: 66))
"RETURN (count() / ( MATCH (a) -->(b) RETURN count() ) * 100)"
                                 ^

enter image description here

cybersam

This query will return the percentage of connections to each fraud:

MATCH (:Person)-[:CALL|:SMS]->(f:Person)
WITH TOFLOAT(COUNT(*))/100 AS divisor, COLLECT(f) AS fs
UNWIND fs AS f
WITH divisor, f
WHERE f.fraud = 1
RETURN f, COUNT(*)/divisor AS percentage

With the sample data, the result is:

+----------------------------------------------+
| f                        | percentage        |
+----------------------------------------------+
| Node[13]{id:"h",fraud:1} | 9.090909090909092 |
| Node[6]{id:"a",fraud:1}  | 9.090909090909092 |
+----------------------------------------------+

This query only needs a single scan of the DB, and is explicit about the node labels and relationship types -- to filter out any other data that might be in the DB.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Social network - Suggested friends

From Dev

Is it a good practice to use an "id" attribute in Neo4J?

From Dev

Neo4j cypher for co-favorited plus additional attribute

From Dev

Load Social Network Data into Neo4J

From Dev

Social Network Share buttons set to a Percentage based height based on number of shares and number of Social Networks?

From Dev

Get attribute of relationship nodes in Neo4j using Neo4jClient

From Dev

Difference between social network queries

From Dev

history attribute in neo4j

From Dev

social network vk auth with martini

From Dev

Not null attribute in Neo4J constraint

From Dev

remove attribute from very large number of nodes in neo4j

From Dev

Social Media Icons Link Attribute

From Dev

Neo4j vs. ArangoDB when modeling a social network

From Dev

How to store social network's actions in NEO4J?

From Dev

AttributeError: 'Graph' object has no attribute 'cypher' in migration of data from Postgress to Neo4j(Graph Database)

From Dev

Cassandra data modeling for a social network

From Dev

Neo4J cypher query to get nodes connected by paths with the same generic attribute

From Dev

How do I model social network connections in neo4j?

From Dev

R: Looping social network analysis

From Dev

Social Network Share buttons set to a Percentage based height based on number of shares and number of Social Networks?

From Dev

Create Relationships between Consequent Nodes (on date attribute) in Neo4j

From Dev

How to represent the lines of a network in Neo4j

From Dev

Building A Social Network

From Dev

filter with relation attribute neo4j

From Dev

Find social network components in Stata

From Dev

remove attribute from very large number of nodes in neo4j

From Dev

Keyboard Shortcut in "The Social Network"

From Dev

sum a node attribute along all paths in neo4j

From Dev

RDF semantic network for social robotics

Related Related

  1. 1

    Social network - Suggested friends

  2. 2

    Is it a good practice to use an "id" attribute in Neo4J?

  3. 3

    Neo4j cypher for co-favorited plus additional attribute

  4. 4

    Load Social Network Data into Neo4J

  5. 5

    Social Network Share buttons set to a Percentage based height based on number of shares and number of Social Networks?

  6. 6

    Get attribute of relationship nodes in Neo4j using Neo4jClient

  7. 7

    Difference between social network queries

  8. 8

    history attribute in neo4j

  9. 9

    social network vk auth with martini

  10. 10

    Not null attribute in Neo4J constraint

  11. 11

    remove attribute from very large number of nodes in neo4j

  12. 12

    Social Media Icons Link Attribute

  13. 13

    Neo4j vs. ArangoDB when modeling a social network

  14. 14

    How to store social network's actions in NEO4J?

  15. 15

    AttributeError: 'Graph' object has no attribute 'cypher' in migration of data from Postgress to Neo4j(Graph Database)

  16. 16

    Cassandra data modeling for a social network

  17. 17

    Neo4J cypher query to get nodes connected by paths with the same generic attribute

  18. 18

    How do I model social network connections in neo4j?

  19. 19

    R: Looping social network analysis

  20. 20

    Social Network Share buttons set to a Percentage based height based on number of shares and number of Social Networks?

  21. 21

    Create Relationships between Consequent Nodes (on date attribute) in Neo4j

  22. 22

    How to represent the lines of a network in Neo4j

  23. 23

    Building A Social Network

  24. 24

    filter with relation attribute neo4j

  25. 25

    Find social network components in Stata

  26. 26

    remove attribute from very large number of nodes in neo4j

  27. 27

    Keyboard Shortcut in "The Social Network"

  28. 28

    sum a node attribute along all paths in neo4j

  29. 29

    RDF semantic network for social robotics

HotTag

Archive