0
このエラーはなぜ発生しますか? 出力に基づいて私のsvmクラシファイアが動作するようですが、残りは動作しません。私はRから与えられた虹彩データセットでこれを試みました、そして、以下のコードは完全に働いていました。ただし、ロードされたデータセットで実行しようとすると、ロードされません。eval(expr、envir、enclos)のエラー:オブジェクト 'V2'が見つかりません
エラー:
Error in eval(expr, envir, enclos) : object 'V2' not found
コード:
balance_data = read.table(file.choose(), sep=",")
str(balance_data)
x <- balance_data[, c(2,3,4,5)]
y <- balance_data[,1]
X_train <-head(x,500)
Y_train <- head(y,100)
X_test <-tail(x,122)
decisionTree_Learnruntime = c()
svm_Learnruntime = c()
naivebayes_Learnruntime = c()
knn_Learnruntime = c()
decisionTree_Predictruntime = c()
svm_Predictruntime = c()
naivebayes_Predictruntime =c()
knn_Predictruntime = c()
for (i in 1:20){
library(e1071)
library(caret)
#SVM Model
start.time <- Sys.time()
svm_model <- svm(X_train,Y_train)
end.time <- Sys.time()
time.taken <- end.time - start.time
svm_Learnruntime [i]<- time.taken
#Prediction Time
start.time <- Sys.time()
pred <- predict(svm_model,X_test)
end.time <- Sys.time()
time.taken <- end.time - start.time
svm_Predictruntime [i]<- time.taken
library(rpart)
#Decision Tree
#Learn Time
start.time <- Sys.time()
tree_model <- rpart(X_train,Y_train)
end.time <- Sys.time()
time.taken <- end.time - start.time
decisionTree_Learnruntime [i]<- time.taken
#Prediction Time
start.time <- Sys.time()
pred = predict(tree_model,X_test)
end.time <- Sys.time()
time.taken <- end.time - start.time
decisionTree_Predictruntime[i] <- time.taken
#Naive Bayes
#Learn Time
start.time <- Sys.time()
naive_model <-naiveBayes(X_train,Y_train)
end.time <- Sys.time()
time.taken <- end.time - start.time
naivebayes_Learnruntime [i]<- time.taken
#Prediction Time
start.time <- Sys.time()
pred <- predict(naive_model,X_test)
end.time <- Sys.time()
time.taken <- end.time - start.time
naivebayes_Predictruntime [i]<- time.taken
}
mean(svm_Learnruntime)
mean(svm_Predictruntime)
decisionTree_Learnruntime
decisionTree_Predictruntime
naivebayes_Learnruntime
naivebayes_Predictruntime
出力
> mean(svm_Learnruntime)
[1] 0.01403713
> mean(svm_Predictruntime)
[1] 0.001003027
> decisionTree_Learnruntime
NULL
> decisionTree_Predictruntime
NULL
> naivebayes_Learnruntime
NULL
> naivebayes_Predictruntime
NULL
構造
> str(balance_data)
'data.frame': 625 obs. of 5 variables:
$ V1: Factor w/ 3 levels "B","L","R": 1 3 3 3 3 3 3 3 3 3 ...
$ V2: int 1 1 1 1 1 1 1 1 1 1 ...
$ V3: int 1 1 1 1 1 1 1 1 1 1 ...
$ V4: int 1 1 1 1 1 2 2 2 2 2 ...
$ V5: int 1 2 3 4 5 1 2 3 4 5 ...
> str(X_train)
'data.frame': 500 obs. of 4 variables:
$ V2: int 1 1 1 1 1 1 1 1 1 1 ...
$ V3: int 1 1 1 1 1 1 1 1 1 1 ...
$ V4: int 1 1 1 1 1 2 2 2 2 2 ...
$ V5: int 1 2 3 4 5 1 2 3 4 5 ...
> str(X_test)
'data.frame': 122 obs. of 4 variables:
$ V2: int 5 5 5 5 5 5 5 5 5 5 ...
$ V3: int 1 1 1 1 1 1 1 1 1 1 ...
$ V4: int 1 1 2 2 2 2 2 3 3 3 ...
$ V5: int 4 5 1 2 3 4 5 1 2 3 ...
> str(Y_train)
Factor w/ 3 levels "B","L","R": 1 3 3 3 3 3 3 3 3 3 ...