[R] Re: visualizing a list of probabilities

Martin Keller-Ressel martin at ist.org
Tue Jun 22 16:36:35 CEST 2004


If the input variables to your network are continuous you can visualize 
the relationship
between two input variables and the resulting output (class probability)
with image() or persp().

Here is an example (you need the mlbench package from CRAN to run this):

library(mlbench)
x <- as.data.frame(mlbench.spirals(400,cycles=1.5,sd=.1))
plot(x$x.1,x$x.2,col=unclass(x$classes))

nn1 <- nnet(classes ~ x.1 + x.2, data = x, size=20)
xval <- seq(-1.5,1.5,length=100)
map <- outer(xval,xval,FUN=function(x,y) 
{predict(nn1,data.frame(x.1=x,x.2=y))})
image(map)
par("usr"=c(-1.5,1.5,-1.5,1.5))
points(x$x.1,x$x.2,pch=as.numeric(x$classes)+15,col=as.numeric(x$classes)+4)

### or use:

persp(z=map,expand=.3,shade=.7,col="orange",phi=45,theta=180)


If you have more than 2 input variables you can keep the other ones at 
fixed levels and see what happens.

hth,

Martin Keller-Ressel




More information about the R-help mailing list