Package smile.validation.metric
Class FScore
java.lang.Object
smile.validation.metric.FScore
- All Implemented Interfaces:
Serializable
,ClassificationMetric
The F-score (or F-measure) considers both the precision and the recall of the test
to compute the score. The precision p is the number of correct positive results
divided by the number of all positive results, and the recall r is the number of
correct positive results divided by the number of positive results that should
have been returned.
The traditional or balanced F-score (F1 score) is the harmonic mean of precision and recall, where an F1 score reaches its best value at 1 and worst at 0.
The general formula involves a positive real β so that F-score measures the effectiveness of retrieval with respect to a user who attaches β times as much importance to recall as precision.
- See Also:
-
Field Summary
-
Constructor Summary
-
Method Summary
-
Field Details
-
F1
The F_1 score, the harmonic mean of precision and recall. -
F2
The F_2 score, which weighs recall higher than precision. -
FHalf
The F_0.5 score, which weighs recall lower than precision.
-
-
Constructor Details
-
FScore
public FScore()Constructor of F1 score. -
FScore
public FScore(double beta) Constructor of general F-score.- Parameters:
beta
- a positive value such that F-score measures the effectiveness of retrieval with respect to a user who attaches β times as much importance to recall as precision.
-
-
Method Details
-
score
public double score(int[] truth, int[] prediction) Description copied from interface:ClassificationMetric
Returns a score to measure the quality of classification.- Specified by:
score
in interfaceClassificationMetric
- Parameters:
truth
- the true class labels.prediction
- the predicted class labels.- Returns:
- the metric.
-
of
public static double of(double beta, int[] truth, int[] prediction) Calculates the F1 score.- Parameters:
beta
- a positive value such that F-score measures the effectiveness of retrieval with respect to a user who attaches β times as much importance to recall as precision.truth
- the ground truth.prediction
- the prediction.- Returns:
- the metric.
-
toString
-