-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'set_fallback' into featureless_quantiles
- Loading branch information
Showing
25 changed files
with
486 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#' @title Create a Fallback Learner | ||
#' | ||
#' @description | ||
#' Create a fallback learner for a given learner. | ||
#' The function searches for a suitable fallback learner based on the task type. | ||
#' Additional checks are performed to ensure that the fallback learner supports the predict type. | ||
#' | ||
#' @param learner [Learner]\cr | ||
#' The learner for which a fallback learner should be created. | ||
#' @param ... `any`\cr | ||
#' ignored. | ||
#' | ||
#' @return [Learner] | ||
default_fallback = function(learner, ...) { | ||
UseMethod("default_fallback") | ||
} | ||
|
||
#' @rdname default_fallback | ||
#' @export | ||
default_fallback.Learner = function(learner, ...) { | ||
# FIXME: remove when new encapsulate/fallback system is in place | ||
return(NULL) | ||
} | ||
|
||
#' @rdname default_fallback | ||
#' @export | ||
default_fallback.LearnerClassif = function(learner) { | ||
fallback = lrn("classif.featureless") | ||
|
||
# set predict type | ||
if (learner$predict_type %nin% fallback$predict_types) { | ||
stopf("Fallback learner '%s' does not support predict type '%s'.", fallback_id, learner$predict_type) | ||
} | ||
|
||
fallback$predict_type = learner$predict_type | ||
|
||
return(fallback) | ||
} | ||
|
||
#' @rdname default_fallback | ||
#' @export | ||
default_fallback.LearnerRegr = function(learner) { | ||
fallback = lrn("regr.featureless") | ||
|
||
# set predict type | ||
if (learner$predict_type %nin% fallback$predict_types) { | ||
stopf("Fallback learner '%s' does not support predict type '%s'.", fallback$id, learner$predict_type) | ||
} | ||
|
||
fallback$predict_type = learner$predict_type | ||
|
||
# set quantiles | ||
if (learner$predict_type == "quantiles") { | ||
|
||
if (is.null(learner$quantiles) || is.null(learner$quantile_response)) { | ||
stopf("Cannot set quantiles for fallback learner. Set `$quantiles` and `$quantile_response` in %s.", learner$id) | ||
} | ||
|
||
fallback$quantiles = learner$quantiles | ||
fallback$quantile_response = learner$quantile_response | ||
} | ||
|
||
return(fallback) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.