我正在尝试R中的subervised SOM,它适用于R版本3.1.0但不适用于3.3.2。这是它在3.1.0中正常工作:
> fitControl <- trainControl(method = "repeatedcv",number = 10,repeats = 10)
> somFit1 <- train(Species ~ ., data = iris, method = "xyf",preProc = c("center","scale"),trControl = fitControl,metric="Kappa")
Loading required package: kohonen
Loading required package: class
Loading required package: MASS
Warning messages:
1: package ‘kohonen’ was built under R version 3.1.3
2: package ‘class’ was built under R version 3.1.3
3: package ‘MASS’ was built under R version 3.1.3
> somFit1
Self-Organizing Maps
150 samples
4 predictor
3 classes: 'setosa', 'versicolor', 'virginica'
Pre-processing: centered (4), scaled (4)
Resampling: Cross-Validated (10 fold, repeated 10 times)
Summary of sample sizes: 135, 135, 135, 135, 135, 135, ...
Resampling results across tuning parameters:
xdim ydim xweight Accuracy Kappa Accuracy SD Kappa SD
1 2 0.5 0.6666667 0.500 0.00000000 0.00000000
1 2 0.7 0.6666667 0.500 0.00000000 0.00000000
1 2 0.9 0.6666667 0.500 0.00000000 0.00000000
1 3 0.5 0.8040000 0.706 0.12128012 0.18192017
1 3 0.7 0.8140000 0.721 0.11996820 0.17995229
1 3 0.9 0.8240000 0.736 0.09309252 0.13963878
1 4 0.5 0.8806667 0.821 0.08384423 0.12576634
1 4 0.7 0.8953333 0.843 0.07043555 0.10565333
1 4 0.9 0.8386667 0.758 0.08693819 0.13040729
2 2 0.5 0.8960000 0.844 0.08649296 0.12973944
2 2 0.7 0.8833333 0.825 0.09057740 0.13586610
2 2 0.9 0.8313333 0.747 0.08499290 0.12748935
2 3 0.5 0.8793333 0.819 0.07796226 0.11694339
2 3 0.7 0.9100000 0.865 0.07602646 0.11403969
2 3 0.9 0.9326667 0.899 0.06930471 0.10395706
2 4 0.5 0.9106667 0.866 0.06977276 0.10465914
2 4 0.7 0.9193333 0.879 0.07478814 0.11218221
2 4 0.9 0.9453333 0.918 0.06021287 0.09031930
3 3 0.5 0.9333333 0.900 0.05763775 0.08645662
3 3 0.7 0.9353333 0.903 0.06317808 0.09476713
3 3 0.9 0.9440000 0.916 0.05336699 0.08005049
3 4 0.5 0.9406667 0.911 0.06205967 0.09308951
3 4 0.7 0.9366667 0.905 0.06658244 0.09987366
3 4 0.9 0.9480000 0.922 0.05808775 0.08713162
Tuning parameter 'topo' was held constant at a value of hexagonal
Kappa was used to select the optimal model using the largest value.
The final values used for the model were xdim = 3, ydim = 4, xweight = 0.9
and topo = hexagonal.
这里它不适用于3.3.2:
> fitControl <- trainControl(method = "repeatedcv",number = 10,repeats = 10)
> somFit1 <- train(Species ~ ., data = iris, method = "xyf",preProc = c("center","scale"),trControl = fitControl,metric="Kappa")
Loading required package: kohonen
Something is wrong; all the Kappa metric values are missing:
Accuracy Kappa
Min. : NA Min. : NA
1st Qu.: NA 1st Qu.: NA
Median : NA Median : NA
Mean :NaN Mean :NaN
3rd Qu.: NA 3rd Qu.: NA
Max. : NA Max. : NA
NA's :24 NA's :24
Error in train.default(x, y, weights = w, ...) : Stopping
In addition: There were 50 or more warnings (use warnings() to see the first 50)
警告是:
Warning messages:
1: package ‘kohonen’ was built under R version 3.3.3
2: In eval(expr, envir, enclos) :
model fit failed for Fold01.Rep01: xdim=1, ydim=2, xweight=0.5, topo=hexagonal Error in supersom(list(X, Y), ...) :
unused arguments (xweight = 0.5, contin = FALSE)
3: In eval(expr, envir, enclos) :
model fit failed for Fold01.Rep01: xdim=2, ydim=2, xweight=0.5, topo=hexagonal Error in supersom(list(X, Y), ...) :
unused arguments (xweight = 0.5, contin = FALSE)
我觉得未使用的问题很重要。在过去,我有一些错误信息,当我删除多余的&#34; verbose = FALSE&#34;插入符号中的参数。但是在这里我不知道如何停止xweight并继续通过。感谢。
答案 0 :(得分:0)
我现在才看到这一点,我正在处理SOM in caret。但似乎你没有包含user.weights。 首先,我正在使用Windows ;-(但是嘿嘿.. 使用并行处理来加快速度:
install.packages("doParallel")
library(doParallel) # https://github.com/tobigithub/R-parallel/wiki/
library(foreach)
#Register cores -1 to allow one core for other work
cl <- makeCluster(detectCores()-1)
registerDoParallel(cl)
getDoParWorkers()
现在我有一个预处理,训练控制和调谐网格。然后我终于训练并记录训练SOM所需的时间
C_preProcess.method <- c("zv", "nzv", "corr", "center", "scale")
fitControl2 <- trainControl(method = "repeatedcv", number = 10, repeats = 5, savePredictions = 'final', classProbs = TRUE, summaryFunction=twoClassSummary)
tg5 <- expand.grid(xdim = c(20,10), ydim=c(20,10), user.weights=c(1,3), topo="hexagonal") #seq(from = 1, to = 10, by = 1))
t5<-system.time(Fit5 <- train(shares ~ ., data = caret.train.data, method = 'xyf', preProcess= C_preProcess.method, metric = "ROC", trControl = fitControl2, tuneGrid=tg5))
我希望这可以帮助那些人...