# 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