@@ -407,30 +407,61 @@ fit_model <- function(obj, roi_x, y, wts, param, lev=NULL, last=FALSE, classProb
407
407
UseMethod(" fit_model" )
408
408
}
409
409
410
- # ' Tune Grid Extraction
410
+ # ' Extract Tuning Grid
411
411
# '
412
- # ' Extract the parameter grid to optimize for a model.
412
+ # ' Returns the parameter grid used to tune a model.
413
413
# '
414
- # ' @param obj The model object.
415
- # ' @param x The training data.
416
- # ' @param y The response vector.
417
- # ' @param len The number of elements in the tuning grid.
418
- tune_grid <- function (obj , x ,y ,len ) {
414
+ # ' @param obj A model or model specification.
415
+ # ' @param x Training data.
416
+ # ' @param y Response variable.
417
+ # ' @param len Number of parameter sets to generate.
418
+ # '
419
+ # ' @return A data frame of tuning parameter combinations.
420
+ # ' @rdname tune_grid-methods
421
+ # ' @export
422
+ # '
423
+ # ' @examples
424
+ # ' ds <- gen_sample_dataset(D = c(5, 5, 5), nobs = 10)
425
+ # ' mdl <- load_model("sda_notune")
426
+ # ' tune_grid(mdl, ds$dataset$train_data, ds$design$y_train, len = 1)
427
+ tune_grid <- function (obj , x , y , len ) {
419
428
UseMethod(" tune_grid" )
420
429
}
421
430
422
431
# ' Test Set Availability
423
432
# '
424
- # ' Check if an object has a test set available.
433
+ # ' Determine whether the object contains a separate test set.
434
+ # '
435
+ # ' @param obj Object to query.
425
436
# '
426
- # ' @param obj The object to check for a test set.
437
+ # ' @return Logical indicating if a test set exists.
438
+ # ' @rdname has_test_set-methods
427
439
# ' @export
440
+ # '
441
+ # ' @examples
442
+ # ' ds <- gen_sample_dataset(D = c(4, 4, 4), nobs = 10, external_test = TRUE)
443
+ # ' has_test_set(ds$design)
428
444
has_test_set <- function (obj ) {
429
445
UseMethod(" has_test_set" )
430
446
}
431
447
432
- # ' Requires cross-validation to be performed
433
- # ' @param obj The model object.
448
+ # ' Cross-Validation Availability
449
+ # '
450
+ # ' Determine whether cross-validation is specified for the object.
451
+ # '
452
+ # ' @param obj Model specification object.
453
+ # '
454
+ # ' @return Logical indicating if cross-validation will be performed.
455
+ # ' @rdname has_crossval-methods
456
+ # ' @export
457
+ # '
458
+ # ' @examples
459
+ # ' ds <- gen_sample_dataset(D = c(4, 4, 4), nobs = 10)
460
+ # ' cval <- blocked_cross_validation(ds$design$block_var)
461
+ # ' mdl <- load_model("sda_notune")
462
+ # ' mspec <- mvpa_model(mdl, ds$dataset, ds$design,
463
+ # ' "classification", crossval = cval)
464
+ # ' has_crossval(mspec)
434
465
has_crossval <- function (obj ) {
435
466
UseMethod(" has_crossval" )
436
467
}
@@ -442,25 +473,37 @@ has_crossval.default <- function(obj) {
442
473
443
474
# ' Compute Performance Metrics
444
475
# '
445
- # ' Compute performance metrics (accuracy, AUC, RMSE, etc.) for classification/regression results .
476
+ # ' Generic function to compute performance metrics from result objects .
446
477
# '
447
- # ' @param x The classification/regression result object to evaluate .
448
- # ' @param ... Additional arguments passed to method-specific performance functions .
478
+ # ' @param x Result object from a classification or regression analysis .
479
+ # ' @param ... Additional arguments passed to methods .
449
480
# '
450
- # ' @return A list of performance metrics.
481
+ # ' @return Named numeric vector of performance metrics.
482
+ # ' @rdname performance-methods
451
483
# ' @export
452
- performance <- function (x ,... ) {
484
+ # '
485
+ # ' @examples
486
+ # ' cres <- binary_classification_result(
487
+ # ' observed = factor(c("a", "b")),
488
+ # ' predicted = factor(c("a", "b")),
489
+ # ' probs = matrix(c(0.8, 0.2, 0.3, 0.7), ncol = 2,
490
+ # ' dimnames = list(NULL, c("a", "b")))
491
+ # ' )
492
+ # ' performance(cres)
493
+ performance <- function (x , ... ) {
453
494
UseMethod(" performance" )
454
495
}
455
496
456
497
# ' Compute Performance for an Object
457
498
# '
458
499
# ' Delegates calculation of performance metrics to the appropriate method.
459
500
# '
460
- # ' @param obj The input object.
461
- # ' @param result The classification/regression result object to evaluate.
501
+ # ' @param obj Model specification or object capable of computing performance .
502
+ # ' @param result The classification/regression result to evaluate.
462
503
# '
463
- # ' @return A list of performance metrics.
504
+ # ' @return Named numeric vector of performance metrics.
505
+ # ' @rdname compute_performance-methods
506
+ # ' @export
464
507
# '
465
508
# ' @examples
466
509
# ' cres <- binary_classification_result(
@@ -472,7 +515,6 @@ performance <- function(x,...) {
472
515
# ' dummy <- list(performance = performance)
473
516
# ' class(dummy) <- "mvpa_model"
474
517
# ' compute_performance(dummy, cres)
475
- # ' @export
476
518
compute_performance <- function (obj , result ) {
477
519
UseMethod(" compute_performance" )
478
520
}
0 commit comments