Learn R Programming

GowerSom (version 0.1.0)

gsom_predict: Predict BMUs for new data using a fitted Gower-SOM

Description

Maps new observations to their Best Matching Units (BMUs) using the codebook and grid stored in a fitted gowersom object.

Usage

gsom_predict(object, newdata, ...)

Value

A data.frame with the following columns:

bmu

Integer BMU index (1 .. n_rows * n_cols).

distance

Numeric Gower distance to the BMU.

row

Integer, BMU grid row coordinate.

col

Integer, BMU grid column coordinate.

Arguments

object

A gowersom object returned by gsom_Training().

newdata

A data.frame of new observations to map. Must be typed consistently with the training data (numeric, factor, etc.).

...

Additional arguments passed to internal functions (not used).

Author

Patricio Sáez <patricsaez@udec.cl>; Patricio Salas <patricioasalas@udec.cl>

Details

This function is a convenience wrapper around get_bmu_gower. It automatically extracts the grid dimensions from object\$coords and applies BMU mapping for each observation in newdata.

References

Sáez, P., Salas, P. Gower-SOM: a self-organizing map for mixed data with gower distance and heuristic adaptation for data analytics. Int J Data Sci Anal 22, 26 (2026). https://doi.org/10.1007/s41060-025-00941-6/."

See Also

get_bmu_gower

Examples

Run this code
set.seed(1)
df <- data.frame(
  x1 = rnorm(20),
  x2 = rnorm(20),
  g  = factor(sample(letters[1:3], 20, TRUE))
)
fit <- gsom_Training(df, grid_rows = 3, grid_cols = 3,
                num_iterations = 5, batch_size = 4)

# Map observations to BMUs
pred <- gsom_predict(fit, df)
head(pred)

Run the code above in your browser using DataLab