Skip to content

Commit

Permalink
added cobweb learner
Browse files Browse the repository at this point in the history
  • Loading branch information
damirpolat committed Oct 18, 2020
1 parent b6f67e4 commit 1aaf234
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Collate:
'LearnerClust.R'
'LearnerClustAgnes.R'
'LearnerClustCMeans.R'
'LearnerClustCobweb.R'
'LearnerClustDBSCAN.R'
'LearnerClustDiana.R'
'LearnerClustFanny.R'
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ S3method(is_missing_prediction_data,PredictionDataClust)
export(LearnerClust)
export(LearnerClustAgnes)
export(LearnerClustCMeans)
export(LearnerClustCobweb)
export(LearnerClustDBSCAN)
export(LearnerClustDiana)
export(LearnerClustFanny)
Expand Down
53 changes: 53 additions & 0 deletions R/LearnerClustCobweb.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#' @title Cobweb Clustering Learner
#'
#' @name mlr_learners_clust.cobweb
#' @include LearnerClust.R
#'
#' @description
#' A [LearnerClust] for Cobweb clustering implemented in [RWeka::Cobweb()].
#' The predict method uses [RWeka::predict.Weka_clusterer()] to compute the
#' cluster memberships for new data.
#'
#' @templateVar id clust.cobweb
#' @template section_dictionary_learner
#' @template example
#'
#' @export
LearnerClustCobweb = R6Class("LearnerClustCobweb",
inherit = LearnerClust,
public = list(
#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
ps = ParamSet$new(
params = list(
ParamDbl$new(id = "A", default = 1, lower = 0, tags = "train"),
ParamDbl$new(id = "C", default = 0.002, lower = 0, tags = "train"),
ParamInt$new(id = "S", default = 42L, lower = 1L, tags = "train")
)
)

super$initialize(
id = "clust.cobweb",
feature_types = c("logical", "integer", "numeric"),
predict_types = "partition",
param_set = ps,
properties = c("partitional", "exclusive", "complete"),
packages = "RWeka"
)
}
),

private = list(
.train = function(task) {
pv = self$param_set$get_values(tags = "train")
ctrl = do.call(RWeka::Weka_control, pv)
invoke(RWeka::Cobweb, x = task$data(), control = ctrl)
},

.predict = function(task) {
partition = predict(self$model, newdata = task$data(), type = "class") + 1L
PredictionClust$new(task = task, partition = partition)
}
)
)
1 change: 1 addition & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ register_mlr3 = function() {
x$add("clust.cmeans", LearnerClustCMeans)
x$add("clust.dbscan", LearnerClustDBSCAN)
x$add("clust.xmeans", LearnerClustXMeans)
x$add("clust.cobweb", LearnerClustCobweb)

x = utils::getFromNamespace("mlr_measures", ns = "mlr3")
x$add("clust.db", MeasureClustInternal, name = "db")
Expand Down
76 changes: 76 additions & 0 deletions man/mlr_learners_clust.cobweb.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1aaf234

Please sign in to comment.