From 6778d00dbf345a4a905035b216185d9c97fb5bf3 Mon Sep 17 00:00:00 2001 From: Mike J Innes Date: Mon, 1 May 2017 13:46:23 +0100 Subject: [PATCH] this is no longer specific to training --- src/utils.jl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/utils.jl b/src/utils.jl index 48af20a7..daac39cf 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -15,3 +15,14 @@ mapt(f, xs::Tuple) = map(x -> mapt(f, x), xs) convertel(T::Type, xs::AbstractArray) = convert.(T, xs) convertel{T}(::Type{T}, xs::AbstractArray{T}) = xs + +function accuracy(m, data) + n = 0 + correct = 0 + for (x, y) in data + x, y = tobatch.((x, y)) + n += size(x, 1) + correct += sum(onecold(m(x)) .== onecold(y)) + end + return correct/n +end