SomParam-class | R Documentation |
Use the self-organizing map implementation in the kohonen package to cluster observations into the specified number of nodes. Note that this requires the installation of the kohonen package.
SomParam(
centers,
dim.ratio = 1,
topo = "rectangular",
neighbourhood.fct = "bubble",
toroidal = FALSE,
rlen = 100,
alpha = c(0.05, 0.01),
radius = NULL,
dist.fct = "sumofsquares"
)
## S4 method for signature 'ANY,SomParam'
clusterRows(x, BLUSPARAM, full = FALSE)
centers |
An integer scalar specifying the number of centers. Alternatively, a function that takes the number of observations and returns the number of centers. |
dim.ratio |
A positive numeric scalar in specifying how |
topo , neighbourhood.fct , toroidal |
Further arguments to pass to the |
rlen , alpha , radius , dist.fct |
Further arguments to pass to the |
x |
A numeric matrix-like object where rows represent observations and columns represent variables. |
BLUSPARAM |
A SomParam object. |
full |
Logical scalar indicating whether the full SOM statistics should be returned. |
This class usually requires the user to specify the number of clusters beforehand. However, we can also allow the number of clusters to vary as a function of the number of observations. The latter is occasionally useful, e.g., to allow the clustering to automatically become more granular for large datasets.
Note that the final number of clusters may not be exactly equal to centers
, depending on how dim.ratio
is specified.
For example, if centers
is a perfect square and dim.ratio=1
, we will get exactly the requested number of points.
To modify an existing SomParam object x
,
users can simply call x[[i]]
or x[[i]] <- value
where i
is any argument used in the constructor.
For radius
, a value of NULL
means that the default argument in the som
function signature is used.
This is are data-dependent and so cannot be specified during construction of the SomParam object.
For dist.fct
, users can specify any string that can be used in the dist.fcts
arguments in som
.
In practice, the only real alternative is "manhattan"
.
The SomParam
constructor will return a SomParam object with the specified parameters.
The clusterRows
method will return a factor of length equal to nrow(x)
containing the cluster assignments.
If full=TRUE
, a list is returned with clusters
(the factor, as above) and objects
(a list containing som
, the direct output of som
).
Aaron Lun
som
from the kohonen package, which does all of the heavy lifting.
FixedNumberParam, the parent of the SomParam class.
clusterRows(iris[,1:4], SomParam(centers=16))
clusterRows(iris[,1:4], SomParam(centers=12, dim.ratio=3/4))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.