public float Evaluate(List <float[]> data, SVM svm) { var correct = 0; for (int i = 0; i < data.Count; ++i) { var x = new Unit(data[i][0], 0.0f); var y = new Unit(data[i][1], 0.0f); var label = data[i][2]; var predictedValue = svm.Forward(x, y).value; var predictedLabel = predictedValue > 0.0f ? 1.0f : -1.0f; if (predictedLabel == label) { correct++; } } return(correct / (float)data.Count); }
private static double EvalTrainingAccuracy(List <double[]> data, List <int> labels, SVM svm) { var num_correct = 0; for (var i = 0; i < data.Count; i++) { var x = new Unit(data[i][0], 0.0); var y = new Unit(data[i][1], 0.0); var true_label = labels[i]; // see if the prediction matches the provided label var predicted_label = svm.Forward(x, y).Value > 0 ? 1 : -1; if (predicted_label == true_label) { num_correct++; } } double acc = (double)num_correct / data.Count; return(acc); }