Evaluating Regressions#
You can use the
evaluate_regressions()
method to evaluate the predictions of a regression model stored in a
Regression field of your dataset.
Invoking
evaluate_regressions()
returns a RegressionResults instance that provides a variety of methods for
evaluating your model.
In addition, when you specify an eval_key parameter, helpful fields will be
populated on each sample that you can leverage via the
FiftyOne App to interactively explore the strengths and
weaknesses of your model on individual samples.
Simple evaluation (default)#
By default,
evaluate_regressions()
will evaluate each prediction by directly comparing its value to the
associated ground truth value.
You can explicitly request that simple evaluation be used by setting the
method parameter to "simple".
When you specify an eval_key parameter, a float eval_key field will be
populated on each sample that records the error of that sampleβs prediction
with respect to its ground truth value. By default, the squared error will be
computed, but you can customize this via the optional metric argument to
evaluate_regressions(),
which can take any value supported by
SimpleEvaluationConfig.
The example below demonstrates simple evaluation on the quickstart dataset with some fake regression data added to it to demonstrate the workflow:
1import random
2import numpy as np
3
4import fiftyone as fo
5import fiftyone.zoo as foz
6from fiftyone import ViewField as F
7
8dataset = foz.load_zoo_dataset("quickstart").select_fields().clone()
9
10# Populate some fake regression + weather data
11for idx, sample in enumerate(dataset, 1):
12 ytrue = random.random() * idx
13 ypred = ytrue + np.random.randn() * np.sqrt(ytrue)
14 confidence = random.random()
15 sample["ground_truth"] = fo.Regression(value=ytrue)
16 sample["predictions"] = fo.Regression(value=ypred, confidence=confidence)
17 sample["weather"] = random.choice(["sunny", "cloudy", "rainy"])
18 sample.save()
19
20print(dataset)
21
22# Evaluate the predictions in the `predictions` field with respect to the
23# values in the `ground_truth` field
24results = dataset.evaluate_regressions(
25 "predictions",
26 gt_field="ground_truth",
27 eval_key="eval",
28)
29
30# Print some standard regression evaluation metrics
31results.print_metrics()
32
33# Plot a scatterplot of the results colored by `weather` and scaled by
34# `confidence`
35plot = results.plot_results(labels="weather", sizes="predictions.confidence")
36plot.show()
37
38# Launch the App to explore
39session = fo.launch_app(dataset)
40
41# Show the samples with the smallest regression error
42session.view = dataset.sort_by("eval")
43
44# Show the samples with the largest regression error
45session.view = dataset.sort_by("eval", reverse=True)
mean squared error 59.69
root mean squared error 7.73
mean absolute error 5.48
median absolute error 3.57
r2 score 0.97
explained variance score 0.97
max error 31.77
support 200
Note
Did you know? You can attach regression plots to the App and interactively explore them by selecting scatter points and/or modifying your view in the App.