accuracy<T> function
Accuracy metric: the proportion of correct predictions over total predictions.
Implementation
double accuracy<T>(List<T> yTrue, List<T> yPred) {
if (yTrue.length != yPred.length) {
throw ArgumentError('Lengths of true and predicted labels must match.');
}
final correct = List.generate(yTrue.length, (i) => yTrue[i] == yPred[i] ? 1 : 0).reduce((a, b) => a + b);
return correct / yTrue.length;
}