【发布时间】:2018-01-15 04:38:11
【问题描述】:
我正在尝试为som 地图编写脚本。它来自这个tutorial。我的问题是 Rstudio 不起作用。我有这个代码:
require(kohonen)
# Create a training data set (rows are samples, columns are variables
# Here I am selecting a subset of my variables available in "data"
data_train <- data[, c(2,4,5,8)]
# Change the data frame with training data to a matrix
# Also center and scale all variables to give them equal importance during
# the SOM training process.
data_train_matrix <- as.matrix(scale(data_train))
# Create the SOM Grid - you generally have to specify the size of the
# training grid prior to training the SOM. Hexagonal and Circular
# topologies are possible
som_grid <- somgrid(xdim = 20, ydim=20, topo="hexagonal")
# Finally, train the SOM, options for the number of iterations,
# the learning rates, and the neighbourhood are available
som_model <- som(data_train_matrix,
grid=som_grid,
rlen=500,
alpha=c(0.05,0.01),
keep.data = TRUE )
plot(som_model, type="changes")
如果我尝试运行这个脚本,它会写出这个错误:
Error in supersom(list(X), ...) : object 'data_train_matrix' not found
> plot(som_model, type="changes")
Error in plot(som_model, type = "changes") : object 'som_model' not found
我不明白这一点。没有data_train_matrix是什么意思?我之前有data_train_matrix 几行。当我只运行前 3 行代码(到data_train_matrix <- as.matrix(scale(data_train)))时,它会写出这个错误:
data_train_matrix <- as.matrix(scale(data_train))
Error in scale(data_train) : object 'data_train' not found
当我只运行前两行时它写道:
data_train <- data[, c(2,4,5,8)]
Error in data[, c(2, 4, 5, 8)] :
object of type 'closure' is not subsettable
当我使用相同的代码有这么多错误时,这段代码怎么可能在教程中工作?
【问题讨论】:
-
你安装了kohonen然后激活了吗?