diff --git a/DESCRIPTION b/DESCRIPTION index ee0c15e7..13cf8955 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -37,6 +37,7 @@ Suggests: mclust, mlbench, RWeka, + stream, testthat (>= 3.0.0) Config/testthat/edition: 3 Encoding: UTF-8 @@ -47,6 +48,8 @@ Collate: 'aaa.R' 'LearnerClustAffinityPropagation.R' 'LearnerClustAgnes.R' + 'LearnerClustBICO.R' + 'LearnerClustBIRCH.R' 'LearnerClustCMeans.R' 'LearnerClustCobweb.R' 'LearnerClustDBSCAN.R' diff --git a/NAMESPACE b/NAMESPACE index d1f5562a..a0e4519c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,8 @@ S3method(is_missing_prediction_data,PredictionDataClust) export(LearnerClust) export(LearnerClustAP) export(LearnerClustAgnes) +export(LearnerClustBICO) +export(LearnerClustBIRCH) export(LearnerClustCMeans) export(LearnerClustCobweb) export(LearnerClustDBSCAN) diff --git a/NEWS.md b/NEWS.md index d6c533bb..4b969a5e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # mlr3cluster (development version) +* Add BIRCH learner from 'stream' package +* Add BICO learner from 'stream' package + # mlr3cluster 0.1.9 * Add DBSCAN learner from 'fpc' package diff --git a/R/LearnerClustBICO.R b/R/LearnerClustBICO.R new file mode 100644 index 00000000..f81992a0 --- /dev/null +++ b/R/LearnerClustBICO.R @@ -0,0 +1,66 @@ +#' @title BICO Clustering Learner +#' +#' @name mlr_learners_clust.bico +#' +#' @description +#' BICO (Fast computation of k-means coresets in a data stream) clustering. +#' Calls [stream::DSC_BICO()] from \CRANpkg{stream}. +#' +#' @templateVar id clust.bico +#' @template learner +#' +#' @references +#' `r format_bib("fichtenberger2013bico", "hahsler2017stream")` +#' +#' @export +#' @template seealso_learner +#' @template example +LearnerClustBICO = R6Class("LearnerClustBICO", + inherit = LearnerClust, + public = list( + #' @description + #' Creates a new instance of this [R6][R6::R6Class] class. + initialize = function() { + param_set = ps( + k = p_int(1L, default = 5L, tags = "train"), + space = p_int(1L, default = 10L, tags = "train"), + p = p_int(1L, default = 10L, tags = "train"), + iterations = p_int(1L, default = 10L, tags = "train") + ) + + super$initialize( + id = "clust.bico", + feature_types = c("integer", "numeric"), + predict_types = "partition", + param_set = param_set, + properties = c("partitional", "exclusive", "complete"), + packages = "stream", + man = "mlr3cluster::mlr_learners_clust.bico", + label = "BICO Clustering" + ) + } + ), + private = list( + .train = function(task) { + pv = self$param_set$get_values(tags = "train") + dt = task$data() + m = invoke(stream::DSC_BICO, .args = pv) + x = stream::DSD_Memory(dt) + stats::update(m, x, n = nrow(dt)) + + if (self$save_assignments) { + self$assignments = as.integer(invoke(predict, m, newdata = dt)[[1L]]) + } + + return(m) + }, + + .predict = function(task) { + partition = as.integer(invoke(predict, self$model, newdata = task$data())[[1L]]) + PredictionClust$new(task = task, partition = partition) + } + ) +) + +#' @include aaa.R +learners[["clust.bico"]] = LearnerClustBICO diff --git a/R/LearnerClustBIRCH.R b/R/LearnerClustBIRCH.R new file mode 100644 index 00000000..51086d25 --- /dev/null +++ b/R/LearnerClustBIRCH.R @@ -0,0 +1,67 @@ +#' @title BIRCH Clustering Learner +#' +#' @name mlr_learners_clust.birch +#' +#' @description +#' BIRCH (Balanced Iterative Reducing Clustering using Hierarchies) clustering. +#' Calls [stream::DSC_BIRCH()] from \CRANpkg{stream}. +#' +#' @templateVar id clust.birch +#' @template learner +#' +#' @references +#' `r format_bib("zhang1996birch", "zhang1997birch", "hahsler2017stream")` +#' +#' @export +#' @template seealso_learner +#' @template example +LearnerClustBIRCH = R6Class("LearnerClustBIRCH", + inherit = LearnerClust, + public = list( + #' @description + #' Creates a new instance of this [R6][R6::R6Class] class. + initialize = function() { + param_set = ps( + threshold = p_dbl(0L, tags = c("train", "required")), + branching = p_int(1L, tags = c("train", "required")), + maxLeaf = p_int(1L, tags = c("train", "required")), + maxMem = p_int(0L, default = 0L, tags = "train"), + outlierThreshold = p_dbl(default = 0.25, tags = "train") + ) + + super$initialize( + id = "clust.birch", + feature_types = c("integer", "numeric"), + predict_types = "partition", + param_set = param_set, + properties = c("hierarchical", "exclusive", "complete"), + packages = "stream", + man = "mlr3cluster::mlr_learners_clust.birch", + label = "BIRCH Clustering" + ) + } + ), + private = list( + .train = function(task) { + pv = self$param_set$get_values(tags = "train") + dt = task$data() + m = invoke(stream::DSC_BIRCH, .args = pv) + x = stream::DSD_Memory(dt) + stats::update(m, x, n = nrow(dt)) + + if (self$save_assignments) { + self$assignments = as.integer(invoke(predict, m, newdata = dt)[[1L]]) + } + + return(m) + }, + + .predict = function(task) { + partition = as.integer(invoke(predict, self$model, newdata = task$data())[[1L]]) + PredictionClust$new(task = task, partition = partition) + } + ) +) + +#' @include aaa.R +learners[["clust.birch"]] = LearnerClustBIRCH diff --git a/R/bibentries.R b/R/bibentries.R index 4662635c..b62c82f7 100644 --- a/R/bibentries.R +++ b/R/bibentries.R @@ -320,5 +320,42 @@ bibentries = c( # nolint start pages = "274--295", year = "2014", doi = "10.1007/s00357-014-9161-z" + ), + hahsler2017stream = bibentry("article", + title = "Introduction to {stream}: An Extensible Framework for Data Stream Clustering Research with {R}", + author = "Michael Hahsler and Matthew Bola\u00f1os and John Forrest", + journal = "Journal of Statistical Software", + year = "2017", + volume = "76", + number = "14", + pages = "1--50", + doi = "10.18637/jss.v076.i14", + ), + fichtenberger2013bico = bibentry("inproceedings", + title = "BICO: BIRCH Meets Coresets for k-Means Clustering", + author = "Fichtenberger, Hendrik and Gille, Marc and Schmidt, Melanie and Schwiegelshohn, Chris and Sohler, Christian", + booktitle = "Algorithms--ESA 2013: 21st Annual European Symposium, Sophia Antipolis, France, September 2-4, 2013. Proceedings 21", + pages = "481--492", + year = "2013", + organization = "Springer" + ), + zhang1996birch = bibentry("article", + title = "BIRCH: An Efficient Data Clustering Method for Very Large Databases", + author = "Zhang, Tian and Ramakrishnan, Raghu and Livny, Miron", + journal = "ACM sigmod record", + volume = "25", + number = "2", + pages = "103--114", + year = "1996", + publisher = "ACM New York, NY, USA" + ), + zhang1997birch = bibentry("article", + title = "BIRCH: A new data clustering algorithm and its applications", + author = "Zhang, Tian and Ramakrishnan, Raghu and Livny, Miron", + journal = "Data Mining and Knowledge Discovery", + volume = "1", + pages = "141--182", + year = "1997", + publisher = "Springer" ) ) # nolint end diff --git a/README.md b/README.md index 625f1704..5a31dcb1 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ pak::pak("mlr-org/mlr3cluster") The current version of **mlr3cluster** contains: -- A selection of 22 clustering learners that represent a wide variety of +- A selection of 24 clustering learners that represent a wide variety of clusterers: partitional, hierarchical, fuzzy, etc. - A selection of 4 performance measures - Two built-in tasks to get started with clustering @@ -60,6 +60,8 @@ create great visualizations with just one line of code! | [clust.SimpleKMeans](https://mlr3cluster.mlr-org.com/reference/mlr_learners_clust.SimpleKMeans) | K-Means (Weka) | [RWeka](https://cran.r-project.org/package=RWeka) | | [clust.agnes](https://mlr3cluster.mlr-org.com/reference/mlr_learners_clust.agnes) | Agglomerative Hierarchical Clustering | [cluster](https://cran.r-project.org/package=cluster) | | [clust.ap](https://mlr3cluster.mlr-org.com/reference/mlr_learners_clust.ap) | Affinity Propagation Clustering | [apcluster](https://cran.r-project.org/package=apcluster) | +| [clust.bico](https://mlr3cluster.mlr-org.com/reference/mlr_learners_clust.bico) | BICO Clustering | [stream](https://cran.r-project.org/package=stream) | +| [clust.birch](https://mlr3cluster.mlr-org.com/reference/mlr_learners_clust.birch) | BIRCH Clustering | [stream](https://cran.r-project.org/package=stream) | | [clust.cmeans](https://mlr3cluster.mlr-org.com/reference/mlr_learners_clust.cmeans) | Fuzzy C-Means Clustering Learner | [e1071](https://cran.r-project.org/package=e1071) | | [clust.cobweb](https://mlr3cluster.mlr-org.com/reference/mlr_learners_clust.cobweb) | Cobweb Clustering | [RWeka](https://cran.r-project.org/package=RWeka) | | [clust.dbscan](https://mlr3cluster.mlr-org.com/reference/mlr_learners_clust.dbscan) | Density-Based Clustering | [dbscan](https://cran.r-project.org/package=dbscan) | diff --git a/man/mlr_learners_clust.MBatchKMeans.Rd b/man/mlr_learners_clust.MBatchKMeans.Rd index cad2a81a..98087751 100644 --- a/man/mlr_learners_clust.MBatchKMeans.Rd +++ b/man/mlr_learners_clust.MBatchKMeans.Rd @@ -84,6 +84,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.SimpleKMeans.Rd b/man/mlr_learners_clust.SimpleKMeans.Rd index 071638d7..8a9b90a2 100644 --- a/man/mlr_learners_clust.SimpleKMeans.Rd +++ b/man/mlr_learners_clust.SimpleKMeans.Rd @@ -98,6 +98,8 @@ Other Learner: \code{\link{mlr_learners_clust.MBatchKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.agnes.Rd b/man/mlr_learners_clust.agnes.Rd index 7bbaf0a7..9ee017be 100644 --- a/man/mlr_learners_clust.agnes.Rd +++ b/man/mlr_learners_clust.agnes.Rd @@ -76,6 +76,8 @@ Other Learner: \code{\link{mlr_learners_clust.MBatchKMeans}}, \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.ap.Rd b/man/mlr_learners_clust.ap.Rd index e8b53258..08da61b8 100644 --- a/man/mlr_learners_clust.ap.Rd +++ b/man/mlr_learners_clust.ap.Rd @@ -87,6 +87,8 @@ Other Learner: \code{\link{mlr_learners_clust.MBatchKMeans}}, \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.bico.Rd b/man/mlr_learners_clust.bico.Rd new file mode 100644 index 00000000..1ff73506 --- /dev/null +++ b/man/mlr_learners_clust.bico.Rd @@ -0,0 +1,154 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/LearnerClustBICO.R +\name{mlr_learners_clust.bico} +\alias{mlr_learners_clust.bico} +\alias{LearnerClustBICO} +\title{BICO Clustering Learner} +\description{ +BICO (Fast computation of k-means coresets in a data stream) clustering. +Calls \code{\link[stream:DSC_BICO]{stream::DSC_BICO()}} from \CRANpkg{stream}. +} +\section{Dictionary}{ + +This \link{Learner} can be instantiated via the \link[mlr3misc:Dictionary]{dictionary} \link{mlr_learners} or with the associated sugar function \code{\link[=lrn]{lrn()}}: + +\if{html}{\out{
}}\preformatted{mlr_learners$get("clust.bico") +lrn("clust.bico") +}\if{html}{\out{
}} +} + +\section{Meta Information}{ + +\itemize{ +\item Task type: \dQuote{clust} +\item Predict Types: \dQuote{partition} +\item Feature Types: \dQuote{integer}, \dQuote{numeric} +\item Required Packages: \CRANpkg{mlr3}, \CRANpkg{mlr3cluster}, \CRANpkg{stream} +} +} + +\section{Parameters}{ +\tabular{llll}{ + Id \tab Type \tab Default \tab Range \cr + k \tab integer \tab 5 \tab \eqn{[1, \infty)}{[1, Inf)} \cr + space \tab integer \tab 10 \tab \eqn{[1, \infty)}{[1, Inf)} \cr + p \tab integer \tab 10 \tab \eqn{[1, \infty)}{[1, Inf)} \cr + iterations \tab integer \tab 10 \tab \eqn{[1, \infty)}{[1, Inf)} \cr +} +} + +\examples{ +if (requireNamespace("stream")) { + learner = mlr3::lrn("clust.bico") + print(learner) + + # available parameters: + learner$param_set$ids() +} +} +\references{ +Fichtenberger, Hendrik, Gille, Marc, Schmidt, Melanie, Schwiegelshohn, Chris, Sohler, Christian (2013). +\dQuote{BICO: BIRCH Meets Coresets for k-Means Clustering.} +In \emph{Algorithms--ESA 2013: 21st Annual European Symposium, Sophia Antipolis, France, September 2-4, 2013. Proceedings 21}, 481--492. +Springer. + +Hahsler M, Bolaños M, Forrest J (2017). +\dQuote{Introduction to stream: An Extensible Framework for Data Stream Clustering Research with R.} +\emph{Journal of Statistical Software}, \bold{76}(14), 1--50. +\doi{10.18637/jss.v076.i14}. +} +\seealso{ +\itemize{ +\item Chapter in the \href{https://mlr3book.mlr-org.com/}{mlr3book}: +\url{https://mlr3book.mlr-org.com/chapters/chapter2/data_and_basic_modeling.html#sec-learners} +\item Package \href{https://github.com/mlr-org/mlr3extralearners}{mlr3extralearners} for more learners. +\item \link[mlr3misc:Dictionary]{Dictionary} of \link[=Learner]{Learners}: \link{mlr_learners} +\item \code{as.data.table(mlr_learners)} for a table of available \link[=Learner]{Learners} in the running session (depending on the loaded packages). +\item \CRANpkg{mlr3pipelines} to combine learners with pre- and postprocessing steps. +\item Extension packages for additional task types: +\itemize{ +\item \CRANpkg{mlr3proba} for probabilistic supervised regression and survival analysis. +\item \CRANpkg{mlr3cluster} for unsupervised clustering. +} +\item \CRANpkg{mlr3tuning} for tuning of hyperparameters, \CRANpkg{mlr3tuningspaces} +for established default tuning spaces. +} + +Other Learner: +\code{\link{mlr_learners_clust.MBatchKMeans}}, +\code{\link{mlr_learners_clust.SimpleKMeans}}, +\code{\link{mlr_learners_clust.agnes}}, +\code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.birch}}, +\code{\link{mlr_learners_clust.cmeans}}, +\code{\link{mlr_learners_clust.cobweb}}, +\code{\link{mlr_learners_clust.dbscan}}, +\code{\link{mlr_learners_clust.dbscan_fpc}}, +\code{\link{mlr_learners_clust.diana}}, +\code{\link{mlr_learners_clust.em}}, +\code{\link{mlr_learners_clust.fanny}}, +\code{\link{mlr_learners_clust.featureless}}, +\code{\link{mlr_learners_clust.ff}}, +\code{\link{mlr_learners_clust.hclust}}, +\code{\link{mlr_learners_clust.hdbscan}}, +\code{\link{mlr_learners_clust.kkmeans}}, +\code{\link{mlr_learners_clust.kmeans}}, +\code{\link{mlr_learners_clust.mclust}}, +\code{\link{mlr_learners_clust.meanshift}}, +\code{\link{mlr_learners_clust.optics}}, +\code{\link{mlr_learners_clust.pam}}, +\code{\link{mlr_learners_clust.xmeans}} +} +\concept{Learner} +\section{Super classes}{ +\code{\link[mlr3:Learner]{mlr3::Learner}} -> \code{\link[mlr3cluster:LearnerClust]{mlr3cluster::LearnerClust}} -> \code{LearnerClustBICO} +} +\section{Methods}{ +\subsection{Public methods}{ +\itemize{ +\item \href{#method-LearnerClustBICO-new}{\code{LearnerClustBICO$new()}} +\item \href{#method-LearnerClustBICO-clone}{\code{LearnerClustBICO$clone()}} +} +} +\if{html}{\out{ +
Inherited methods + +
+}} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-LearnerClustBICO-new}{}}} +\subsection{Method \code{new()}}{ +Creates a new instance of this \link[R6:R6Class]{R6} class. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{LearnerClustBICO$new()}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-LearnerClustBICO-clone}{}}} +\subsection{Method \code{clone()}}{ +The objects of this class are cloneable with this method. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{LearnerClustBICO$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_clust.birch.Rd b/man/mlr_learners_clust.birch.Rd new file mode 100644 index 00000000..84721f3b --- /dev/null +++ b/man/mlr_learners_clust.birch.Rd @@ -0,0 +1,158 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/LearnerClustBIRCH.R +\name{mlr_learners_clust.birch} +\alias{mlr_learners_clust.birch} +\alias{LearnerClustBIRCH} +\title{BIRCH Clustering Learner} +\description{ +BIRCH (Balanced Iterative Reducing Clustering using Hierarchies) clustering. +Calls \code{\link[stream:DSC_BIRCH]{stream::DSC_BIRCH()}} from \CRANpkg{stream}. +} +\section{Dictionary}{ + +This \link{Learner} can be instantiated via the \link[mlr3misc:Dictionary]{dictionary} \link{mlr_learners} or with the associated sugar function \code{\link[=lrn]{lrn()}}: + +\if{html}{\out{
}}\preformatted{mlr_learners$get("clust.birch") +lrn("clust.birch") +}\if{html}{\out{
}} +} + +\section{Meta Information}{ + +\itemize{ +\item Task type: \dQuote{clust} +\item Predict Types: \dQuote{partition} +\item Feature Types: \dQuote{integer}, \dQuote{numeric} +\item Required Packages: \CRANpkg{mlr3}, \CRANpkg{mlr3cluster}, \CRANpkg{stream} +} +} + +\section{Parameters}{ +\tabular{llll}{ + Id \tab Type \tab Default \tab Range \cr + threshold \tab numeric \tab - \tab \eqn{[0, \infty)}{[0, Inf)} \cr + branching \tab integer \tab - \tab \eqn{[1, \infty)}{[1, Inf)} \cr + maxLeaf \tab integer \tab - \tab \eqn{[1, \infty)}{[1, Inf)} \cr + maxMem \tab integer \tab 0 \tab \eqn{[0, \infty)}{[0, Inf)} \cr + outlierThreshold \tab numeric \tab 0.25 \tab \eqn{(-\infty, \infty)}{(-Inf, Inf)} \cr +} +} + +\examples{ +if (requireNamespace("stream")) { + learner = mlr3::lrn("clust.birch") + print(learner) + + # available parameters: + learner$param_set$ids() +} +} +\references{ +Zhang, Tian, Ramakrishnan, Raghu, Livny, Miron (1996). +\dQuote{BIRCH: An Efficient Data Clustering Method for Very Large Databases.} +\emph{ACM sigmod record}, \bold{25}(2), 103--114. + +Zhang, Tian, Ramakrishnan, Raghu, Livny, Miron (1997). +\dQuote{BIRCH: A new data clustering algorithm and its applications.} +\emph{Data Mining and Knowledge Discovery}, \bold{1}, 141--182. + +Hahsler M, Bolaños M, Forrest J (2017). +\dQuote{Introduction to stream: An Extensible Framework for Data Stream Clustering Research with R.} +\emph{Journal of Statistical Software}, \bold{76}(14), 1--50. +\doi{10.18637/jss.v076.i14}. +} +\seealso{ +\itemize{ +\item Chapter in the \href{https://mlr3book.mlr-org.com/}{mlr3book}: +\url{https://mlr3book.mlr-org.com/chapters/chapter2/data_and_basic_modeling.html#sec-learners} +\item Package \href{https://github.com/mlr-org/mlr3extralearners}{mlr3extralearners} for more learners. +\item \link[mlr3misc:Dictionary]{Dictionary} of \link[=Learner]{Learners}: \link{mlr_learners} +\item \code{as.data.table(mlr_learners)} for a table of available \link[=Learner]{Learners} in the running session (depending on the loaded packages). +\item \CRANpkg{mlr3pipelines} to combine learners with pre- and postprocessing steps. +\item Extension packages for additional task types: +\itemize{ +\item \CRANpkg{mlr3proba} for probabilistic supervised regression and survival analysis. +\item \CRANpkg{mlr3cluster} for unsupervised clustering. +} +\item \CRANpkg{mlr3tuning} for tuning of hyperparameters, \CRANpkg{mlr3tuningspaces} +for established default tuning spaces. +} + +Other Learner: +\code{\link{mlr_learners_clust.MBatchKMeans}}, +\code{\link{mlr_learners_clust.SimpleKMeans}}, +\code{\link{mlr_learners_clust.agnes}}, +\code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.cmeans}}, +\code{\link{mlr_learners_clust.cobweb}}, +\code{\link{mlr_learners_clust.dbscan}}, +\code{\link{mlr_learners_clust.dbscan_fpc}}, +\code{\link{mlr_learners_clust.diana}}, +\code{\link{mlr_learners_clust.em}}, +\code{\link{mlr_learners_clust.fanny}}, +\code{\link{mlr_learners_clust.featureless}}, +\code{\link{mlr_learners_clust.ff}}, +\code{\link{mlr_learners_clust.hclust}}, +\code{\link{mlr_learners_clust.hdbscan}}, +\code{\link{mlr_learners_clust.kkmeans}}, +\code{\link{mlr_learners_clust.kmeans}}, +\code{\link{mlr_learners_clust.mclust}}, +\code{\link{mlr_learners_clust.meanshift}}, +\code{\link{mlr_learners_clust.optics}}, +\code{\link{mlr_learners_clust.pam}}, +\code{\link{mlr_learners_clust.xmeans}} +} +\concept{Learner} +\section{Super classes}{ +\code{\link[mlr3:Learner]{mlr3::Learner}} -> \code{\link[mlr3cluster:LearnerClust]{mlr3cluster::LearnerClust}} -> \code{LearnerClustBIRCH} +} +\section{Methods}{ +\subsection{Public methods}{ +\itemize{ +\item \href{#method-LearnerClustBIRCH-new}{\code{LearnerClustBIRCH$new()}} +\item \href{#method-LearnerClustBIRCH-clone}{\code{LearnerClustBIRCH$clone()}} +} +} +\if{html}{\out{ +
Inherited methods + +
+}} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-LearnerClustBIRCH-new}{}}} +\subsection{Method \code{new()}}{ +Creates a new instance of this \link[R6:R6Class]{R6} class. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{LearnerClustBIRCH$new()}\if{html}{\out{
}} +} + +} +\if{html}{\out{
}} +\if{html}{\out{}} +\if{latex}{\out{\hypertarget{method-LearnerClustBIRCH-clone}{}}} +\subsection{Method \code{clone()}}{ +The objects of this class are cloneable with this method. +\subsection{Usage}{ +\if{html}{\out{
}}\preformatted{LearnerClustBIRCH$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_clust.cmeans.Rd b/man/mlr_learners_clust.cmeans.Rd index 14026ec8..8a9b6656 100644 --- a/man/mlr_learners_clust.cmeans.Rd +++ b/man/mlr_learners_clust.cmeans.Rd @@ -85,6 +85,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, \code{\link{mlr_learners_clust.dbscan_fpc}}, diff --git a/man/mlr_learners_clust.cobweb.Rd b/man/mlr_learners_clust.cobweb.Rd index 51b903d7..c6be77d3 100644 --- a/man/mlr_learners_clust.cobweb.Rd +++ b/man/mlr_learners_clust.cobweb.Rd @@ -81,6 +81,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.dbscan}}, \code{\link{mlr_learners_clust.dbscan_fpc}}, diff --git a/man/mlr_learners_clust.dbscan.Rd b/man/mlr_learners_clust.dbscan.Rd index d9b673aa..751382e4 100644 --- a/man/mlr_learners_clust.dbscan.Rd +++ b/man/mlr_learners_clust.dbscan.Rd @@ -82,6 +82,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan_fpc}}, diff --git a/man/mlr_learners_clust.dbscan_fpc.Rd b/man/mlr_learners_clust.dbscan_fpc.Rd index 26176e45..e45fe3ac 100644 --- a/man/mlr_learners_clust.dbscan_fpc.Rd +++ b/man/mlr_learners_clust.dbscan_fpc.Rd @@ -76,6 +76,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.diana.Rd b/man/mlr_learners_clust.diana.Rd index cabb368d..7ae950f0 100644 --- a/man/mlr_learners_clust.diana.Rd +++ b/man/mlr_learners_clust.diana.Rd @@ -75,6 +75,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.em.Rd b/man/mlr_learners_clust.em.Rd index 3e41cb61..b4902ec8 100644 --- a/man/mlr_learners_clust.em.Rd +++ b/man/mlr_learners_clust.em.Rd @@ -87,6 +87,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.fanny.Rd b/man/mlr_learners_clust.fanny.Rd index ead96859..25218996 100644 --- a/man/mlr_learners_clust.fanny.Rd +++ b/man/mlr_learners_clust.fanny.Rd @@ -81,6 +81,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.featureless.Rd b/man/mlr_learners_clust.featureless.Rd index 5445cca1..c0c87073 100644 --- a/man/mlr_learners_clust.featureless.Rd +++ b/man/mlr_learners_clust.featureless.Rd @@ -65,6 +65,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.ff.Rd b/man/mlr_learners_clust.ff.Rd index 19043a42..4efa8d77 100644 --- a/man/mlr_learners_clust.ff.Rd +++ b/man/mlr_learners_clust.ff.Rd @@ -77,6 +77,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.hclust.Rd b/man/mlr_learners_clust.hclust.Rd index 1985408b..4aa27054 100644 --- a/man/mlr_learners_clust.hclust.Rd +++ b/man/mlr_learners_clust.hclust.Rd @@ -115,6 +115,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.hdbscan.Rd b/man/mlr_learners_clust.hdbscan.Rd index ad1503e3..02a2f0bd 100644 --- a/man/mlr_learners_clust.hdbscan.Rd +++ b/man/mlr_learners_clust.hdbscan.Rd @@ -79,6 +79,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.kkmeans.Rd b/man/mlr_learners_clust.kkmeans.Rd index 82a70c83..48248e1e 100644 --- a/man/mlr_learners_clust.kkmeans.Rd +++ b/man/mlr_learners_clust.kkmeans.Rd @@ -86,6 +86,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.kmeans.Rd b/man/mlr_learners_clust.kmeans.Rd index 3989e1d4..be9a5b02 100644 --- a/man/mlr_learners_clust.kmeans.Rd +++ b/man/mlr_learners_clust.kmeans.Rd @@ -90,6 +90,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.mclust.Rd b/man/mlr_learners_clust.mclust.Rd index 0100f232..04293b90 100644 --- a/man/mlr_learners_clust.mclust.Rd +++ b/man/mlr_learners_clust.mclust.Rd @@ -80,6 +80,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.meanshift.Rd b/man/mlr_learners_clust.meanshift.Rd index 41d0981a..412e12f5 100644 --- a/man/mlr_learners_clust.meanshift.Rd +++ b/man/mlr_learners_clust.meanshift.Rd @@ -75,6 +75,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.optics.Rd b/man/mlr_learners_clust.optics.Rd index 204e23b4..ce30ac3f 100644 --- a/man/mlr_learners_clust.optics.Rd +++ b/man/mlr_learners_clust.optics.Rd @@ -81,6 +81,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.pam.Rd b/man/mlr_learners_clust.pam.Rd index d2f25d46..dccfa0ff 100644 --- a/man/mlr_learners_clust.pam.Rd +++ b/man/mlr_learners_clust.pam.Rd @@ -85,6 +85,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/man/mlr_learners_clust.xmeans.Rd b/man/mlr_learners_clust.xmeans.Rd index d2e93777..e7f25652 100644 --- a/man/mlr_learners_clust.xmeans.Rd +++ b/man/mlr_learners_clust.xmeans.Rd @@ -90,6 +90,8 @@ Other Learner: \code{\link{mlr_learners_clust.SimpleKMeans}}, \code{\link{mlr_learners_clust.agnes}}, \code{\link{mlr_learners_clust.ap}}, +\code{\link{mlr_learners_clust.bico}}, +\code{\link{mlr_learners_clust.birch}}, \code{\link{mlr_learners_clust.cmeans}}, \code{\link{mlr_learners_clust.cobweb}}, \code{\link{mlr_learners_clust.dbscan}}, diff --git a/tests/testthat/test_mlr_learners_clust_bico.R b/tests/testthat/test_mlr_learners_clust_bico.R new file mode 100644 index 00000000..75f04dc2 --- /dev/null +++ b/tests/testthat/test_mlr_learners_clust_bico.R @@ -0,0 +1,37 @@ +skip_if_not_installed("stream") + +test_that("autotest", { + learner = mlr3::lrn("clust.bico") + expect_learner(learner) + result = run_autotest(learner) + expect_true(result, info = result$error) +}) + +test_that("Learner properties are respected", { + task = tsk("usarrests") + learner = lrn("clust.bico") + expect_learner(learner, task) + + # test on multiple paramsets + parset_list = list( + list(k = 5), + list(k = 5, space = 5L), + list(k = 5, space = 5L, p = 5L), + list(k = 5, space = 5L, p = 5L, iterations = 5L) + ) + + for (i in seq_along(parset_list)) { + parset = parset_list[[i]] + learner$param_set$values = parset + + p = learner$train(task)$predict(task) + expect_prediction_clust(p) + + if ("complete" %in% learner$properties) { + expect_prediction_complete(p, learner$predict_type) + } + if ("exclusive" %in% learner$properties) { + expect_prediction_exclusive(p, learner$predict_type) + } + } +}) diff --git a/tests/testthat/test_mlr_learners_clust_birch.R b/tests/testthat/test_mlr_learners_clust_birch.R new file mode 100644 index 00000000..40b055a0 --- /dev/null +++ b/tests/testthat/test_mlr_learners_clust_birch.R @@ -0,0 +1,36 @@ +skip_if_not_installed("stream") + +test_that("autotest", { + learner = mlr3::lrn("clust.birch", threshold = 0.1, branching = 8L, maxLeaf = 20L) + expect_learner(learner) + result = run_autotest(learner) + expect_true(result, info = result$error) +}) + +test_that("Learner properties are respected", { + task = tsk("usarrests") + learner = lrn("clust.birch", threshold = 0.1, branching = 8L, maxLeaf = 20L) + expect_learner(learner, task) + + # test on multiple paramsets + parset_list = list( + list(threshold = 0.1, branching = 8L, maxLeaf = 20L), + list(threshold = 0.2, branching = 4L, maxLeaf = 10, maxMem = 2L), + list(threshold = 0.3, branching = 12L, maxLeaf = 5L, outlierThreshold = 0.3) + ) + + for (i in seq_along(parset_list)) { + parset = parset_list[[i]] + learner$param_set$values = parset + + p = learner$train(task)$predict(task) + expect_prediction_clust(p) + + if ("complete" %in% learner$properties) { + expect_prediction_complete(p, learner$predict_type) + } + if ("exclusive" %in% learner$properties) { + expect_prediction_exclusive(p, learner$predict_type) + } + } +})