Instantly share code, notes, and snippets.

Embed
What would you like to do?
Neural Network Sort helper method
# See also https://gist.github.com/primaryobjects/5a28e0c27fd433123f1a
# fit: Trained neural network. scaleVal: Original scaled data used in training the network. a, b, c: Numbers to sort.
nnsort <- function(fit, scaleVal, a, b, c) {
numbers <- data.frame(a=a, b=b, c=c, x=0, y=0, z=0)
numbersScaled <- as.data.frame(scale(numbers, attr(scaleVal, 'scaled:center'), attr(scaleVal, 'scaled:scale')))
round(unscale(compute(fit, numbersScaled[,1:3])$net.result, scaleVal))[,4:6]
}
# Example usage:
> nnsort(fit, data, 100, 20, 32)
x y z
20 32 100
> nnsort(fit, data, 37, 6, 4)
x y z
4 6 37
> nnsort(fit, data, 78, 1, 12)
x y z
1 12 78
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment