0
然而,我的問題與this thread完全相同,因爲這似乎還沒有令人滿意的答案,所以我認爲再次詢問以及可重複的代碼。當用SVM模型預測時,R返回因子(0)
training <- read.csv("https://d396qusza40orc.cloudfront.net/predmachlearn/pml-training.csv")[,-1]
testing <- read.csv("https://d396qusza40orc.cloudfront.net/predmachlearn/pml-testing.csv")[,-1]
# Importing data
library(e1071)
# Load the required package for SVM
svm_model <- svm(classe ~ pitch_arm + pitch_forearm + pitch_dumbbell + pitch_belt +
roll_arm + roll_forearm + roll_dumbbell + roll_belt +
yaw_arm + yaw_forearm + yaw_dumbbell + yaw_belt,
data = training, scale = FALSE, cross = 10)
# Perform SVM analysis with default gamma and cost, and do 10-fold cross validation
predict(svm_model, testing)
# R returns factor(0) here
我已檢查測試數據框是否具有所需的所有列,並且這些所需列中不存在NA。請給我一些想法繼續。謝謝!
是的,它們屬於同一類型。感謝您的提醒! :) – ytu