Skip to content

Commit

Permalink
docs(extending): use set_values in example code (#402)
Browse files Browse the repository at this point in the history
* docs(extending): use `set_values` in example code

* docs(extending): same pattern for importance example function
  • Loading branch information
m-muecke authored Jan 2, 2025
1 parent e796fe1 commit dd5e37c
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions vignettes/extending.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ LearnerRegrRpartSimple = R6Class("LearnerRegrRpartSimple",
usesurrogate = p_int(0L, 2L, default = 2L, tags = "train"),
xval = p_int(0L, default = 10L, tags = "train")
)
param_set$values$xval = 10
param_set$set_values(xval = 10L)
super$initialize(
id = "regr.rpart_simple",
feature_types = c("logical", "integer", "numeric", "factor", "ordered"),
Expand All @@ -58,11 +58,10 @@ LearnerRegrRpartSimple = R6Class("LearnerRegrRpartSimple",
}
# importance is only present if there is at least on split
if (is.null(self$model$variable.importance)) {
importance = set_names(numeric())
set_names(numeric())
} else {
importance = sort(self$model$variable.importance, decreasing = TRUE)
sort(self$model$variable.importance, decreasing = TRUE)
}
return(importance)
}
),
private = list(
Expand Down Expand Up @@ -285,11 +284,10 @@ importance = function() {
}
# importance is only present if there is at least on split
if (is.null(self$model$variable.importance)) {
importance = set_names(numeric())
set_names(numeric())
} else {
importance = sort(self$model$variable.importance, decreasing = TRUE)
sort(self$model$variable.importance, decreasing = TRUE)
}
return(importance)
}
```

Expand Down

0 comments on commit dd5e37c

Please sign in to comment.