Class AbstractClassificationMetric<U>
java.lang.Object
es.uam.eps.ir.relison.links.linkprediction.metrics.AbstractClassificationMetric<U>
- Type Parameters:
U
- type of the users.
- All Implemented Interfaces:
LinkPredictionMetric<U>
public abstract class AbstractClassificationMetric<U> extends java.lang.Object implements LinkPredictionMetric<U>
Implementation of the area under the receiver-operating characteristic curve
for link prediction.
-
Field Summary
Fields Modifier and Type Field Description private int
cutoff
The number of items in the ranking to consider.private double
threshold
The classification threshold (values below this will be classified as negative).private boolean
useCutoff
True if we use the cutoff of the prediction to differentiate between positive and negative examples, false if we use a threshold value. -
Constructor Summary
Constructors Constructor Description AbstractClassificationMetric(double threshold)
Constructor.AbstractClassificationMetric(int cutoff)
Constructor. -
Method Summary
Modifier and Type Method Description protected abstract double
compute(long size, long truePos, long trueNeg, long falsePos, long falseNeg)
Computes the actual classification metric.double
evaluate(Graph<U> graph, Prediction<U> pred)
Evaluates a link prediction algorithm.double
evaluate(Graph<U> graph, Prediction<U> pred, java.util.function.Predicate<Pair<U>> filter)
Evaluates a link prediction algorithm.double
evaluate(Graph<U> graph, Prediction<U> pred, java.util.stream.Stream<Pair<U>> pairs)
Evaluates a link prediction algorithm.
-
Field Details
-
cutoff
private final int cutoffThe number of items in the ranking to consider. -
threshold
private final double thresholdThe classification threshold (values below this will be classified as negative). -
useCutoff
private final boolean useCutoffTrue if we use the cutoff of the prediction to differentiate between positive and negative examples, false if we use a threshold value.
-
-
Constructor Details
-
AbstractClassificationMetric
public AbstractClassificationMetric(int cutoff)Constructor.- Parameters:
cutoff
- the number of items in the ranking to consider. If cutoff is smaller or equal than 0, we consider that the links in the ranking are all the seen objects.
-
AbstractClassificationMetric
public AbstractClassificationMetric(double threshold)Constructor.- Parameters:
threshold
- the minimum threshold. Pairs given a value greater or equal than the threshold will be considered as if they were positively classified. The rest, as negative.
-
-
Method Details
-
evaluate
Description copied from interface:LinkPredictionMetric
Evaluates a link prediction algorithm. It considers that the prediction is applied over all pairs of users in the network.- Specified by:
evaluate
in interfaceLinkPredictionMetric<U>
- Parameters:
graph
- a graph containing the set of links to predict.pred
- the prediction.- Returns:
- the value of the metric.
-
evaluate
public double evaluate(Graph<U> graph, Prediction<U> pred, java.util.function.Predicate<Pair<U>> filter)Description copied from interface:LinkPredictionMetric
Evaluates a link prediction algorithm. It considers that the prediction is only applied for a subset of pairs of users in the network: those who pass a given filter.- Specified by:
evaluate
in interfaceLinkPredictionMetric<U>
- Parameters:
graph
- a graph containing the set of links to predict.pred
- the prediction.filter
- the filter for the different pairs of users.- Returns:
- the value of the metric.
-
evaluate
Description copied from interface:LinkPredictionMetric
Evaluates a link prediction algorithm. It considers that we only apply this over a given set of links.- Specified by:
evaluate
in interfaceLinkPredictionMetric<U>
- Parameters:
graph
- a graph containing the set of links to predict.pred
- the prediction.pairs
- the set of users to apply the recommendation to.- Returns:
- the value of the metric.
-
compute
protected abstract double compute(long size, long truePos, long trueNeg, long falsePos, long falseNeg)Computes the actual classification metric.- Parameters:
size
- the total number of links to consider.truePos
- the number of correctly classified positive links.trueNeg
- the number of correctly classified negative links.falsePos
- the number of wrongly classified positive links.falseNeg
- the number of wrongly classified negative links.- Returns:
- the value of the metric.
-