#------------------ # Data Preparation #------------------ #Read datasets #Download the data from http://www.saedsayad.com/datasets/BikeRental.zip train <- read.csv("bike_rental_train.csv") test <- read.csv("bike_rental_test.csv") #Rows and Cols dim(train) dim(test) #Columns name colnames(train) colnames(test) #Show head(train) head(test) #Rows and Cols dim(train) dim(test) #Columns name colnames(train) colnames(test) #Show head(train) head(test) #--------------------------- # Self-Organizing Map (SOM) #--------------------------- library(kohonen) #Data matrix train.matrix <- as.matrix(scale(train)) #Create the SOM Grid som_grid <- somgrid(xdim = 20, ydim=20, topo="hexagonal") #Train model.SOM <- som(train.matrix, grid=som_grid, rlen=100, alpha=c(0.05,0.01), keep.data = TRUE, n.hood='circular') #Plot training progress plot(model.SOM, type="changes") #Plot node counts plot(model.SOM, type="count") #Plot neighbors distance plot(model.SOM, type="dist.neighbours") #Heatmap plot(model.SOM, type = "property", property = model.SOM$codes[,4], main=names(model.SOM$data)[4])