cts.thresholds( computedLabels as Array, knownLabels as Array, [recallWeight as double] ) as Array
Compute precision, recall, the F measure, and thresholds for the classes computed by the classifier, by comparing with the labels for the same set.
You use the output of cts.thresholds
to determine
the best thresholds values for your data, based on the first pass
through the first part of your training data. The output of cts.thresholds
provides you
with precision and recall measurements at the calculated thresholds
for each class. The following are the definitions of the attributes
of the thresholds
element returned by
cts.thresholds
:
name
threshold
cts.classify
when
classifying documents, and is defined to be the positive
or negative distance from the hyperplane which represents the edge of
the class.
precision
recall
F
(the F-measure)
+Infinity
indicates
that weighting is recall only.// This returns the computed thresholds for the second half of // the plays in a Shakespeare database, based on a classifier // trained with the first half of the plays. For example: var firsthalf = fn.subsequence(xdmp.directory("/shakespeare/plays/", "1"), 1, 19); var plays1 = firsthalf.clone(); var secondhalf = fn.subsequence(xdmp.directory("/shakespeare/plays/", "1"), 20, 37); var plays2 = secondhalf.clone(); var firstlabels = []; for (var x of firsthalf) { var singleClass = [{"name": xdmp.documentProperties(xdmp.nodeUri(x)).next(). value.xpath("//playtype/fn:string()") }]; firstlabels.push({"classes": singleClass}); } var secondlabels = []; for (var x of secondhalf) { var singleClass = [{"name": xdmp.documentProperties(xdmp.nodeUri(x)).next(). value.xpath("//playtype/fn:string()") }]; secondlabels.push({"classes": singleClass}); }; var classifier = cts.train(plays1.toArray(), firstlabels, {"classifierType": "supports", "useDbConfig": true, "epsilon": 0.00001}); var classifysecond = cts.classify(plays2.toArray(), classifier, {}, plays1.toArray()); cts.thresholds(classifysecond, secondlabels); => [ { "name": "HISTORY", "threshold": 4.16419839859009, "precision": 1, "recall": 0.5, "f": 0.666666666666667, "count": 4 }, { "name": "COMEDY", "threshold": 3.69728088378906, "precision": 0.611111111111111, "recall": 1, "f": 0.758620689655173, "count": 11 }, { "name": "TRAGEDY", "threshold": 2.37126207351685, "precision": 0.4, "recall": 0.666666666666667, "f": 0.5, "count": 3 } ]