Api Reference

Documentation for ClassificationMetrics.

ClassificationMetrics.apply_metricMethod
apply_metric(metric, TP, FN, FP, TN; aggregation=default_aggregation(), kws...)
apply_metric(metric, pr::PredictionResults; aggregation=default_aggregation(), kws...)
apply_metric(metric, confusion_matrix::ConfusionMatrix; aggregation=default_aggregation(), kws...)
apply_metric(metric, predicted, classes; aggregation=default_aggregation() label_set=nothing, sort_labels=false, kws...)

Applies metric defined as a function of TP, FN, FP, TN with a given aggregation strategy. It is assumed that the metric is defined for a single class, and apply_metric should be used for multiclass setting. kws keywords can be used to pass additional parameters to the metric, e.g. β for the Fβ-score

Note: all metrics defined with @metric macro are automatically extended, so they can be called in multiclass setting without calling this function explicitly.

source
ClassificationMetrics.classification_reportMethod
classification_report(predicted, actual; label_set=nothing, sort_labels=true, kws...)
classification_report(cf::ConfusionMatrix; kws...)
classification_report(prediction_results::PredictionResults; kws...)

Print classification report.

Keywords

  • metrics=[precision, recall, F1_score]: metrics to compute
  • show_per_class=true: show results per each class or only the aggregated results
  • aggregations=[micro_aggregation, macro_aggregation, weighted_aggregation]: aggregations

to be used. If the aggregation function is passed, it will be applied to all classes. Alternatively, it is possible to aggregate only a subset of classes by passing AggregationSubset created with aggregate_subset.

  • io::IO | String | HTML = stdout: io to print out. Refer to PrettyTables for more information.
  • include_support=true: print support column or not
  • default_format=val->@sprintf("%.4f", val): string format for the values
  • backend=Val(:text): the backend used to generate table.

Can be Val(:text), Val(:html), Val(:latex), Val(:markdown). Refer to PrettyTables for more information.

  • optional_kws = DEFAULT_PARAMETERS[backend]: optional keywords to pass topretty_table`
source
ClassificationMetrics.confusion_matrixFunction
confusion_matrix(predicted, actual[, label_set]; sort_labels=false)
confusion_matrix(predicted::OneHotLike, actual::OneHotLike, label_set)

Returns a ConfusionMatrix object that holds both the matrix and ladel set. predicted and actual can be provided as vectors of labels or in the one-hot encoded form. Optionally, label_set can be provided explicitly.

source
ClassificationMetrics.recallMethod
recall(TP, FN, FP, TN) = safe_div(TP, TP + FN)
sensitivity(TP, FN, FP, TN) = safe_div(TP, TP + FN)
true_positive_rate(TP, FN, FP, TN) = safe_div(TP, TP + FN)
source
ClassificationMetrics.sensitivityMethod
recall(TP, FN, FP, TN) = safe_div(TP, TP + FN)
sensitivity(TP, FN, FP, TN) = safe_div(TP, TP + FN)
true_positive_rate(TP, FN, FP, TN) = safe_div(TP, TP + FN)
source
ClassificationMetrics.weighted_aggregationMethod
weighted_aggregation(func, TP, FN, FP, TN; weights=TP .+ FN)
weighted_aggregation(weights; name="Weighted (Custom)")

One of possible aggregation options. Performs weighted aggregation, i.e. applies metric to each class and reports the weighted mean. By default, uses support of each class as the weight, but allows passing custom weights. weighted_aggregation(weights; name="Weighted (Custom)") returns an aggregation function with fixed weights, useful for passing to classification_report.

source
ClassificationMetrics.@metricMacro
@metric ["Metric print name"] metric_function(TP, FN, FP, TN) = ...
@metric ["Metric print name"] function metric_function(TP, FN, FP, TN) 
    ... 
end
@metric ["Metric 1 print name"] metric1_function ["Metric 2 print name"] metric2_function ...

A macro to automatically define aggregation calls for a metric defined for a single class. The metric should have signature metric(TP, FN, FP, TN) where TP, FN, FP and TN are all scalars.

It is also possible to optionally define a print name for a metric to be used for printing classification report.

source