class documentation

Base class for evaluation results that expose classification metrics like P/R/F1 and confusion matrices.

Parameters
samplesthe fiftyone.core.collections.SampleCollection used
configthe fiftyone.core.evaluation.EvaluationMethodConfig used
eval_keythe evaluation key
ytruea list of ground truth labels
ypreda list of predicted labels
confsan optional list of confidences for the predictions
weightsan optional list of sample weights
ytrue_idsa list of IDs for the ground truth labels
ypred_idsa list of IDs for the predicted labels
classesthe list of possible classes. If not provided, the observed ground truth/predicted labels are used
missinga missing label string. Any None-valued labels are given this label for evaluation purposes
custom_metricsan optional dict of custom metrics
backenda fiftyone.core.evaluation.EvaluationMethod backend
Method __enter__ Undocumented
Method __exit__ Undocumented
Method __init__ Undocumented
Method clear_subset Clears the subset set by use_subset, if any.
Method confusion_matrix Generates a confusion matrix for the results via sklearn:sklearn.metrics.confusion_matrix.
Method metrics Computes classification metrics for the results, including accuracy, precision, recall, and F-beta score.
Method plot_confusion_matrix Plots a confusion matrix for the evaluation results.
Method print_metrics Prints the metrics computed via metrics.
Method print_report Prints a classification report for the results via sklearn:sklearn.metrics.classification_report.
Method report Generates a classification report for the results via sklearn:sklearn.metrics.classification_report.
Method use_subset Restricts the evaluation results to the specified subset.
Instance Variable classes Undocumented
Instance Variable confs Undocumented
Instance Variable missing Undocumented
Instance Variable weights Undocumented
Instance Variable ypred Undocumented
Instance Variable ypred_ids Undocumented
Instance Variable ytrue Undocumented
Instance Variable ytrue_ids Undocumented
Property has_subset Whether these results are currently restricted to a subset via use_subset.
Class Method _from_dict Subclass implementation of from_dict.
Method _confusion_matrix Undocumented
Method _parse_classes Undocumented
Instance Variable _confs_orig Undocumented
Instance Variable _has_subset Undocumented
Instance Variable _samples Undocumented
Instance Variable _samples_orig Undocumented
Instance Variable _weights_orig Undocumented
Instance Variable _ypred_ids_orig Undocumented
Instance Variable _ypred_orig Undocumented
Instance Variable _ytrue_ids_orig Undocumented
Instance Variable _ytrue_orig Undocumented

Inherited from BaseEvaluationResults:

Method add_custom_metrics Computes the given custom metrics and adds them to these results.
Method _get_custom_metrics Undocumented
Method _print_metrics Undocumented

Inherited from BaseRunResults (via BaseEvaluationResults, EvaluationResults):

Class Method from_dict Builds a BaseRunResults from a JSON dict representation of it.
Static Method base_results_cls Returns the results class for the given run type.
Method attributes Returns the list of class attributes that will be serialized by serialize.
Method save Saves the results to the database.
Method save_config Saves these results config to the database.
Property cls The fully-qualified name of this BaseRunResults class.
Property config The BaseRunConfig for these results.
Property key The run key for these results.
Property samples The fiftyone.core.collections.SampleCollection associated with these results.
Instance Variable _backend Undocumented
Instance Variable _config Undocumented
Instance Variable _key Undocumented
def __enter__(self): (source)

Undocumented

def __exit__(self, *args): (source)

Undocumented

def __init__(self, samples, config, eval_key, ytrue, ypred, confs=None, weights=None, ytrue_ids=None, ypred_ids=None, classes=None, missing=None, custom_metrics=None, backend=None): (source)
def clear_subset(self): (source)

Clears the subset set by use_subset, if any.

Subsequent operations will be performed on the full results.

def confusion_matrix(self, classes=None, include_other=False, include_missing=False): (source)

Generates a confusion matrix for the results via sklearn:sklearn.metrics.confusion_matrix.

The rows of the confusion matrix represent ground truth and the columns represent predictions.

Parameters
classes:Nonean optional list of classes to include in the confusion matrix
include_other:Falsewhether to include an extra row/column at the end of the matrix for labels that do not appear in classes. Only applicable if classes are provided
include_missing:Falsewhether to include a row/column at the end of the matrix for unmatched labels. Only applicable if self.missing does not already appear in classes. If both "other" and "missing" rows/columns are requested, this one is last
Returns
a num_classes x num_classes confusion matrix
def metrics(self, classes=None, average='micro', beta=1.0): (source)

Computes classification metrics for the results, including accuracy, precision, recall, and F-beta score.

See sklearn:sklearn.metrics.precision_recall_fscore_support for details.

Also includes any custom metrics from custom_metrics.

Parameters
classes:Nonean optional list of classes to include in the calculations
average:"micro"the averaging strategy to use
beta:1.0the F-beta value to use
Returns
a dict
def plot_confusion_matrix(self, classes=None, include_other=None, include_missing=None, other_label='(other)', backend='plotly', **kwargs): (source)

Plots a confusion matrix for the evaluation results.

If you are working in a notebook environment with the default plotly backend, this method returns an interactive fiftyone.core.plots.plotly.InteractiveHeatmap that you can attach to an App session via its fiftyone.core.session.Session.plots attribute, which will automatically sync the session's view with the currently selected cells in the confusion matrix.

Parameters
classes:Nonean optional list of classes to include in the confusion matrix
include_other:None

whether to include a row/column for examples whose label is in classes but are matched to labels that do not appear in classes. Only applicable if classes are provided. The supported values are:

  • None (default): only include a row/column for other labels if there are any
  • True: do include a row/column for other labels
  • False: do not include a row/column for other labels
include_missing:None

whether to include a row/column for missing ground truth/predictions in the confusion matrix. The supported values are:

  • None (default): only include a row/column for missing labels if there are any
  • True: do include a row/column for missing labels
  • False: do not include a row/column for missing labels
other_label:"(other)"the label to use for "other" predictions
backend:"plotly"the plotting backend to use. Supported values are ("plotly", "matplotlib")
**kwargs

keyword arguments for the backend plotting method:

Returns
one of the following
def print_metrics(self, classes=None, average='micro', beta=1.0, digits=2): (source)

Prints the metrics computed via metrics.

Parameters
classes:Nonean optional list of classes to include in the calculations
average:"micro"the averaging strategy to use
beta:1.0the F-beta value to use
digits:2the number of digits of precision to print
def print_report(self, classes=None, digits=2): (source)

Prints a classification report for the results via sklearn:sklearn.metrics.classification_report.

Parameters
classes:Nonean optional list of classes to include in the report
digits:2the number of digits of precision to print
def report(self, classes=None): (source)

Generates a classification report for the results via sklearn:sklearn.metrics.classification_report.

Parameters
classes:Nonean optional list of classes to include in the report
Returns
a dict
def use_subset(self, subset_def): (source)

Restricts the evaluation results to the specified subset.

Subsequent calls to supported methods on this instance will only contain results from the specified subset rather than the full results.

Use clear_subset to reset to the full results. Or, equivalently, use the context manager interface as demonstrated below to automatically reset the results when the context exits.

Example usage:

import fiftyone as fo
import fiftyone.zoo as foz
import fiftyone.utils.random as four
from fiftyone import ViewField as F

dataset = foz.load_zoo_dataset("quickstart")
four.random_split(dataset, {"sunny": 0.7, "cloudy": 0.2, "rainy": 0.1})

results = dataset.evaluate_detections(
    "predictions",
    gt_field="ground_truth",
    eval_key="eval",
)

counts = dataset.count_values("ground_truth.detections.label")
classes = sorted(counts, key=counts.get, reverse=True)[:5]

# Full results
results.print_report(classes=classes)

# Sunny samples
subset_def = dict(type="field", field="tags", value="sunny")
with results.use_subset(subset_def):
    results.print_report(classes=classes)

# Small objects
bbox_area = F("bounding_box")[2] * F("bounding_box")[3]
small_objects = bbox_area <= 0.05
subset_def = dict(type="attribute", expr=small_objects)
with results.use_subset(subset_def):
    results.print_report(classes=classes)
Parameters
subset_def

the subset definition, which can be:

Returns
self

Undocumented

Undocumented

Whether these results are currently restricted to a subset via use_subset.

@classmethod
def _from_dict(cls, d, samples, config, eval_key, **kwargs): (source)

Subclass implementation of from_dict.

Parameters
da JSON dict
samplesthe fiftyone.core.collections.SampleCollection for the run
configthe BaseRunConfig for the run
eval_keyUndocumented
keythe run key
**kwargsUndocumented
Returns
a BaseRunResults
def _confusion_matrix(self, classes=None, include_other=None, include_missing=None, other_label=None, tabulate_ids=False): (source)

Undocumented

def _parse_classes(self, classes): (source)
_confs_orig = (source)

Undocumented

_has_subset: bool = (source)

Undocumented

_samples_orig = (source)

Undocumented

_weights_orig = (source)

Undocumented

_ypred_ids_orig = (source)

Undocumented

_ypred_orig = (source)

Undocumented

_ytrue_ids_orig = (source)

Undocumented

_ytrue_orig = (source)

Undocumented