Skip to main content

split_edges

Function split_edges 

Source
pub fn split_edges(
    graph: &Graph,
    test_fraction: f64,
    seed: u64,
) -> IgraphResult<EdgeSplit>
Expand description

Split graph edges into train and test sets.

Randomly partitions the edge set: test_fraction of edges go to the test set, the remainder to training. Useful for link prediction evaluation where test edges are removed from the graph.

§Parameters

  • graph — The input graph.
  • test_fraction — Fraction of edges for the test set (0.0 to 1.0).
  • seed — PRNG seed for deterministic splitting.

§Returns

An EdgeSplit with train and test edge vectors.

§Errors

Returns an error if test_fraction is not in [0.0, 1.0].

§Examples

use rust_igraph::{Graph, split_edges};

let g = Graph::from_edges(
    &[(0,1),(1,2),(2,3),(3,4),(4,0),(0,2),(1,3),(2,4)],
    false, Some(5)
).unwrap();

let split = split_edges(&g, 0.25, 42).unwrap();
assert_eq!(split.train.len() + split.test.len(), g.ecount());
assert_eq!(split.test.len(), 2); // 25% of 8 = 2