Skip to content

Consolidate checks on the classification type #101

Open

Description

@hfrick

We can consolidate something here:

set_tailor_type() updates the type based on the outcome, while update_type() determines the classification type from the number of probability columns, i.e., from the predictors. Both are being called only in fit.tailor().

tailor/R/tailor.R

Lines 286 to 308 in b5e1325

set_tailor_type <- function(object, y, call = caller_env()) {
if (object$type != "unknown") {
check_variable_type(y, object$type, "outcome", call = call)
return(object)
}
if (is.factor(y)) {
lvls <- levels(y)
if (length(lvls) == 2) {
object$type <- "binary"
} else {
object$type <- "multiclass"
}
} else if (is.numeric(y)) {
object$type <- "regression"
} else {
cli_abort(
"Only factor and numeric outcomes are currently supported.",
call = call
)
}
object
}

tailor/R/validation-rules.R

Lines 129 to 136 in b5e1325

update_type <- function(type, probabilities) {
if (type == "binary") {
if (length(probabilities) > 2) {
type <- "multiclass"
}
}
type
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    upkeepmaintenance, infrastructure, and similar

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions