ClustPredictor {FACT} | R Documentation |
A ClustPredictor
object holds any unsupervised clustering algorithm
and the data to be used for analyzing the model. The interpretation methods
in the FACT
package need the clustering algorithm to be wrapped in a
ClustPredictor
object.
A Cluster Predictor object is a container for the unsupervised prediction model and the data. This ensures that the clustering algorithm can be analyzed in a robust way. The Model inherits from iml::Predictor Object and adjusts this Object to contain unsupervised Methods.
iml::Predictor
-> ClustPredictor
type
character(1)
Either partition for cluster assignments or prob
for soft labels. Can be decided by chosen by the
user when initializing the object. If NULL
,
it checks the the dimensions of y
.
cnames
character
Is NULL
, if hard labeling is used. If soft
labels are used, column names of y
are being
transferred.
new()
Create a ClustPredictor object
ClustPredictor$new( model = NULL, data = NULL, predict.function = NULL, y = NULL, batch.size = 1000, type = NULL )
model
any
The trained clustering algorithm. Recommended
are models from mlr3cluster
. For other
clustering algorithms predict functions need to
be specified.
data
data.frame
The data to be used for analyzing the prediction model. Allowed column
classes are: numeric, factor, integer, ordered and character
predict.function
function
The function to assign newdata. Only needed if
model
is not a model from mlr3cluster
. The
first argument of predict.fun
has to be the
model, the second the newdata
:
function(model, newdata)
y
any
A integer vector representing the assigned
clusters or a data.frame representing the
soft labels per cluster assigned in columns.
batch.size
numeric(1)
The maximum number of rows to be input the model for prediction at once.
Currently only respected for SMART.
type
character(1)
)
This argument is passed to the prediction
function of the model. For soft label
predictions, use type="prob"
. For hard label
predictions, use type="partition"
. Consult
the documentation or definition of the
clustering algorithm you use to find which type
options you have.
clone()
The objects of this class are cloneable with this method.
ClustPredictor$clone(deep = FALSE)
deep
Whether to make a deep clone.
require(factoextra)
require(FuzzyDBScan)
multishapes <- as.data.frame(multishapes[, 1:2])
eps = c(0, 0.2)
pts = c(3, 15)
res <- FuzzyDBScan$new(multishapes, eps, pts)
res$plot("x", "y")
# create hard label predictor
predict_part = function(model, newdata) model$predict(new_data = newdata, cmatrix = FALSE)$cluster
ClustPredictor$new(res, as.data.frame(multishapes), y = res$clusters,
predict.function = predict_part, type = "partition")
# create soft label predictor
predict_prob = function(model, newdata) model$predict(new_data = newdata)
ClustPredictor$new(res, as.data.frame(multishapes), y = res$results,
predict.function = predict_prob, type = "prob")