Unraveling the Secret Code: How to Identify Correct Inputs for SOM Nodes
I will add to your code a few changes.
#find which node is white
q <- getCodes(som_model)[,4]
for (i in 1:length(q)){
if(q[i]>2){
t<- q[i]
}
}
#find name od node
node <- names(t)
#remove "V" letter from node name
mynode <- gsub("V","",node)
#find which node has which input ???
mydata2 <- som_model$unit.classif
print(mydata2)
#choose just imputs which go to right node
result <- vector('list',length(mydata2))
for (i in 1:length(mydata2)){
result <- cbind(result, som_model$unit.classif== mynode)
}
#remove FALSE results
result2 <- which(rowSums(result) == 1)
#write all input line
for (i in 1:length(result2)){
print(data[result2[i],])
}
Also I noticed that you were missing a rowNames() function for data. So, the corrected version is:
#find which node is white
q <- getCodes(som_model)[,4]
for (i in 1:length(q)){
if(q[i]>2){
t<- q[i]
}
}
#find name od node
node <- names(t)
#remove "V" letter from node name
mynode <- gsub("V","",node)
#find which node has which input ???
mydata2 <- som_model$unit.classif
print(mydata2)
#choose just imputs which go to right node
result <- vector('list',length(mydata2))
for (i in 1:length(mydata2)){
result[[i]] <- cbind(som_model$unit.classif== mynode)
}
#remove FALSE results
result2 <- which(rowSums(result) == 1)
#write all input line
for (i in 1:length(result2)){
print(data[result2[i],,])
}
Last modified on 2023-09-11