context("Machine Learning SVM Regression")
# Test fixed model #############################################################
options <- initMlOptions("mlRegressionSvm")
options$target <- "Sepal.Length"
options$target.types <- "scale"
options$predictors <- c("Sepal.Width", "Petal.Length", "Petal.Width")
options$predictors.types <- rep("scale", 3)
options$modelOptimization <- "manual"
options$holdoutData <- "holdoutManual"
options$modelValid <- "validationManual"
options$savePath <- ""
options$predictionsColumn <- ""
options$testIndicatorColumn <- ""
options$testSetIndicatorVariable <- ""
options$dataSplitPlot <- FALSE
options$setSeed <- TRUE
set.seed(1)
results <- jaspTools::runAnalysis("mlRegressionSvm", "iris.csv", options)
table <- results[["results"]][["regressionTable"]][["data"]]
jaspTools::expect_equal_tables(table,
list(1, 30, 120, 0.082058421211194, 117))
# Test optimized model #########################################################
options <- initMlOptions("mlRegressionSvm")
options$target <- "Sepal.Length"
options$target.types <- "scale"
options$predictors <- c("Sepal.Width", "Petal.Length", "Petal.Width")
options$predictors.types <- rep("scale", 3)
options$validationMeasures <- TRUE
options$supportVectorsTable <- TRUE
options$predictedPerformancePlot <- TRUE
options$modelOptimization <- "optimized"
options$addIndicator <- FALSE
options$addPredictions <- FALSE
options$holdoutData <- "holdoutManual"
options$modelValid <- "validationManual"
options$noOfFolds <- 5
options$predictionsColumn <- ""
options$saveModel <- FALSE
options$savePath <- ""
options$setSeed <- TRUE
options$testDataManual <- 0.2
options$testIndicatorColumn <- ""
options$testSetIndicatorVariable <- ""
options$validationDataManual <- 0.2
options$tableShap <- TRUE
options$fromIndex <- 1
options$toIndex <- 5
options$featureImportanceTable <- TRUE
options$optimPlot <- TRUE
set.seed(1)
results <- jaspTools::runAnalysis("mlRegressionSvm", "iris.csv", options)
test_that("Feature Importance Metrics table results match", {
table <- results[["results"]][["featureImportanceTable"]][["data"]]
jaspTools::expect_equal_tables(table,
list(1.75777339483526, "Petal.Length", 0.651769817049865, "Petal.Width",
0.499354093712062, "Sepal.Width"))
})
test_that("Mean Squared Error Plot matches", {
skip("Does not reproduce on machine KD <-> GitHub Actions")
plotName <- results[["results"]][["optimPlot"]][["data"]]
testPlot <- results[["state"]][["figures"]][[plotName]][["obj"]]
jaspTools::expect_equal_plots(testPlot, "mean-squared-error-plot")
})
test_that("Data Split plot matches", {
plotName <- results[["results"]][["plotDataSplit"]][["data"]]
testPlot <- results[["state"]][["figures"]][[plotName]][["obj"]]
jaspTools::expect_equal_plots(testPlot, "data-split")
})
test_that("Predictive Performance Plot matches", {
plotName <- results[["results"]][["predictedPerformancePlot"]][["data"]]
testPlot <- results[["state"]][["figures"]][[plotName]][["obj"]]
jaspTools::expect_equal_plots(testPlot, "predictive-performance-plot")
})
test_that("Support Vector Machine Regression table results match", {
table <- results[["results"]][["regressionTable"]][["data"]]
jaspTools::expect_equal_tables(table,
list(1.3, 30, 96, 24, 0.078579272419928, 0.0630630181540719, 95))
})
test_that("Support Vectors table results match", {
table <- results[["results"]][["supportVectorsTable"]][["data"]]
jaspTools::expect_equal_tables(table,
list(-1.27910398223806, -1.31105214820513, 0.786173830160854, 1, 0.42032557786565,
0.132067294448948, -0.590395133155819, 2, 0.42032557786565,
0.394452647658781, -0.131538812050262, 3, -1.22245633023461,
-1.31105214820513, 0.327317509055296, 4, 1.32668800992096, 0.919223354078446,
-0.590395133155819, 5, 1.04344974990368, 1.57518673710303, 0.786173830160854,
6, 0.250382621855279, 0.132067294448948, -0.819823293708598,
7, -1.33575163424152, -1.31105214820513, -0.36096697260304,
8, -1.33575163424152, -1.31105214820513, 0.786173830160854,
9, -1.05251337422423, -1.31105214820513, 0.786173830160854,
10, 0.760211489886394, 0.919223354078446, -0.819823293708598,
11, 0.646916185879479, 0.394452647658781, 0.0978893485025173,
12, 1.15674505391059, 1.3128013838932, -0.131538812050262, 13,
0.193734969851822, -0.261510735365801, -0.819823293708598, 14,
0.250382621855279, 0.132067294448948, -0.36096697260304, 15,
1.49663096593134, 1.05041603068336, 1.70388647237197, 16, 0.533620881872565,
0.263259971053865, 0.327317509055296, 17, 0.760211489886394,
0.919223354078446, -0.819823293708598, 18, -1.27910398223806,
-1.31105214820513, 1.01560199071363, 19, 0.760211489886394,
0.525645324263697, -0.819823293708598, 20, -1.33575163424152,
-1.31105214820513, 2.62159911458308, 21, -1.33575163424152,
-1.31105214820513, -0.131538812050262, 22, -1.33575163424152,
-1.31105214820513, 0.327317509055296, 23, 0.42032557786565,
0.656838000868614, -1.27867961481416, 24, -1.39239928624498,
-1.17985947160021, -1.73753593591971, 25, -0.259446246175835,
-0.261510735365801, -1.50810777536693, 26, 0.137087317848365,
0.132067294448948, -0.590395133155819, 27, 0.476973229869108,
0.132067294448948, -0.36096697260304, 28, -1.27910398223806,
-1.0486667949953, 1.47445831181919, 29, 0.250382621855279, 0.000874617844032097,
-0.131538812050262, 30, 0.590268533876022, 0.263259971053865,
-0.590395133155819, 31, 0.363677925862193, 0.000874617844032097,
-1.04925145426138, 32, -1.33575163424152, -1.44224482481005,
-0.131538812050262, 33, -1.33575163424152, -1.17985947160021,
-0.131538812050262, 35, 0.703563837882936, 1.05041603068336,
-1.27867961481416, 36, 0.590268533876022, 0.78803067747353,
0.327317509055296, 37, 0.81685914188985, 1.05041603068336, -0.131538812050262,
38, 0.0804396658449078, 0.263259971053865, -0.819823293708598,
39, 0.533620881872565, 0.525645324263697, 0.556745669608075,
40, 0.0804396658449078, 0.000874617844032097, -0.819823293708598,
41, -1.39239928624498, -1.31105214820513, 0.327317509055296,
42, -1.33575163424152, -1.31105214820513, 0.556745669608075,
43, 0.307030273858736, 0.132067294448948, -0.36096697260304,
44, 0.0804396658449078, -0.130318058760884, -1.27867961481416,
45, 1.66657392194171, 1.05041603068336, -0.590395133155819,
46, -1.16580867823115, -0.917474118390382, 0.556745669608075,
47, -1.27910398223806, -1.44224482481005, 0.0978893485025173,
48, 0.81685914188985, 1.44399406049811, -0.131538812050262,
49, 1.32668800992096, 1.44399406049811, -0.131538812050262,
50, -1.22245633023461, -1.0486667949953, 0.786173830160854,
51, 0.930154445896765, 1.44399406049811, 0.786173830160854,
52, 0.986802097900222, 0.78803067747353, -0.131538812050262,
53, 0.533620881872565, 0.263259971053865, -0.36096697260304,
54, 1.15674505391059, 0.78803067747353, -1.27867961481416, 55,
1.04344974990368, 1.18160870728828, -0.590395133155819, 56,
0.42032557786565, 0.394452647658781, -0.131538812050262, 57,
-0.146150942168921, -0.261510735365801, -1.04925145426138, 58,
-1.22245633023461, -1.31105214820513, -0.131538812050262, 59,
-1.39239928624498, -1.31105214820513, 1.01560199071363, 60,
0.42032557786565, 0.394452647658781, -0.36096697260304, 61,
0.760211489886394, 1.44399406049811, 0.0978893485025173, 62,
0.533620881872565, 0.394452647658781, 0.0978893485025173, 63,
-0.429389202186207, -0.130318058760884, -1.27867961481416, 64,
0.42032557786565, 0.394452647658781, -1.96696409647249, 65,
-1.22245633023461, -1.31105214820513, 0.0978893485025173, 66,
1.21339270591405, 1.18160870728828, -0.131538812050262, 67,
0.703563837882936, 0.656838000868614, -0.131538812050262, 68,
1.43998331392788, 0.78803067747353, -0.36096697260304, 69, 0.0237920138414506,
-0.130318058760884, -1.50810777536693, 70, -1.50569459025189,
-1.44224482481005, -0.131538812050262, 71, 0.760211489886394,
1.05041603068336, 0.327317509055296, 72, 0.590268533876022,
0.78803067747353, -0.590395133155819, 73, 1.04344974990368,
1.57518673710303, 0.0978893485025173, 74, -1.44904693824843,
-1.31105214820513, 2.16274279347753, 75, -1.27910398223806,
-1.31105214820513, 0.0978893485025173, 76, 1.32668800992096,
1.70637941370794, 1.24503015126641, 77, 0.363677925862193, 0.263259971053865,
0.0978893485025173, 78, -1.22245633023461, -0.786281441785466,
1.01560199071363, 79, 1.77986922594862, 1.44399406049811, -1.04925145426138,
80, 0.590268533876022, 0.78803067747353, -0.131538812050262,
81, 1.10009740190714, 1.70637941370794, 0.556745669608075, 82,
1.27004035791751, 1.70637941370794, 0.556745669608075, 83, -1.33575163424152,
-1.17985947160021, 1.01560199071363, 84, 0.986802097900222,
1.18160870728828, -0.131538812050262, 85, -1.22245633023461,
-1.31105214820513, 1.70388647237197, 86, -0.259446246175835,
-0.261510735365801, -1.73753593591971, 87, 0.986802097900222,
0.78803067747353, 0.0978893485025173, 88, -1.16580867823115,
-1.31105214820513, 0.786173830160854, 89, -1.39239928624498,
-1.31105214820513, -0.131538812050262, 90, 0.137087317848365,
0.132067294448948, -1.73753593591971, 91, 0.760211489886394,
0.78803067747353, -0.131538812050262, 92, 0.476973229869108,
0.394452647658781, -0.590395133155819, 93, -1.33575163424152,
-1.31105214820513, 1.01560199071363, 94, 0.646916185879479,
0.78803067747353, -0.131538812050262, 95, 1.66657392194171,
1.3128013838932, 1.70388647237197, 96))
})
test_that("Additive Explanations for Predictions of Test Set Cases table results match", {
table <- results[["results"]][["tableShap"]][["data"]]
jaspTools::expect_equal_tables(table,
list(-1.68717959496207, 0.536808197400473, 0.39212324794155, 5.88492763855368,
1, 5.12667948893364, -1.61790275958296, 0.53680819740048, 0.459827981399075,
5.88492763855368, 2, 5.26366105777028, -1.54862592420385, 0.536808197400479,
0.256713781026471, 5.88492763855368, 3, 5.12982369277679, -1.75645643034118,
0.433118887641029, 0.595237448314155, 5.88492763855368, 4, 5.15682754416768,
-1.47934908882474, 0.484963542520762, 0.527532714856622, 5.88492763855368,
5, 5.41807480710632))
})
test_that("Model Performance Metrics table results match", {
table <- results[["results"]][["validationMeasures"]][["data"]]
jaspTools::expect_equal_tables(table,
list("Values", 0.233880681803325, 0.0405178555867029, 0.0785792724199296,
0.14900759463868, 0.851794443398157, 0.280319946525269))
})
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.