# NOT RUN {
## Set up Sonar data with 20% labeled
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)
y.true<-Sonar$Class
Sonar$Class[U]=NA
g.agraph1<-agraph(Class~.,data=Sonar)
##The following gives an equivalent output to the g.agraph1<-agraph(Class~.,data=Sonar) call.
# }
# NOT RUN {
ctrl<-SemiSupervised.control()
g<-AnchorGraph(x.scaleL(Sonar[,-p],L),control=ctrl)
g.agraph2<-agraph(Class~.+aG(g),data=Sonar,control=ctrl)
## For performance comparison check against agraph with graph only
tab=table(fitted(g.agraph2)[U],y.true[U])
1-sum(diag(tab))/sum(tab)
## Fit agraph to Sonar but graph only
g.agraph3<-agraph(Class~aG(g),data=Sonar,control=ctrl)
g.agraph3
tab=table(fitted(g.agraph3)[U],y.true[U])
1-sum(diag(tab))/sum(tab)
# }
Run the code above in your browser using DataLab