R 对于第三个预测器的特定范围,如何从NN中可视化两个预测器的洞察

R 对于第三个预测器的特定范围,如何从NN中可视化两个预测器的洞察,r,R,我已经拟合了一个基于3个变量的神经网络:x1,x2,x3生成预测y。 我想根据x1、x3和每个组合的平均预测y构建一个矩阵,而x2在0-25范围内。(接下来,我想为x2制作一个类似的矩阵,范围为26-50、51-75和76-100 我曾多次尝试使用dplyr和基于R中数据透视表的解决方案,但没有成功 目前我的代码如下: library(nnet) library(caret) library(dplyr) x <- mydata[,2:4] y <- mydata[,5] par

我已经拟合了一个基于3个变量的神经网络:x1,x2,x3生成预测y。 我想根据x1、x3和每个组合的平均预测y构建一个矩阵,而x2在0-25范围内。(接下来,我想为x2制作一个类似的矩阵,范围为26-50、51-75和76-100

我曾多次尝试使用dplyr和基于R中数据透视表的解决方案,但没有成功

目前我的代码如下:

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))
根据这个矩阵,我想生成一个热图

谢谢!

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