Skip to content

Conversation

AnnaNzrv
Copy link
Collaborator

@AnnaNzrv AnnaNzrv commented Sep 2, 2025

closes #479

This PR implements binary classification only, following the approach from the previous version of mlr2.

The following steps have been completed to ensure proper functionality:

  • The added learner(s) are sufficiently tested
  • All the CI tests are passing (including the CodeFactor)
  • Update docs with devtools::document()
  • Updated the NEWS.md field to include the addition of the learner
  • Not modify anything not related to the new learner
  • Contributor in the DESCRIPTION of the R package

@AnnaNzrv
Copy link
Collaborator Author

AnnaNzrv commented Sep 2, 2025

While extending the learner to support multiclass classification should generally be possible, as outlined in an example of the neuralnet documentation, there is some unexpected behavior. Specifically, when applying neuralnet::neuralnet to tasks like the wine classification (tsk("wine")), the model predicts the same response for all observations. This issue requires further investigation if we decide to extend the learner to multiclass classification.

Example:

task = tsk("wine")
pars = list(act.fct = "logistic", linear.output = FALSE, err.fct = "ce")
target = task$target_names
class_names = task$class_names
data = task$data()

# Create formula based on neuralnet documentation
lhs = paste0("(", eval(target), "== \"", class_names, "\")", collapse = " + ")
formula_str = paste(lhs, "~ .")
formula = as.formula(formula_str)

model = invoke(
      neuralnet::neuralnet,
      formula = formula,
      data = data,
      .args = pars
    )

newdata = task$data()  # ordered_features(task, self)
invoke(predict, model, newdata = newdata)
#> Prediction matrix with only duplicated rows

@AnnaNzrv AnnaNzrv marked this pull request as ready for review September 2, 2025 17:44
@be-marc be-marc merged commit 8be756e into main Oct 1, 2025
3 of 5 checks passed
@be-marc be-marc deleted the learners_neuralnet branch October 1, 2025 08:25
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.

neuralnet from package neuralnet
2 participants