SHARE
TWEET

Untitled

a guest Jul 23rd, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Raw <- read.csv("ptr_all_T.csv")
  2. dim(Raw)
  3. [1] 900  36
  4. Scale_Raw_Mat <- matrix(scale(Raw[,2:36]))
  5. #create som grid
  6. Scale_Raw_Mat_Grid = somgrid(xdim = 30, ydim=30, topo="hexagonal")
  7. #train som model
  8. Scale_Raw_Mat_Som = som(Scale_Raw_Mat, grid=Scale_Raw_Mat_Grid, rlen=100, alpha=c(0.05,0.01))
  9. #optomize the best number of clusters
  10. #gererate distance matrix for map lacation
  11. Dist_Map <- kohonen::unit.distances(Scale_Raw_Mat_Grid)
  12. #gererate distance matrix for codes
  13. Codes <- getCodes(Scale_Raw_Mat_Som)
  14. Dist_Codes <- as.matrix(dist(Codes))
  15. #exponentiate Euclidean distance by distance on map
  16. Dist_Exp <- Dist_Codes^Dist_Map
  17. #create plot to determine best number of clusters
  18. factoextra::fviz_nbclust(Dist_Exp, factoextra::hcut, method =
  19. "silhouette", hc_method = "ward.D2", k.max =  15)
  20. Clust_Exp = hclust(as.dist(Dist_Exp), 'ward.D2')
  21. Som_Cluster_Exp = cutree(Clust_Exp, 3)
  22. #create color for som mapping
  23.  
  24. #plot som clusters om map
  25. plot(Scale_Raw_Mat_Som, type="mapping", keep.data==TRUE, bgcol = col_vector[Som_Cluster_Exp], pchs = NA)`
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top