# NOT RUN {
## Prediction depends on the nature of the call. Consider some examples.
library(mlbench)
data(Sonar)
n=dim(Sonar)[1]
p=dim(Sonar)[2]
nu=0.2
set.seed(100)
L=sort(sample(1:n,ceiling(nu*n)))
U=setdiff(1:n,L)
U1=sample(U,ceiling(0.5*n))
y.true<-Sonar$Class
Sonar$Class[U]=NA
## Typical, call to s4pm and predict
g.s4pm<-s4pm(Class~.,data=Sonar[c(L,U1),])
p.s4pm<-predict(g.s4pm,xnew=Sonar[U,-p])
tab=table(y.true[U],p.s4pm)
1-sum(diag(tab))/sum(tab)
# }
# NOT RUN {
## Predict the graph only case
Dij<-x.scaleL(Sonar[,-p],L)
Dij<-as.matrix(cosineDist(Dij))
Dij1<-Dij[c(L,U1),c(L,U1)]
attr(Dij1,"metric")=attr(Dij,"metric")
attr(Dij1,"distance.graph")=attr(Dij,"distance.graph")
g.s4pm<-s4pm(Class~dG(Dij1),data=Sonar[c(L,U1),])
p.s4pm<-predict(g.s4pm,gnew=Dij[U,c(L,U1)])
tab=table(y.true[U],p.s4pm)
1-sum(diag(tab))/sum(tab)
# }
Run the code above in your browser using DataLab