Structures
The following structures are available globally.

An individual result row in a
See moreClassifierResults
instance, for a single activity type.Declaration
Swift
public struct ClassifierResultItem: Equatable

The results of a call to
classify(_:types:)
on anActivityTypeClassifier
.Classifier Results are an iterable sequence of
ClassifierResultItem
rows, with each row representing a singleActivityTypeName
and its match probability score.The results are ordered from best match to worst match, thus the first result row represents the best match for the given sample.
Using The Results
The simplest way to use the results is to take the first result row (ie the best match) and ignore the rest.
let results = classifier.classify(sample) let bestMatch = results.first
You could also iterate through the results, in order from best match to worst match.
for result in results { print("name: \(result.name) score: \(result.score)") }
If you want to know the probability score of a specific type, you could extract that result row by
ActivityTypeName
:let walkingResult = results[.walking]
If you want the first and second result rows:
let firstResult = results[0] let secondResult = results[1]
Interpreting Classifier Results
Two key indicators can help to interpret the probability scores. The first being the most obvious: a higher score indicates a better match.
The second, and perhaps more important indicator, is the ratio of the best match’s score to the second best match’s score.
For example if the first result row has a probability score of 0.9 (a 90% match) while the second result row’s score is 0.1 (a 10% match), that indicates that the best match is nine times more probable than the second best match (
0.9 / 0.1 = 9.0
). However if the second row’s score where instead 0.8, the first row would only be 1.125 times more probable than the second (0.9 / 0.8 = 1.125
).The ratio between the first and second best matches can be loosely considered a
confidence
score. Thus the0.9 / 0.1 = 9.0
example gives a confidence score of 9.0, whilst the second example of0.9 / 0.8 = 1.125
gives a much lower confidence score of 1.125.A real world example might be results that have
car
andbus
as the top two results. If both types achieve a high probability score, but the scores are close together, that indicates there is high confidence that the type is either car or bus, but low confidence of knowing which one of the two it is.The easiest way to apply these two metrics is with simple thresholds. For example a raw score threshold of 0.01 and a firsttosecondmatch ratio threshold of 2.0. If the first match falls below these thresholds, you could consider it an
See moreuncertain
match. Although which kinds of thresholds to use will depend heavily on the application.Declaration
Swift
public struct ClassifierResults: Sequence, IteratorProtocol

Settings for use of the LocoKit Service.
See moreDeclaration
Swift
public struct LocoKitService