### Typical use under rminer:
# 1st example, regression, 1-D sensitivity analysis
data(sin1reg) # x1 should account for 70%, x2 for 30% and x3 for 0%.
M=fit(y~.,sin1reg,model="svm")
I=Importance(M,sin1reg,method="sens",measure="gradient") # 1-D SA
print(I)
L=list(runs=1,sen=t(I$imp),sresponses=I$sresponses)
mgraph(L,graph="IMP",leg=names(sin1reg),col="gray",Grid=10)
mgraph(L,graph="VEC",xval=1,Grid=10,data=sin1reg) # or:
vecplot(I,xval=1,Grid=10,data=sin1reg,datacol="gray") # the same graph
vecplot(I,xval=c(1,2,3),pch=c(1,2,3),Grid=10,
leg=list(pos="bottomright",leg=c("x1","x2","x3"))) # all x1, x2 and x3 VEC curves
# 2nd example, regression, 2-D sensitivity analysis with
# the most relevant input (x1, index 1):
I2=Importance(M,sin1reg,method="sensg",interactions=which.max(I$imp))
print(I2)
# influence of x1 and x2 over y
vecplot(I2,graph="VEC3",xval=2) # VEC surface
vecplot(I2,graph="VECC",xval=2) # VEC contour
# influence of x1 and x3 over y (influence of x3 is small random noise, 0%):
vecplot(I2,graph="VEC3",xval=3)
vecplot(I2,graph="VECC",xval=3)
# 3rd example, regression, full 3-D sensitivity analysis
I3=Importance(M,sin1reg,method="sensg",interactions=c(1,2,3))
print(I3)
I3_1d=avg_imp(I3,c(1)) # 1-D averaging under x1
vecplot(I3_1d,graph="VEC",xval=1,Grid=10)
I3_2d=avg_imp(I3,c(1,2)) # 2-D averaging under the pair x1,x2
vecplot(I3_2d,graph="VEC3")
### If you want to use Importance over your own model:
# 1st example, regression, uses the theoretical sin1reg function
mypred=function(M,data)
{ return (M[1]*sin(pi*data[,1]/M[3])+M[2]*sin(pi*data[,2]/M[3])) }
M=c(0.7,0.3,2000)
# 4 is the column index of y
I=Importance(M,sin1reg,method="sens",measure="gradient",PRED=mypred,outindex=4)
print(I$imp) # x1=72.3% and x2=27.7%
L=list(runs=1,sen=t(I$imp),sresponses=I$sresponses)
mgraph(L,graph="IMP",leg=names(sin1reg),col="gray",Grid=10)
mgraph(L,graph="VEC",xval=1,Grid=10) # equal to:
vecplot(I,graph="VEC",xval=1,Grid=10)
# 2nd example, 3-class classification for iris and lda model:
data(iris)
library(MASS)
predlda=function(M,data) # the PRED function
{ return (predict(M,data)$posterior) }
LDA=lda(Species ~ .,iris, prior = c(1,1,1)/3)
# 4 is the column index of Species
I=Importance(LDA,iris,method="sensg",PRED=predlda,outindex=4)
vecplot(I,graph="VEC",xval=1,Grid=10,TC=1,
main="1-D VEC for Sepal.Lenght (x-axis) influence in setosa (prob.)")
# 3rd example, binary classification for setosa iris and lda model:
iris2=iris;iris2$Species=factor(iris$Species=="setosa")
predlda2=function(M,data) # the PRED function
{ return (predict(M,data)$class) }
LDA2=lda(Species ~ .,iris2)
I=Importance(LDA2,iris2,method="sensg",PRED=predlda2,outindex=4)
vecplot(I,graph="VEC",xval=1,
main="1-D VEC for Sepal.Lenght (x-axis) influence in setosa (class)",Grid=10)
Run the code above in your browser using DataLab