From 987f96c5ee1959f96299e8542dff6818c3367761 Mon Sep 17 00:00:00 2001 From: awinterstetter Date: Sat, 24 Jan 2026 21:38:28 +0100 Subject: [PATCH 1/5] implementation --- NAMESPACE | 1 + R/bibentries.R | 15 ++ R/learner_class_classif_lvq1.R | 72 +++++++++ man/mlr_learners_classif.C50.Rd | 2 +- man/mlr_learners_classif.abess.Rd | 2 +- man/mlr_learners_classif.bayes_net.Rd | 16 +- man/mlr_learners_classif.earth.Rd | 38 +---- man/mlr_learners_classif.lvq1.Rd | 143 ++++++++++++++++++ man/mlr_learners_regr.abess.Rd | 2 +- man/mlr_learners_regr.cubist.Rd | 2 +- man/mlr_learners_regr.earth.Rd | 38 +---- man/mlr_learners_surv.bart.Rd | 2 +- man/mlr_learners_surv.flexreg.Rd | 21 +-- tests/testthat/test_class_classif_lvq1.R | 8 + .../test_paramtest_class_classif_lvq1.R | 14 ++ 15 files changed, 266 insertions(+), 110 deletions(-) create mode 100644 R/learner_class_classif_lvq1.R create mode 100644 man/mlr_learners_classif.lvq1.Rd create mode 100644 tests/testthat/test_class_classif_lvq1.R create mode 100644 tests/testthat/test_paramtest_class_classif_lvq1.R diff --git a/NAMESPACE b/NAMESPACE index fd5ba0d21..5865ce28a 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -47,6 +47,7 @@ export(LearnerClassifLSSVM) export(LearnerClassifLiblineaR) export(LearnerClassifLightGBM) export(LearnerClassifLogistic) +export(LearnerClassifLvq1) export(LearnerClassifMda) export(LearnerClassifMdeb) export(LearnerClassifMob) diff --git a/R/bibentries.R b/R/bibentries.R index 01f0b8435..79f3053ac 100644 --- a/R/bibentries.R +++ b/R/bibentries.R @@ -952,6 +952,21 @@ bibentries = c( # nolint start number = "1", pages = "1--46", doi = "10.18637/jss.v072.i01" + ), + kohonen_1990 = bibentry("article", + title = "The self-organizing map", + author = "Kohonen, Teuvo", + journal = "Proceedings of the IEEE", + year = "1990", + volume = "78", + pages = "1464--1480" + ), + kohonen_1995 = bibentry("book", + title = "Self-Organizing Maps", + author = "Kohonen, Teuvo", + year = "1995", + publisher = "Springer", + address = "Berlin" ) ) # nolint end diff --git a/R/learner_class_classif_lvq1.R b/R/learner_class_classif_lvq1.R new file mode 100644 index 000000000..c745ee1b6 --- /dev/null +++ b/R/learner_class_classif_lvq1.R @@ -0,0 +1,72 @@ +#' @title Classification Learning Vector Quantization 1 +#' @author awinterstetter +#' @name mlr_learners_classif.lvq1 +#' +#' @description +#' Learning Vector Quantization 1. +#' Calls [class::lvqinit()], [class::lvq1()], and [class::lvqtest()] from \CRANpkg{class}. +#' +#' @templateVar id classif.lvq1 +#' @template learner +#' +#' @references +#' `r format_bib("kohonen_1990", "kohonen_1995")` +#' +#' @template seealso_learner +#' @template example +#' @export +LearnerClassifLvq1 = R6Class("LearnerClassifLvq1", + inherit = LearnerClassif, + public = list( + #' @description + #' Creates a new instance of this [R6][R6::R6Class] class. + initialize = function() { + param_set = ps( + size = p_int(default = NULL, lower = 1L, special_vals = list(NULL), tags = "train"), + prior = p_uty(default = NULL, tags = "train"), + k = p_int(default = 5L, lower = 1L, tags = "train"), + niter = p_int(default = NULL, lower = 1L, special_vals = list(NULL), tags = "train"), + alpha = p_dbl(default = 0.03, lower = 0, tags = "train") + ) + + super$initialize( + id = "classif.lvq1", + packages = "class", + feature_types = c("integer", "numeric"), + predict_types = "response", + param_set = param_set, + properties = c("twoclass", "multiclass"), + man = "mlr3extralearners::mlr_learners_classif.lvq1", + label = "Learning Vector Quantization 1" + ) + } + ), + private = list( + .train = function(task) { + pars = self$param_set$get_values(tags = "train") + + d = as.matrix(task$data(cols = task$feature_names)) + target = task$truth() + + init_pars = pars[names(pars) %in% c("size", "prior", "k")] + init_args = c(list(x = d, cl = target), init_pars) + codebk = invoke( + class::lvqinit, + .args = init_args) + + train_pars = pars[names(pars) %in% c("niter", "alpha")] + train_args = c(list(x = d, cl = target, codebk = codebk), train_pars) + + invoke(class::lvq1, .args = train_args) + }, + .predict = function(task) { + newdata = as.matrix(ordered_features(task, self)) + pred = invoke(class::lvqtest, + codebk = self$model, + test = newdata) + list(response = pred) + } + ) +) + +.extralrns_dict$add("classif.lvq1", LearnerClassifLvq1) diff --git a/man/mlr_learners_classif.C50.Rd b/man/mlr_learners_classif.C50.Rd index 4b8c96ab7..f0b480478 100644 --- a/man/mlr_learners_classif.C50.Rd +++ b/man/mlr_learners_classif.C50.Rd @@ -6,7 +6,7 @@ \title{Classification C5.0 Learner} \description{ Decision Tree Algorithm. -Calls \code{\link[C50:C5.0]{C50::C5.0.formula()}} from \CRANpkg{C50}. +Calls \code{\link[C50:C5.0.formula]{C50::C5.0.formula()}} from \CRANpkg{C50}. } \section{Dictionary}{ diff --git a/man/mlr_learners_classif.abess.Rd b/man/mlr_learners_classif.abess.Rd index 7eae86b24..7629c706c 100644 --- a/man/mlr_learners_classif.abess.Rd +++ b/man/mlr_learners_classif.abess.Rd @@ -148,7 +148,7 @@ Creates a new instance of this \link[R6:R6Class]{R6} class. \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-LearnerClassifAbess-selected_features}{}}} \subsection{Method \code{selected_features()}}{ -Extract the name of selected features from the model by \code{\link[abess:extract.abess]{abess::extract()}}. +Extract the name of selected features from the model by \code{\link[abess:extract]{abess::extract()}}. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{LearnerClassifAbess$selected_features()}\if{html}{\out{
}} } diff --git a/man/mlr_learners_classif.bayes_net.Rd b/man/mlr_learners_classif.bayes_net.Rd index 850e20585..cb111ff04 100644 --- a/man/mlr_learners_classif.bayes_net.Rd +++ b/man/mlr_learners_classif.bayes_net.Rd @@ -77,20 +77,8 @@ This \link[mlr3:Learner]{Learner} can be instantiated via \link[mlr3:mlr_sugar]{ } \section{Parameters}{ -\tabular{lllll}{ - Id \tab Type \tab Default \tab Levels \tab Range \cr - subset \tab untyped \tab - \tab \tab - \cr - na.action \tab untyped \tab - \tab \tab - \cr - D \tab logical \tab - \tab TRUE, FALSE \tab - \cr - B \tab untyped \tab - \tab \tab - \cr - Q \tab character \tab - \tab global.K2, global.HillClimber, global.SimulatedAnnealing, global.TabuSearch, global.TAN, local.K2, local.HillClimber, local.LAGDHillClimber, local.SimulatedAnnealing, local.TabuSearch, \link{...} \tab - \cr - E \tab character \tab - \tab estimate.SimpleEstimator, estimate.BMAEstimator, estimate.MultiNomialBMAEstimator \tab - \cr - output_debug_info \tab logical \tab FALSE \tab TRUE, FALSE \tab - \cr - do_not_check_capabilities \tab logical \tab FALSE \tab TRUE, FALSE \tab - \cr - num_decimal_places \tab integer \tab 2 \tab \tab \eqn{[1, \infty)}{[1, Inf)} \cr - batch_size \tab integer \tab 100 \tab \tab \eqn{[1, \infty)}{[1, Inf)} \cr - options \tab untyped \tab NULL \tab \tab - \cr -} + +`r paste(mlr3misc::rd_info(lrn("classif.bayes_net")$param_set), collapse = "\n")` } \examples{ diff --git a/man/mlr_learners_classif.earth.Rd b/man/mlr_learners_classif.earth.Rd index d5e082b65..a024c5a1a 100644 --- a/man/mlr_learners_classif.earth.Rd +++ b/man/mlr_learners_classif.earth.Rd @@ -33,42 +33,8 @@ This \link[mlr3:Learner]{Learner} can be instantiated via \link[mlr3:mlr_sugar]{ } \section{Parameters}{ -\tabular{lllll}{ - Id \tab Type \tab Default \tab Levels \tab Range \cr - wp \tab untyped \tab NULL \tab \tab - \cr - offset \tab untyped \tab NULL \tab \tab - \cr - keepxy \tab logical \tab FALSE \tab TRUE, FALSE \tab - \cr - trace \tab character \tab 0 \tab 0, .3, .5, 1, 2, 3, 4, 5 \tab - \cr - degree \tab integer \tab 1 \tab \tab \eqn{[1, \infty)}{[1, Inf)} \cr - penalty \tab numeric \tab 2 \tab \tab \eqn{[-1, \infty)}{[-1, Inf)} \cr - nk \tab untyped \tab NULL \tab \tab - \cr - thresh \tab numeric \tab 0.001 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr - minspan \tab numeric \tab 0 \tab \tab \eqn{[0, \infty)}{[0, Inf)} \cr - endspan \tab numeric \tab 0 \tab \tab \eqn{[0, \infty)}{[0, Inf)} \cr - newvar.penalty \tab numeric \tab 0 \tab \tab \eqn{[0, \infty)}{[0, Inf)} \cr - fast.k \tab integer \tab 20 \tab \tab \eqn{[0, \infty)}{[0, Inf)} \cr - fast.beta \tab integer \tab 1 \tab \tab \eqn{[0, 1]}{[0, 1]} \cr - linpreds \tab untyped \tab FALSE \tab \tab - \cr - allowed \tab untyped \tab - \tab \tab - \cr - pmethod \tab character \tab backward \tab backward, none, exhaustive, forward, seqrep, cv \tab - \cr - nprune \tab integer \tab - \tab \tab \eqn{[0, \infty)}{[0, Inf)} \cr - nfold \tab integer \tab 0 \tab \tab \eqn{[0, \infty)}{[0, Inf)} \cr - ncross \tab integer \tab 1 \tab \tab \eqn{[0, \infty)}{[0, Inf)} \cr - stratify \tab logical \tab TRUE \tab TRUE, FALSE \tab - \cr - varmod.method \tab character \tab none \tab none, const, lm, rlm, earth, gam, power, power0, x.lm, x.rlm, \link{...} \tab - \cr - varmod.exponent \tab numeric \tab 1 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr - varmod.conv \tab numeric \tab 1 \tab \tab \eqn{[0, 1]}{[0, 1]} \cr - varmod.clamp \tab numeric \tab 0.1 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr - varmod.minspan \tab numeric \tab -3 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr - Scale.y \tab logical \tab FALSE \tab TRUE, FALSE \tab - \cr - Adjust.endspan \tab numeric \tab 2 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr - Auto.linpreds \tab logical \tab TRUE \tab TRUE, FALSE \tab - \cr - Force.weights \tab logical \tab FALSE \tab TRUE, FALSE \tab - \cr - Use.beta.cache \tab logical \tab TRUE \tab TRUE, FALSE \tab - \cr - Force.xtx.prune \tab logical \tab FALSE \tab TRUE, FALSE \tab - \cr - Get.leverages \tab logical \tab TRUE \tab TRUE, FALSE \tab - \cr - Exhaustive.tol \tab numeric \tab 1e-10 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr -} + +`r paste(mlr3misc::rd_info(lrn("classif.earth")$param_set), collapse = "\n")` } \examples{ diff --git a/man/mlr_learners_classif.lvq1.Rd b/man/mlr_learners_classif.lvq1.Rd new file mode 100644 index 000000000..ce63ab4b3 --- /dev/null +++ b/man/mlr_learners_classif.lvq1.Rd @@ -0,0 +1,143 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/learner_class_classif_lvq1.R +\name{mlr_learners_classif.lvq1} +\alias{mlr_learners_classif.lvq1} +\alias{LearnerClassifLvq1} +\title{Classification Learning Vector Quantization 1} +\description{ +Learning Vector Quantization 1. +Calls \code{\link[class:lvqinit]{class::lvqinit()}}, \code{\link[class:lvq1]{class::lvq1()}}, and \code{\link[class:lvqtest]{class::lvqtest()}} from \CRANpkg{class}. +} +\section{Dictionary}{ + +This \link[mlr3:Learner]{Learner} can be instantiated via \link[mlr3:mlr_sugar]{lrn()}: + +\if{html}{\out{
}}\preformatted{lrn("classif.lvq1") +}\if{html}{\out{
}} +} + +\section{Meta Information}{ + +\itemize{ +\item Task type: \dQuote{classif} +\item Predict Types: \dQuote{response} +\item Feature Types: \dQuote{integer}, \dQuote{numeric} +\item Required Packages: \CRANpkg{mlr3}, \CRANpkg{class} +} +} + +\section{Parameters}{ +\tabular{llll}{ + Id \tab Type \tab Default \tab Range \cr + size \tab integer \tab NULL \tab \eqn{[1, \infty)}{[1, Inf)} \cr + prior \tab untyped \tab NULL \tab - \cr + k \tab integer \tab 5 \tab \eqn{[1, \infty)}{[1, Inf)} \cr + niter \tab integer \tab NULL \tab \eqn{[1, \infty)}{[1, Inf)} \cr + alpha \tab numeric \tab 0.03 \tab \eqn{[0, \infty)}{[0, Inf)} \cr +} +} + +\examples{ +\dontshow{if (learner_is_runnable("classif.lvq1")) withAutoprint(\{ # examplesIf} +# Define the Learner +learner = lrn("classif.lvq1") +print(learner) + +# Define a Task +task = tsk("sonar") + +# Create train and test set +ids = partition(task) + +# Train the learner on the training ids +learner$train(task, row_ids = ids$train) + +print(learner$model) + + +# Make predictions for the test rows +predictions = learner$predict(task, row_ids = ids$test) + +# Score the predictions +predictions$score() +\dontshow{\}) # examplesIf} +} +\references{ +Kohonen, Teuvo (1990). +\dQuote{The self-organizing map.} +\emph{Proceedings of the IEEE}, \bold{78}, 1464--1480. + +Kohonen, Teuvo (1995). +\emph{Self-Organizing Maps}. +Springer, Berlin. +} +\seealso{ +\itemize{ +\item \link[mlr3misc:Dictionary]{Dictionary} of \link[mlr3:Learner]{Learners}: \link[mlr3:mlr_learners]{mlr3::mlr_learners}. +\item \code{as.data.table(mlr_learners)} for a table of available \link[mlr3:Learner]{Learners} in the running session (depending on the loaded packages). +\item Chapter in the \href{https://mlr3book.mlr-org.com/}{mlr3book}: \url{https://mlr3book.mlr-org.com/basics.html#learners} +\item \CRANpkg{mlr3learners} for a selection of recommended learners. +\item \CRANpkg{mlr3cluster} for unsupervised clustering learners. +\item \CRANpkg{mlr3pipelines} to combine learners with pre- and postprocessing steps. +\item \CRANpkg{mlr3tuning} for tuning of hyperparameters, \CRANpkg{mlr3tuningspaces} for established default tuning spaces. +} +} +\author{ +awinterstetter +} +\section{Super classes}{ +\code{\link[mlr3:Learner]{mlr3::Learner}} -> \code{\link[mlr3:LearnerClassif]{mlr3::LearnerClassif}} -> \code{LearnerClassifLvq1} +} +\section{Methods}{ +\subsection{Public methods}{ +\itemize{ +\item \href{#method-LearnerClassifLvq1-new}{\code{LearnerClassifLvq1$new()}} +\item \href{#method-LearnerClassifLvq1-clone}{\code{LearnerClassifLvq1$clone()}} +} +} +\if{html}{\out{ +
Inherited methods + +
+}} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-LearnerClassifLvq1-new}{}}} +\subsection{Method \code{new()}}{ +Creates a new instance of this \link[R6:R6Class]{R6} class. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{LearnerClassifLvq1$new()}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-LearnerClassifLvq1-clone}{}}} +\subsection{Method \code{clone()}}{ +The objects of this class are cloneable with this method. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{LearnerClassifLvq1$clone(deep = FALSE)}\if{html}{\out{
}} +} + +\subsection{Arguments}{ +\if{html}{\out{
}} +\describe{ +\item{\code{deep}}{Whether to make a deep clone.} +} +\if{html}{\out{
}} +} +} +} diff --git a/man/mlr_learners_regr.abess.Rd b/man/mlr_learners_regr.abess.Rd index 7bc2970d1..5afb60d2a 100644 --- a/man/mlr_learners_regr.abess.Rd +++ b/man/mlr_learners_regr.abess.Rd @@ -148,7 +148,7 @@ Creates a new instance of this \link[R6:R6Class]{R6} class. \if{html}{\out{}} \if{latex}{\out{\hypertarget{method-LearnerRegrAbess-selected_features}{}}} \subsection{Method \code{selected_features()}}{ -Extract the name of selected features from the model by \code{\link[abess:extract.abess]{abess::extract()}}. +Extract the name of selected features from the model by \code{\link[abess:extract]{abess::extract()}}. \subsection{Usage}{ \if{html}{\out{
}}\preformatted{LearnerRegrAbess$selected_features()}\if{html}{\out{
}} } diff --git a/man/mlr_learners_regr.cubist.Rd b/man/mlr_learners_regr.cubist.Rd index 6197b05bc..a70a24621 100644 --- a/man/mlr_learners_regr.cubist.Rd +++ b/man/mlr_learners_regr.cubist.Rd @@ -7,7 +7,7 @@ \description{ Rule-based model that is an extension of Quinlan's M5 model tree. Each tree contains linear regression models at the terminal leaves. -Calls \code{\link[Cubist:cubist.default]{Cubist::cubist()}} from \CRANpkg{Cubist}. +Calls \code{\link[Cubist:cubist]{Cubist::cubist()}} from \CRANpkg{Cubist}. } \section{Dictionary}{ diff --git a/man/mlr_learners_regr.earth.Rd b/man/mlr_learners_regr.earth.Rd index 870634fae..2ba2014a4 100644 --- a/man/mlr_learners_regr.earth.Rd +++ b/man/mlr_learners_regr.earth.Rd @@ -33,42 +33,8 @@ This \link[mlr3:Learner]{Learner} can be instantiated via \link[mlr3:mlr_sugar]{ } \section{Parameters}{ -\tabular{lllll}{ - Id \tab Type \tab Default \tab Levels \tab Range \cr - wp \tab untyped \tab NULL \tab \tab - \cr - offset \tab untyped \tab NULL \tab \tab - \cr - keepxy \tab logical \tab FALSE \tab TRUE, FALSE \tab - \cr - trace \tab character \tab 0 \tab 0, .3, .5, 1, 2, 3, 4, 5 \tab - \cr - degree \tab integer \tab 1 \tab \tab \eqn{[1, \infty)}{[1, Inf)} \cr - penalty \tab numeric \tab 2 \tab \tab \eqn{[-1, \infty)}{[-1, Inf)} \cr - nk \tab untyped \tab NULL \tab \tab - \cr - thresh \tab numeric \tab 0.001 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr - minspan \tab numeric \tab 0 \tab \tab \eqn{[0, \infty)}{[0, Inf)} \cr - endspan \tab numeric \tab 0 \tab \tab \eqn{[0, \infty)}{[0, Inf)} \cr - newvar.penalty \tab numeric \tab 0 \tab \tab \eqn{[0, \infty)}{[0, Inf)} \cr - fast.k \tab integer \tab 20 \tab \tab \eqn{[0, \infty)}{[0, Inf)} \cr - fast.beta \tab integer \tab 1 \tab \tab \eqn{[0, 1]}{[0, 1]} \cr - linpreds \tab untyped \tab FALSE \tab \tab - \cr - allowed \tab untyped \tab - \tab \tab - \cr - pmethod \tab character \tab backward \tab backward, none, exhaustive, forward, seqrep, cv \tab - \cr - nprune \tab integer \tab - \tab \tab \eqn{[0, \infty)}{[0, Inf)} \cr - nfold \tab integer \tab 0 \tab \tab \eqn{[0, \infty)}{[0, Inf)} \cr - ncross \tab integer \tab 1 \tab \tab \eqn{[0, \infty)}{[0, Inf)} \cr - stratify \tab logical \tab TRUE \tab TRUE, FALSE \tab - \cr - varmod.method \tab character \tab none \tab none, const, lm, rlm, earth, gam, power, power0, x.lm, x.rlm, \link{...} \tab - \cr - varmod.exponent \tab numeric \tab 1 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr - varmod.conv \tab numeric \tab 1 \tab \tab \eqn{[0, 1]}{[0, 1]} \cr - varmod.clamp \tab numeric \tab 0.1 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr - varmod.minspan \tab numeric \tab -3 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr - Scale.y \tab logical \tab FALSE \tab TRUE, FALSE \tab - \cr - Adjust.endspan \tab numeric \tab 2 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr - Auto.linpreds \tab logical \tab TRUE \tab TRUE, FALSE \tab - \cr - Force.weights \tab logical \tab FALSE \tab TRUE, FALSE \tab - \cr - Use.beta.cache \tab logical \tab TRUE \tab TRUE, FALSE \tab - \cr - Force.xtx.prune \tab logical \tab FALSE \tab TRUE, FALSE \tab - \cr - Get.leverages \tab logical \tab TRUE \tab TRUE, FALSE \tab - \cr - Exhaustive.tol \tab numeric \tab 1e-10 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr -} + +`r paste(mlr3misc::rd_info(lrn("regr.earth")$param_set), collapse = "\n")` } \examples{ diff --git a/man/mlr_learners_surv.bart.Rd b/man/mlr_learners_surv.bart.Rd index e205425e7..93331e274 100644 --- a/man/mlr_learners_surv.bart.Rd +++ b/man/mlr_learners_surv.bart.Rd @@ -6,7 +6,7 @@ \title{Survival Bayesian Additive Regression Trees Learner} \description{ Fits a Bayesian Additive Regression Trees (BART) learner to right-censored -survival data. Calls \code{\link[BART:surv.bart]{BART::mc.surv.bart()}} from \CRANpkg{BART}. +survival data. Calls \code{\link[BART:mc.surv.bart]{BART::mc.surv.bart()}} from \CRANpkg{BART}. } \section{Prediction types}{ diff --git a/man/mlr_learners_surv.flexreg.Rd b/man/mlr_learners_surv.flexreg.Rd index 38097e97a..023b253b1 100644 --- a/man/mlr_learners_surv.flexreg.Rd +++ b/man/mlr_learners_surv.flexreg.Rd @@ -27,25 +27,8 @@ This \link[mlr3:Learner]{Learner} can be instantiated via \link[mlr3:mlr_sugar]{ } \section{Parameters}{ -\tabular{lllll}{ - Id \tab Type \tab Default \tab Levels \tab Range \cr - formula \tab untyped \tab - \tab \tab - \cr - anc \tab untyped \tab - \tab \tab - \cr - bhazard \tab untyped \tab - \tab \tab - \cr - rtrunc \tab untyped \tab - \tab \tab - \cr - dist \tab character \tab - \tab gengamma, gengamma.orig, genf, genf.orig, weibull, weibullph, gamma, exp, exponential, llogis, \link{...} \tab - \cr - inits \tab untyped \tab - \tab \tab - \cr - fixedpars \tab untyped \tab - \tab \tab - \cr - cl \tab numeric \tab 0.95 \tab \tab \eqn{[0, 1]}{[0, 1]} \cr - hessian \tab logical \tab TRUE \tab TRUE, FALSE \tab - \cr - hess.control \tab untyped \tab - \tab \tab - \cr - maxiter \tab integer \tab 30 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr - rel.tolerance \tab numeric \tab 1e-09 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr - toler.chol \tab numeric \tab 1e-10 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr - debug \tab integer \tab 0 \tab \tab \eqn{[0, 1]}{[0, 1]} \cr - outer.max \tab integer \tab 10 \tab \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr - times \tab untyped \tab - \tab \tab - \cr -} + +`r paste(mlr3misc::rd_info(lrn("surv.flexreg")$param_set), collapse = "\n")` } \section{Prediction types}{ diff --git a/tests/testthat/test_class_classif_lvq1.R b/tests/testthat/test_class_classif_lvq1.R new file mode 100644 index 000000000..1b2b9f1c8 --- /dev/null +++ b/tests/testthat/test_class_classif_lvq1.R @@ -0,0 +1,8 @@ +skip_if_not_installed("class") + +test_that("autotest", { + learner = lrn("classif.lvq1") + expect_learner(learner) + result = run_autotest(learner) + expect_true(result, info = result$error) +}) diff --git a/tests/testthat/test_paramtest_class_classif_lvq1.R b/tests/testthat/test_paramtest_class_classif_lvq1.R new file mode 100644 index 000000000..e2a55534f --- /dev/null +++ b/tests/testthat/test_paramtest_class_classif_lvq1.R @@ -0,0 +1,14 @@ +skip_if_not_installed("class") + +test_that("paramtest classif.lvq1 train", { + learner = lrn("classif.lvq1") + fun_list = list(class::lvqinit, class::lvq1) + exclude = c( + "x", # handled internally + "cl", # handled internally + "codebk" # handled internally + ) + + paramtest = run_paramtest(learner, fun_list, exclude, tag = "train") + expect_paramtest(paramtest) +}) From 00857d85871e55e42078afc97a396b4ce9e23206 Mon Sep 17 00:00:00 2001 From: awinterstetter Date: Sun, 25 Jan 2026 13:06:21 +0100 Subject: [PATCH 2/5] fixed autotest and added documentation --- R/learner_class_classif_lvq1.R | 16 ++++++++++------ man/mlr_learners_classif.lvq1.Rd | 3 +++ tests/testthat/test_class_classif_lvq1.R | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/R/learner_class_classif_lvq1.R b/R/learner_class_classif_lvq1.R index c745ee1b6..5d6415c69 100644 --- a/R/learner_class_classif_lvq1.R +++ b/R/learner_class_classif_lvq1.R @@ -6,6 +6,9 @@ #' Learning Vector Quantization 1. #' Calls [class::lvqinit()], [class::lvq1()], and [class::lvqtest()] from \CRANpkg{class}. #' +#' @note +#' The learner does not work on tasks with two target groups and one feature. +#' #' @templateVar id classif.lvq1 #' @template learner #' @@ -48,16 +51,17 @@ LearnerClassifLvq1 = R6Class("LearnerClassifLvq1", d = as.matrix(task$data(cols = task$feature_names)) target = task$truth() - init_pars = pars[names(pars) %in% c("size", "prior", "k")] - init_args = c(list(x = d, cl = target), init_pars) + cdbk_pars = pars[names(pars) %in% c("size", "prior", "k")] + cdbk_args = c(list(x = d, cl = target), cdbk_pars) codebk = invoke( class::lvqinit, - .args = init_args) + .args = cdbk_args) - train_pars = pars[names(pars) %in% c("niter", "alpha")] - train_args = c(list(x = d, cl = target, codebk = codebk), train_pars) + lvq_pars = pars[names(pars) %in% c("niter", "alpha")] + lvq_args = c(list(x = d, cl = target, codebk = codebk), lvq_pars) - invoke(class::lvq1, .args = train_args) + invoke(class::lvq1, .args = lvq_args) + }, .predict = function(task) { newdata = as.matrix(ordered_features(task, self)) diff --git a/man/mlr_learners_classif.lvq1.Rd b/man/mlr_learners_classif.lvq1.Rd index ce63ab4b3..334a5bf38 100644 --- a/man/mlr_learners_classif.lvq1.Rd +++ b/man/mlr_learners_classif.lvq1.Rd @@ -8,6 +8,9 @@ Learning Vector Quantization 1. Calls \code{\link[class:lvqinit]{class::lvqinit()}}, \code{\link[class:lvq1]{class::lvq1()}}, and \code{\link[class:lvqtest]{class::lvqtest()}} from \CRANpkg{class}. } +\note{ +The learner does not work on tasks with two target groups and one feature. +} \section{Dictionary}{ This \link[mlr3:Learner]{Learner} can be instantiated via \link[mlr3:mlr_sugar]{lrn()}: diff --git a/tests/testthat/test_class_classif_lvq1.R b/tests/testthat/test_class_classif_lvq1.R index 1b2b9f1c8..ea3683268 100644 --- a/tests/testthat/test_class_classif_lvq1.R +++ b/tests/testthat/test_class_classif_lvq1.R @@ -3,6 +3,6 @@ skip_if_not_installed("class") test_that("autotest", { learner = lrn("classif.lvq1") expect_learner(learner) - result = run_autotest(learner) + result = run_autotest(learner, exclude = "feat_single_integer_binary|feat_single_numeric_binary") expect_true(result, info = result$error) }) From 9e28cff3bd024e58b6e67f2bb85d22968aeb99bd Mon Sep 17 00:00:00 2001 From: awinterstetter Date: Mon, 26 Jan 2026 10:05:50 +0100 Subject: [PATCH 3/5] updated NEWS +cleaned code --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index 22fa2a5ff..75fe9b69f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -16,6 +16,7 @@ - `LearnerRegrBtlm` - `LearnerClassifNNTrain` - `LearnerClassifDbnDNN` + - `LearnerClassifLvq1` ## Breaking Changes From 072bd70d64e2d2aefaac98ec5d62e1a1a6f4c794 Mon Sep 17 00:00:00 2001 From: awinterstetter Date: Mon, 26 Jan 2026 10:06:02 +0100 Subject: [PATCH 4/5] cleaned code --- R/learner_class_classif_lvq1.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/learner_class_classif_lvq1.R b/R/learner_class_classif_lvq1.R index 5d6415c69..0f9dd0572 100644 --- a/R/learner_class_classif_lvq1.R +++ b/R/learner_class_classif_lvq1.R @@ -55,19 +55,23 @@ LearnerClassifLvq1 = R6Class("LearnerClassifLvq1", cdbk_args = c(list(x = d, cl = target), cdbk_pars) codebk = invoke( class::lvqinit, - .args = cdbk_args) + .args = cdbk_args + ) lvq_pars = pars[names(pars) %in% c("niter", "alpha")] lvq_args = c(list(x = d, cl = target, codebk = codebk), lvq_pars) - invoke(class::lvq1, .args = lvq_args) + invoke(class::lvq1, + .args = lvq_args + ) }, .predict = function(task) { newdata = as.matrix(ordered_features(task, self)) pred = invoke(class::lvqtest, codebk = self$model, - test = newdata) + test = newdata + ) list(response = pred) } ) From 7859b34f2f41f6fc03983662d9554420b757ce16 Mon Sep 17 00:00:00 2001 From: awinterstetter Date: Tue, 27 Jan 2026 15:06:45 +0100 Subject: [PATCH 5/5] reordered lines --- R/learner_class_classif_lvq1.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/R/learner_class_classif_lvq1.R b/R/learner_class_classif_lvq1.R index 0f9dd0572..b9f8712bb 100644 --- a/R/learner_class_classif_lvq1.R +++ b/R/learner_class_classif_lvq1.R @@ -61,14 +61,16 @@ LearnerClassifLvq1 = R6Class("LearnerClassifLvq1", lvq_pars = pars[names(pars) %in% c("niter", "alpha")] lvq_args = c(list(x = d, cl = target, codebk = codebk), lvq_pars) - invoke(class::lvq1, + invoke( + class::lvq1, .args = lvq_args ) }, .predict = function(task) { newdata = as.matrix(ordered_features(task, self)) - pred = invoke(class::lvqtest, + pred = invoke( + class::lvqtest, codebk = self$model, test = newdata )