################
# Example 1
################
# Get some data
data("iris")
s = sample(1:150, 100)
train_set = iris[s,1:4]
test_set = iris[-s,1:4]
# Train GrowingSOM
gsom_map <- train.gsom(train_set, spreadFactor=0.8)
# Some Plots
plot(gsom_map, type = "training")
plot(gsom_map, type="count")
par(mfrow=c(2,2))
plot(gsom_map, type="property")
par(mfrow=c(1,1))
# Map new data
gsom_mapped = map.gsom(gsom_map, test_set)
plot(gsom_mapped)
################
# Example 2
################
# load data
data("auto_mpg")
s = sample(1:392, 300)
train_set = auto_mpg[s,1:8]
test_set = auto_mpg[-s,1:8]
# Train Gsom Model (hexagonal grid)
gsom_map <- train_xy.gsom(train_set[,2:8], train_set[,1], spreadFactor = 0.9, nhood="hex")
print(gsom_map)
plot(gsom_map, type = "predict")
# Predict mpg for the test set
gsom_predictions = predict.gsom(gsom_map, test_set[,2:8])
Run the code above in your browser using DataLab