Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

226 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

kohonen

R-CMD-check

The kohonen R package trains supervised and unsupervised self-organizing maps (SOMs), maps new observations to trained maps, generates predictions, and visualizes and interrogates map structure. It supports online and batch training, parallel batch training, multiple data layers with separate distance measures, and both rectangular and hexagonal grids.

Installation

Install this fork from GitHub:

remotes::install_github("AngusWright/kohonen/kohonen")

Using the package

The standard API is centred on supersom(), with som() and xyf() as single-layer and supervised convenience wrappers. Train a map, map observations with map() or predict(), and inspect it with summary(), getCodes(), and plot(). The built-in plot types include codebook vectors, training changes, mapping locations, counts, per-unit properties, representation quality, and neighbour-distance (U-matrix) plots.

This fork also provides a high-level workflow for tabular catalogues:

library(kohonen)

som_map <- kohtrain(
  data = training_data,
  train.expr = c("feature_1", "feature_2", "feature_1 - feature_2"),
  som.dim = c(20, 20)
)

som_map <- kohparse(som_map, new_data)
som_map <- generate.kohgroups(som_map, n.cluster.bins = 20)

group_properties <- generate.kohgroup.property(
  som_map,
  new_data,
  expression = "mean(data$feature_1, na.rm = TRUE)",
  expr.label = "mean_feature_1"
)

plot(som_map, type = "counts")
plot(som_map, type = "property",
     property = group_properties$property$mean_feature_1)

train.expr accepts column names and R expressions evaluated against data. kohtrain() evaluates and robustly scales these features, handles configured missing values and thresholds, can train from a sparse random or weighted sample, and stores the scaling parameters on the returned map. Use kohparse() to apply those same parameters to new data and assign each usable row to its best-matching unit. Set n.cores when parallel parsing or training is appropriate.

Additions to base (CRAN) version

This repository is a fork of the CRAN package and retains its core SOM API. Its fork-specific additions focus on catalogue-oriented preprocessing, clustering, and visualisation:

  • kohtrain() is a high-level training wrapper that prepares expression-based input features, optionally whitens them, supports sparse training samples, and records the preprocessing metadata needed for later parsing.
  • kohparse() applies a trained map's saved whitening parameters to new data, maps valid rows to best-matching units, and refreshes existing group classifications when applicable.
  • generate.kohgroups() hierarchically clusters codebook vectors into a requested number of groups and stores both cell-level and observation-level group assignments on the map. It can also parse and group a supplied new dataset in one call.
  • generate.kohgroup.property() evaluates one or more expressions for every generated group and returns a group-level property table together with the updated map. This makes group statistics directly usable in downstream analysis and property plots.
  • Plotting is extended for these group assignments: count plots can use clustered classifications and subsets, while property plots accept either cell-level or group-level values. The plotting helpers also add logarithmic colour scaling, percentile-based colour limits, configurable out-of-range colours, and heat-key controls.

References

About

Supervised and unsupervised self-organising maps

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages