Skip to content

Conversation

AnnaNzrv
Copy link
Collaborator

@AnnaNzrv AnnaNzrv commented Sep 13, 2025

This pr implements a novel base class for Python based learners.

Open ToDo's:

  • Marshaling works
  • Encapsulation works
  • Refactor all python-based learners
  • Update tutorial to include this new class
  • Extend implementation to regression learners

initialize = function(id,
feature_types = c("logical","integer","numeric","factor","ordered"),
predict_types = c("response", "prob"),
param_set = paradox::ParamSet$new(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
param_set = paradox::ParamSet$new(),
param_set = ps()

# Python requirements
py_packages,
python_version,
method = c("auto","virtualenv","conda"),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove method and envname

method = c("auto","virtualenv","conda"),
envname = NULL) {

method = match.arg(method)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert_choice


method = match.arg(method)

base_ps = ps(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also remove this

structure(
list(
fitted = fit$model, # PyObject
meta = meta, # any R metadata (e.g., classes)
Copy link
Member

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.


.predict = function(task) {
self$ensure_deps()
if (is.null(self$model)) stop("Model not trained yet.")
Copy link
Member

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

class_labels = task$class_names
)

if ("prob" %in% self$predict_types && !is.null(res$prob)) {
Copy link
Member

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.

reticulate::py_require(model$py_modules, python_version = model$py_version)
pickle <- reticulate::import("pickle")

raw <- as.raw(pickle$dumps(model$fitted))
Copy link
Member

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?


# 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
Copy link
Member

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

@be-marc
Copy link
Member

be-marc commented Sep 22, 2025

When you are finished with this, you can add a helper function for converting config space objects from python to paradox in R.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants