Browse code

Parameter tuning in .doTrain fixed. - drop FALSE added to crossValidate.

Dario Strbenac authored on 30/06/2022 03:50:02
Showing 2 changed files

... ...
@@ -162,7 +162,7 @@ setMethod("crossValidate", "DataFrame",
162 162
                                   # Loop over classifiers
163 163
                                   set.seed(seed)
164 164
                                   CV(
165
-                                      measurements = measurements[, mcols(measurements)$dataset == dataIndex],
165
+                                      measurements = measurements[, mcols(measurements)$dataset == dataIndex, drop = FALSE],
166 166
                                       classes = classes,
167 167
                                       nFeatures = nFeatures[dataIndex],
168 168
                                       selectionMethod = selectionIndex,
... ...
@@ -440,11 +440,14 @@
440 440
   tuneChosen <- NULL
441 441
   if(!is.null(modellingParams@trainParams@tuneParams) && is.null(modellingParams@selectParams@tuneParams))
442 442
   {
443
+    performanceType <- modellingParams@trainParams@tuneParams[["performanceType"]]
444
+    modellingParams@trainParams@tuneParams <- modellingParams@trainParams@tuneParams[-match("performanceType", names(modellingParams@trainParams@tuneParams))]
443 445
     tuneCombos <- expand.grid(modellingParams@trainParams@tuneParams, stringsAsFactors = FALSE)
444 446
     modellingParams@trainParams@tuneParams <- NULL
445 447
     
446 448
     performances <- sapply(1:nrow(tuneCombos), function(rowIndex)
447 449
     {
450
+      modellingParams@trainParams@otherParams <- c(modellingParams@trainParams@otherParams, as.list(tuneCombos[rowIndex, ]))
448 451
       if(crossValParams@tuneMode == "Resubstitution")
449 452
       {
450 453
         result <- runTest(measurementsTrain, outcomesTrain, measurementsTest, outcomesTest,
... ...
@@ -456,13 +459,13 @@
456 459
           predictedOutcomes <- predictions[, "outcome"]
457 460
         else
458 461
           predictedOutcomes <- predictions
459
-        calcExternalPerformance(outcomesTest, predictedOutcomes, performanceName)
462
+        calcExternalPerformance(outcomesTest, predictedOutcomes, performanceType)
460 463
       } else {
461 464
         result <- runTests(measurementsTrain, outcomesTrain,
462 465
                            crossValParams, modellingParams,
463 466
                            verbose = verbose, .iteration = "internal")
464
-        result <- calcCVperformance(result, performanceName)
465
-        median(predictions(result)["performanceType"])
467
+        result <- calcCVperformance(result, performanceType)
468
+        median(performances(result)[[performanceType]])
466 469
       }
467 470
     })
468 471
     betterValues <- .ClassifyRenvir[["performanceInfoTable"]][.ClassifyRenvir[["performanceInfoTable"]][, "type"] == performanceType, "better"]