Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-01-2022 11:42 PM
I wanted to calculate quantile values over a list of integers. In python, there is Numpy library which does that as follows:
import numpy
list = [4, 6, 1, 3, 10, 5]
q3 = numpy.quantile(list, 0.75) #5.75
q2 = numpy.quantile(list, 0.50) #4.5
q1 = numpy.quantile(list, 0.25) #3.25
How would I be able to do this in cypher?
Solved! Go to Solution.
12-02-2022 02:14 AM
Hi,
in my case, the list is the different values of annot.value returned by a query. annot is a node that has a property named 'value' with a float type.
match (:Search{searchId:"4e69-9ebd-b02e1b0c0d49"})-[:FIRST]->(:SearchSession)-[:ANNOTATION]->(annot:FigureAnnotation)
RETURN apoc.agg.percentiles(annot.value, [0.25, 0.5, 0.75, 1.0]) AS percentiles;
perhaps you can make a similar query?
12-02-2022 01:33 AM
Hi,
Please,have a look at this page about apoc.agg.percentiles function: https://neo4j.com/labs/apoc/4.4/overview/apoc.agg/apoc.agg.percentiles/
12-02-2022 01:54 AM
Yes, I've come across that, but I'm not sure how to use them for a list ....
12-02-2022 02:14 AM
Hi,
in my case, the list is the different values of annot.value returned by a query. annot is a node that has a property named 'value' with a float type.
match (:Search{searchId:"4e69-9ebd-b02e1b0c0d49"})-[:FIRST]->(:SearchSession)-[:ANNOTATION]->(annot:FigureAnnotation)
RETURN apoc.agg.percentiles(annot.value, [0.25, 0.5, 0.75, 1.0]) AS percentiles;
perhaps you can make a similar query?
12-02-2022 02:41 AM
Thanks, I did it this way and it worked ...
WITH [4, 6, 1, 3, 10, 5] as list
UNWIND list as l
RETURN apoc.agg.percentiles(l, [0.25, 0.5, 0.75, 1.0]) AS percentiles
12-02-2022 04:56 AM
There are also the cypher aggregate functions if you don’t want to use the apoc library.
https://neo4j.com/docs/cypher-manual/current/functions/aggregating/#functions-percentilecont
All the sessions of the conference are now available online