Is it possible to write a query to partition the graph

I want to split the graph into two sets, train and test. For each node, add an additional node label, either 'train' or 'test'. For example, 1/3 goes to 'test' and 2/3 goes to 'train'. Is is possible to do this with a cypher in neo4j?

WITH count(n) as total
UNWIND range(1,total) as range
WITH toInteger(rand() * (total - 1 + 1)) + 1 as randomID
WHERE ID(n) = randomID
SET n:Test

It should be something like this. The total needs to be divided into a test and train based on the 1:2 ratio.

We can do this, but it will be a little easier if we leverage APOC Procedures so we can add labels dynamically.

WITH n, rand() * 3 as random
WITH n, CASE WHEN random < 1 THEN 'Test' ELSE 'Train' END as label
CALL apoc.create.addLabels([n], [label]) YIELD node
RETURN count(*)

That's really a smart way to do this task!