Last active
January 2, 2016 16:24
-
-
Save primaryobjects/14fdc4efda1a0e24420c to your computer and use it in GitHub Desktop.
Neural Network Sort helper method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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