# NOT RUN {
## "kknn"
s=mparheuristic("kknn",n="heuristic")
print(s)
s=mparheuristic("kknn",n=1) # same thing
print(s)
s=mparheuristic("kknn",n="heuristic5")
print(s)
s=mparheuristic("kknn",n=5) # same thing
print(s)
s=mparheuristic("kknn",lower=5,upper=15,by=2)
print(s)
# exponential scale:
s=mparheuristic("kknn",lower=1,upper=5,by=1,exponential=2)
print(s)
## "mlpe"
s=mparheuristic("mlpe")
print(s) # "NA" means set size with min(inputs/2,10) in fit
s=mparheuristic("mlpe",n="heuristic10")
print(s)
s=mparheuristic("mlpe",n=10) # same thing
print(s)
s=mparheuristic("mlpe",n=10,lower=2,upper=20)
print(s)
## "randomForest", upper should be set to the number of inputs = max mtry
s=mparheuristic("randomForest",n=10,upper=6)
print(s)
## "ksvm"
s=mparheuristic("ksvm",n=10)
print(s)
s=mparheuristic("ksvm",n=10,kernel="vanilladot")
print(s)
s=mparheuristic("ksvm",n=10,kernel="polydot")
print(s)
## lssvm
s=mparheuristic("lssvm",n=10)
print(s)
## rvm
s=mparheuristic("rvm",n=5)
print(s)
s=mparheuristic("rvm",n=5,kernel="vanilladot")
print(s)
## "rpart" and "ctree" are special cases (see help(fit,package=rminer) examples):
s=mparheuristic("rpart",n=3) # 3 cp values
print(s)
s=mparheuristic("ctree",n=3) # 3 mincriterion values
print(s)
### examples with fit
# }
# NOT RUN {
### classification
data(iris)
# ksvm and rbfdot:
model="ksvm";kernel="rbfdot"
s=mparheuristic(model,n="heuristic5",kernel=kernel)
print(s) # 5 sigma values
search=list(search=s,method=c("holdout",2/3,123))
# task "prob" is assumed, optimization of "AUC":
M=fit(Species~.,data=iris,model=model,search=search,fdebug=TRUE)
print(M@mpar)
# different lower and upper range:
s=mparheuristic(model,n=5,kernel=kernel,lower=-5,upper=1)
print(s) # from 2^-5 to 2^1
search=list(search=s,method=c("holdout",2/3,123))
# task "prob" is assumed, optimization of "AUC":
M=fit(Species~.,data=iris,model=model,search=search,fdebug=TRUE)
print(M@mpar)
# different exponential scale:
s=mparheuristic(model,n=5,kernel=kernel,lower=-4,upper=0,exponential=10)
print(s) # from 10^-5 to 10^1
search=list(search=s,method=c("holdout",2/3,123))
# task "prob" is assumed, optimization of "AUC":
M=fit(Species~.,data=iris,model=model,search=search,fdebug=TRUE)
print(M@mpar)
# "lssvm" Gaussian model, pure classification and ACC optimization, full iris:
model="lssvm";kernel="rbfdot"
s=mparheuristic("lssvm",n=3,kernel=kernel)
print(s)
search=list(search=s,method=c("holdout",2/3,123))
M=fit(Species~.,data=iris,model=model,search=search,fdebug=TRUE)
print(M@mpar)
# test several heuristic5 searches, full iris:
n="heuristic5";inputs=ncol(iris)-1
model=c("ctree","rpart","kknn","ksvm","lssvm","mlpe","randomForest")
for(i in 1:length(model))
{
cat("--- i:",i,"model:",model[i],"\n")
if(model[i]=="randomForest") s=mparheuristic(model[i],n=n,upper=inputs)
else s=mparheuristic(model[i],n=n)
print(s)
search=list(search=s,method=c("holdout",2/3,123))
M=fit(Species~.,data=iris,model=model[i],search=search,fdebug=TRUE)
print(M@mpar)
}
# test several Delgado 2014 searches (some cases launch warnings):
model=c("mlp","mlpe","mlp","ksvm","ksvm","ksvm",
"ksvm","lssvm","rpart","rpart","ctree",
"ctree","randomForest","kknn","kknn","multinom")
n=c("mlp_t","avNNet_t","nnet_t","svm_C","svmRadial_t","svmLinear_t",
"svmPoly_t","lsvmRadial_t","rpart_t","rpart2_t","ctree_t",
"ctree2_t","rf_t","knn_R","knn_t","multinom_t")
inputs=ncol(iris)-1
for(i in 1:length(model))
{
cat("--- i:",i,"model:",model[i],"heuristic:",n[i],"\n")
if(model[i]=="randomForest") s=mparheuristic(model[i],n=n[i],upper=inputs)
else s=mparheuristic(model[i],n=n[i])
print(s)
search=list(search=s,method=c("holdout",2/3,123))
M=fit(Species~.,data=iris,model=model[i],search=search,fdebug=TRUE)
print(M@mpar)
}
# }
# NOT RUN {
#dontrun
### regression
# }
# NOT RUN {
data(sa_ssin)
s=mparheuristic("ksvm",n=3,kernel="polydot")
print(s)
search=list(search=s,metric="MAE",method=c("holdout",2/3,123))
M=fit(y~.,data=sa_ssin,model="ksvm",search=search,fdebug=TRUE)
print(M@mpar)
# regression task, predict iris "Petal.Width":
data(iris)
ir2=iris[,1:4]
names(ir2)[ncol(ir2)]="y" # change output name
n=3;inputs=ncol(ir2)-1 # 3 hyperparameter searches
model=c("ctree","rpart","kknn","ksvm","mlpe","randomForest","rvm")
for(i in 1:length(model))
{
cat("--- i:",i,"model:",model[i],"\n")
if(model[i]=="randomForest") s=mparheuristic(model[i],n=n,upper=inputs)
else s=mparheuristic(model[i],n=n)
print(s)
search=list(search=s,method=c("holdout",2/3,123))
M=fit(y~.,data=ir2,model=model[i],search=search,fdebug=TRUE)
print(M@mpar)
}
# }
# NOT RUN {
#dontrun
### multiple model examples:
# }
# NOT RUN {
data(iris)
inputs=ncol(iris)-1; task="prob"
# 5 machine learning (ML) algorithms, 1 heuristic hyperparameter per algorithm:
sm=mparheuristic(model="automl",task=task,inputs=inputs)
print(sm)
# 5 ML with 10/13 hyperparameter searches:
sm=mparheuristic(model="automl2",task=task,inputs=inputs)
# note: mtry only has 4 searches due to the inputs limit:
print(sm)
# regression example:
ir2=iris[,1:4]
inputs=ncol(ir2)-1; task="reg"
sm=mparheuristic(model="automl2",task=task,inputs=inputs)
# note: ksvm contains 3 UD hyperparameters (and not 2) since task="reg":
print(sm)
# 5 ML and stacking:
inputs=ncol(iris)-1; task="prob"
sm=mparheuristic(model="automl3",task=task,inputs=inputs)
# note: $ls only has 5 elements, one for each individual ML
print(sm)
# other manual design examples: --------------------------------------
# 5 ML and three ensembles:
# the fit or mining functions will search for the best option
# between any of the 5 ML algorithms and any of the three
# ensemble approaches:
sm2=mparheuristic(model="automl3",task=task,inputs=inputs)
# note: ensembles need to be at the end of the $models field:
sm2$models=c(sm2$models,"AE","WE") # add AE and WE
sm2$smethod=c(sm2$smethod,rep("grid",2)) # add grid to AE and WE
# note: $ls only has 5 elements, one for each individual ML
print(sm2)
# 3 ML example:
models=c("cv.glmnet","mlpe","ksvm") # just 3 models
# note: in rminer the default cv.glmnet does not have "hyperparameters"
# since the cv automatically sets lambda
n=c(NA,10,"UD") # 10 searches for mlpe and 13 for ksvm
sm3=mparheuristic(model=models,n=n)
# note: $ls only has 5 elements, one for each individual ML
print(sm3)
# usage in sm2 and sm3 for fit (see mining help for usages in mining):
method=c("holdout",2/3,123)
d=iris
names(d)[ncol(d)]="y" # change output name
s2=list(search=sm2,smethod="auto",method=method,metric="AUC",convex=0)
M2=fit(y~.,data=d,model="auto",search=s2,fdebug=TRUE)
s3=list(search=sm3,smethod="auto",method=method,metric="AUC",convex=0)
M3=fit(y~.,data=d,model="auto",search=s3,fdebug=TRUE)
# -------------------------------------------------------------------
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab