-
-
Notifications
You must be signed in to change notification settings - Fork 55
feat: New base class for python-based learners #484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
R/LearnerPythonClassif.R
Outdated
initialize = function(id, | ||
feature_types = c("logical","integer","numeric","factor","ordered"), | ||
predict_types = c("response", "prob"), | ||
param_set = paradox::ParamSet$new(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
param_set = paradox::ParamSet$new(), | |
param_set = ps() |
R/LearnerPythonClassif.R
Outdated
# Python requirements | ||
py_packages, | ||
python_version, | ||
method = c("auto","virtualenv","conda"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove method and envname
R/LearnerPythonClassif.R
Outdated
method = c("auto","virtualenv","conda"), | ||
envname = NULL) { | ||
|
||
method = match.arg(method) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert_choice
R/LearnerPythonClassif.R
Outdated
|
||
method = match.arg(method) | ||
|
||
base_ps = ps( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also remove this
R/LearnerPythonClassif.R
Outdated
structure( | ||
list( | ||
fitted = fit$model, # PyObject | ||
meta = meta, # any R metadata (e.g., classes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the elements of meta
directly to the returned list.
R/LearnerPythonClassif.R
Outdated
|
||
.predict = function(task) { | ||
self$ensure_deps() | ||
if (is.null(self$model)) stop("Model not trained yet.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already in $predict
R/LearnerPythonClassif.R
Outdated
class_labels = task$class_names | ||
) | ||
|
||
if ("prob" %in% self$predict_types && !is.null(res$prob)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is also handled in mlr3. Take a look at the other learners.
R/LearnerPythonClassif.R
Outdated
reticulate::py_require(model$py_modules, python_version = model$py_version) | ||
pickle <- reticulate::import("pickle") | ||
|
||
raw <- as.raw(pickle$dumps(model$fitted)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this will crash with models larger than 4 GB. Can you test this?
R/LearnerPythonClassif.R
Outdated
|
||
# capture any additional classes (e.g. "classif.tabpfn_model"), keep first one | ||
learner_class <- setdiff(class(model), "pybytes_model") | ||
learner_class <- if (length(learner_class)) learner_class[1L] else NULL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an assert. learner_class
should never be NULL
When you are finished with this, you can add a helper function for converting config space objects from python to paradox in R. |
This pr implements a novel base class for Python based learners.
Open ToDo's: