How can I visualize insight in 2 predictors from a NN for a specific range of a third predictor

How can I visualize insight in 2 predictors from a NN for a specific range of a third predictor



I have fitted a neuralnet based on 3 variables: x1, x2, x3 generating predictions y.
I would like to construct a matrix based on x1, x3 and the average prediction y for each combination while x2 is within range 0-25. (next I would like to make a similar matrix for x2 in range 26-50, 51-75 and 76-100.



I have made many attempts with dplyr and solutions based on pivottables in R although I do not succeed.



Currently I have the code below:


library(nnet)
library(caret)
library(dplyr)

x <- mydata[,2:4]
y <- mydata[,5]

parti <- createDataPartition(y, times = 1, p=0.8, list = FALSE)

x_train <- x[parti,]
x_test <- x[-parti,]
y_train <- y[parti]
y_test <- y[-parti]

fit <- nnet(y_train~., x_train, size=12, maxit=500, linout=T, decay=0.01)

x1 <- seq(0,100,10)
x2 <- seq(0,100,10)
x3 <- seq(0,100,10)

my_grid <- expand.grid(x1=x1, x2=x2, x3=x3)

predictions <- predict(fit ,my_grid, type="raw")
testResults <- data.frame(my_grid, y = predictions)

plot(testResults)

myMatrix <- testResults %>% filter(x2>0 & x2<25) %>% group_by(x1) %>% group_by(x3) %>% summarize(y=average(y))



This code generates the folowing table:


A tibble: 11 x 2
x3 y
<dbl> <dbl>
1 0 18.5
2 10 -19.2
3 20 -2.93
4 30 10.4
5 40 10.9
6 50 4.42
7 60 0.511
8 70 0.0232
9 80 -3.67
10 90 -7.26
11 100 -8.37



Although the outcome I am looking for is something like


x3 ->
x1 0 10 30 40 50 60 70 80 90 100
1 0 18.5 12 7 5
2 10 -19.2 1 3 2
3 20 -2.93 22 1 etc
4 30 10.4 3 7
5 40 10.9 4 3
6 50 4.42 5 2
7 60 0.511 3 1
8 70 0.02324 9
9 80 -3.67 5 2
10 90 -7.26 5 5
11 100 -8.37 -1 0



Based on this matrix I would like to generate a heatmap.



Thanks!




1 Answer
1


vb = testResults[testResults$x2 > 0 & testResults$x2 <= 25,]
vb = dcast(vb, x1~x3, value.var=y, fun.aggregate=mean)



Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)