# NOT RUN {
# }
# NOT RUN {
### Binary Classification Example ####
# Start the graphics device driver to save all plots in a pdf format
pdf(file = "BinaryClassificationExample.pdf",width = 8, height = 6)
# Get the stage C prostate cancer data from the rpart package
data(stagec,package = "rpart")
# Prepare the data. Create a model matrix without the event time
stagec$pgtime <- NULL
stagec$eet <- as.factor(stagec$eet)
options(na.action = 'na.pass')
stagec_mat <- cbind(pgstat = stagec$pgstat,
as.data.frame(model.matrix(pgstat ~ .,stagec))[-1])
# Impute the missing data
dataCancerImputed <- nearestNeighborImpute(stagec_mat)
dataCancerImputed[,1:ncol(dataCancerImputed)] <- sapply(dataCancerImputed,as.numeric)
# Cross validating a LDA classifier.
# 80<!-- % Train and 20% test repeated 10 times -->
cv <- randomCV(dataCancerImputed,"pgstat",MASS::lda,trainFraction = 0.8,
repetitions = 10,featureSelectionFunction = univariate_tstudent,
featureSelection.control = list(limit = 0.5,thr = 0.975));
# Compare the LDA classifier with other methods
cp <- BinaryBenchmark(referenceCV = cv,referenceName = "LDA",
referenceFilterName="t.Student")
pl <- plot(cp,prefix = "StageC: ")
# Default Benchmark classifiers method (BSWiMS) and filter methods.
# 80<!-- % Train Repeated 10 times -->
cp <- BinaryBenchmark(theData = dataCancerImputed,
theOutcome = "pgstat", reps = 10, fraction = 0.8)
# plot the Cross Validation Metrics
pl <- plot(cp,prefix = "Stagec:");
# Shut down the graphics device driver
dev.off()
#### Regression Example ######
# Start the graphics device driver to save all plots in a pdf format
pdf(file = "RegressionExample.pdf",width=8, height=6)
# Get the body fat data from the TH package
data("bodyfat", package = "TH.data")
# Benchmark regression methods and filter methods.
#80<!-- % Train Repeated 10 times -->
cp <- RegresionBenchmark(theData = bodyfat,
theOutcome = "DEXfat", reps = 10, fraction = 0.8)
# plot the Cross Validation Metrics
pl <- plot(cp,prefix = "Body Fat:");
# Shut down the graphics device driver
dev.off()
#### Ordinal Regression Example #####
# Start the graphics device driver to save all plots in a pdf format
pdf(file = "OrdinalRegressionExample.pdf",width=8, height=6)
# Get the GBSG2 data
data("GBSG2", package = "TH.data")
# Prepare the model frame for benchmarking
GBSG2$time <- NULL;
GBSG2$cens <- NULL;
GBSG2_mat <- cbind(tgrade = as.numeric(GBSG2$tgrade),
as.data.frame(model.matrix(tgrade~.,GBSG2))[-1])
# Benchmark regression methods and filter methods.
#30<!-- % Train Repeated 10 times -->
cp <- OrdinalBenchmark(theData = GBSG2_mat,
theOutcome = "tgrade", reps = 10, fraction = 0.3)
# plot the Cross Validation Metrics
pl <- plot(cp,prefix = "GBSG:");
# Shut down the graphics device driver
dev.off()
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab