private List<Sampler<LinkNeighborhood>> loadTrainingData(Set<String> relevantUrls,
            int levels) throws Exception {

        final List<Sampler<LinkNeighborhood>> instances = new ArrayList<>();
        if (levels == 0) {
            // positive and negative case
            instances.add(new Sampler<LinkNeighborhood>(maxSamples));
            instances.add(new Sampler<LinkNeighborhood>(maxSamples));
        } else {
            // levels case
            for (int i = 0; i < levels; i++) {
                instances.add(new Sampler<LinkNeighborhood>(maxSamples));
            }
        }

        frontierManager.getFrontier().visitedLinks((LinkRelevance lr) -> {
            try {
                URL url = lr.getURL();
                LinkNeighborhood ln = graphRep.getLN(url);
                if (ln == null) {
                    return;
                }

                if (levels == 0) {
                    if (relevantUrls.contains(url.toString())) {
                        instances.get(0).sample(ln);
                    } else {
                        // consider add link to irrelevant sample (instances[1]) only if the number
                        // of irrelevant samples is smaller than the number of relevant sample
                        // (instances[1]). This is done to avoid a highly unbalanced number of
                        // samples of each class in the training data.
                        // The number of irrelevant links found is usually much higher than relevant
                        // links, so we only check if the number of irrelevant is not greater than
                        // the number of relevant links.
                        boolean considerSample = instances.get(1).reservoirSize() < instances.get(0).reservoirSize();
                        if (considerSample) {
                            instances.get(1).sample(ln);
                        }
                    }
                } else {
                    if (relevantUrls.contains(ln.getLink().toString())) {
                        instances.get(0).sample(ln);
                        addBacklinks(instances, ln.getLink(), 1, levels, relevantUrls);
                    }
                }
            } catch (Exception e) {
                logger.warn("Failed to include link relevance in training data.", e);
            }
        });

        return instances;
    }
Loads training data to train the link classifier. The training data for each class were are
trying to predict is returned in a separate 'ordered' list. The position of the list
indicates the priority of the links in that list.

@param relevantUrls
@param levels
@return
@throws Exception
ache/src/main/java/achecrawler/link/classifier/builder/LinkClassifierBuilder.java