我,关于每次观察的概率输出格式的问题。
Current output:
0 1
2282 9.791608e-01 2.083920e-02
135 4.769759e-01 5.230241e-01
2036 9.807866e-01 1.921336e-02
Desired output: just like the example below produces
1 0
9 0.4268682 0.5731318
10 0.4268682 0.5731318
4 0.4268682 0.5731318
7 0.2590067 0.7409933
2 0.2590067 0.7409933
通过下面的可重复示例,我得到所需的输出为0到1之间的概率。但是,当我用另一个更大的数据集运行完全相同的代码时,我想运行我的分析,包含1100个变量和10000个观测值每个单元格都填充0或1,所以相同的数据集更大,然后我得到如上所示的当前输出。
# data preparation
A <- c(1, 0, 1, 1, 0, 0, 0, 1, 0, 0)
B <- c(1,0,1,1,1,1,0,0,1,1)
C <- c(0,1,1,1,1,1,1,1,1,1)
train <- data.frame(A, B, C)
train[] <- lapply(train, as.factor)
# randomize data
train <- train[sample(nrow(train)),]
# create 10 equal folds
number_folds <- 2
folds <- cut(seq (1, nrow(train)), breaks = number_folds, labels = FALSE)
# Vectors created to store the initialized values with 0’s
accuracy_SVM <- rep(0,number_folds)
# install packages required for SVM and NB
install.packages("e1071")
library("e1071")
# Cross validation, data segmentations and running the model
for(i in 1:number_folds){
testIndexes <- which(folds == i, arr.ind = TRUE)
testData <- train[testIndexes ,]
trainData <- train[-testIndexes ,]
SVM_model <- svm(A ~ ., data = trainData, probability = T)
classification_svm <- predict(SVM_model, testData, type ="response", probability = T)
accuracy_SVM[i] <- sum(classification_svm == testData$A) / nrow (testData)
}
attr(classification_svm, "probabilities")
很抱歉,我无法提供自己的数据集来帮助您复制相同的输出,但我无法更清楚地表达问题。非常感谢帮助! :)