liveBook · Manning

Negative sample

As explained in Graph Algorithms for Data Science

A negative example is a labeled prediction instance representing the absence of the relationship or outcome being predicted.

A negative sample is a labeled prediction instance representing a pair of nodes without the relationship being predicted. Binary link-prediction models need both positive and negative samples to distinguish existing from absent links. section 10.2.3 section 10.2

Construct negative samples carefully:

  • Select node pairs with no relationship in the feature, training, or test sets. section 10.2.3
  • Subsample them because possible nonrelationships grow quadratically, creating severe class imbalance. section 10.2.3 section 10.6
  • Use roughly as many negative samples as positive samples so majority-class accuracy does not conceal poor minority-class predictions. section 10.2.3
  • Keep feature, training, and test relationships separated when graph-based features could reveal the target link. section 10.2 section 10.6

Balanced link-prediction samples

If an exercise produces 13,082 positive examples, select approximately the same number of unconnected node pairs as negative examples, ensuring those pairs remain relationship-free across the feature, training, and test sets. section 10.2.3

How Graph Algorithms for Data Science covers it

How deep it goes
Explains selection, balancing, and leakage constraints, but does not provide the complete implementation for constructing pairs.
Examples
Uses unconnected social-graph node pairs and an exercise target of approximately 13,082 negative samples.
What it assumes
Assumes familiarity with nodes, relationships, binary classification, and link prediction while teaching why absent relationships must be sampled.
What you can do after
Builds balanced link-prediction datasets while avoiding relationship leakage across feature, training, and test sets.
How it connects
Connects negative samples to link prediction, binary classification, class imbalance, dataset splitting, data leakage, and graph-based features.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Algorithms for Data Science. The section links point to the parts of the book it draws on.