入圍中插入符號錯誤SVM未定義列需要你解決下面的錯誤幫助。列車
##Loading Libraries.
library(caret)
library(kernlab)
##Loading the data
rm(list=ls())
set.seed(3421)
Extrapolation_Data <- read.table("./Data/Data5/EP_CUST_COMBINED_07042017.txt",
sep="|", header=TRUE ,
colClasses = c("X6MNTH_FTD" = "NULL" ,
"X6MNTH_LTD"="NULL" ,
"India3MLtd_TRANS" = "NULL",
"Cust_Considered" = "NULL",
"Customer_No"="character",
"Segment"="factor",
"Store"="factor",
"DISTINCT_VISITS_BAND"="factor",
"DISTINCT_MONTH_VISITS"="factor",
"CUST_SALES_BAND"="factor",
"ITEMS_PER_MONTH_BAND"="factor",
"VISITS_PER_MONTH_BAND"="factor",
"STAPLES_TRANS"="factor",
"BDF_TRANS"="factor",
"HPC_TRANS"="factor",
"PF_TRANS"="factor",
"FV_TRANS"="factor",
"PROCESS_FOOD_TRANS"="factor",
"BREAD_EGGS_TRANS"="factor",
"FROZEN_TRANS"="factor",
"MILK_TRANS"="factor",
"LAUNDRY_TRANS"="factor",
"PC_TRANS"="factor",
"DISTINCT_CLASSES_BAND"="factor",
"LAUNDRY_TRANS_1"="factor",
"Cookies_TRANS"="factor",
"ExoticFruitandVegetables_TRANS"="factor",
"Healthbiscuit_TRANS"="factor",
"Kellogs_TRANS"="factor",
"BasmatiRice_TRANS"="factor",
"Pastry_TRANS"="factor",
"Dessert_TRANS"="factor",
"Organics_TRANS"="factor",
"PaperandTissue_TRANS"="factor",
"Almonds_TRANS"="factor",
"Pears_TRANS"="factor",
"GingellyOil_TRANS"="factor",
"Yoghurt_TRANS"="factor",
"Dove_TRANS"="factor",
"Mayonnaise_TRANS"="factor",
"PeanutButter_TRANS"="factor",
"HealthDietFood_TRANS"="factor",
"OliveOil_TRANS"="factor",
"ShowerGel_TRANS"="factor",
"ChocolateSpread_TRANS"="factor",
"Continental_TRANS"="factor",
"GarbageBag_TRANS"="factor",
"ReadytoEat_TRANS"="factor",
"ToiletPaper_TRANS"="factor",
"MOP_TRANS"="factor",
"IceTea_TRANS"="factor",
"ShowerandBath_TRANS"="factor",
"CarCare_TRANS"="factor",
"PetFood_TRANS"="factor",
"Muesli_TRANS"="factor",
"CottonBall_TRANS"="factor",
"CannedFood_TRANS"="factor",
"PremiumVegetables_TRANS"="factor",
"Maybelline_TRANS"="factor",
"PremixCoffee_TRANS"="factor",
"ImportedCigarettes_TRANS"="factor",
"MicrowaveItems_TRANS"="factor",
"Housekeeping.Plugin_TRANS"="factor",
"YogaMat_TRANS"="factor",
"Moti_TRANS"="factor",
"Toys_TRANS"="factor",
"Loreal_TRANS"="factor",
"AdultsBooks_TRANS"="factor",
"Gala_TRANS"="factor",
"Revlon_TRANS"="factor"))
## Dividing the data in Train Test.
indexes = sample(nrow(Extrapolation_Data),
size=0.2*nrow(Extrapolation_Data), replace= FALSE)
TrainData <- Extrapolation_Data[-indexes,]
TestData <- Extrapolation_Data[indexes,]
##Creating new column Segment_C from Segment
TrainData$Segment_C <- as.factor(ifelse(TrainData$Segment=="C", "Y" , "N"))
TestData$Segment_C <- as.factor(ifelse(TestData$Segment=="C", "Y" , "N"))
## No Null Values
sum(is.na(TrainData))
# [1] 0
fitControl <- trainControl(method = "cv", number = 1,repeats = 2,
summaryFunction = twoClassSummary)
set.seed(10001)
## Executing the below query is giving me error
SVMFit <- train(Segment_C ~ TENURE + CUST_SALES + VISITS_PER_MONTH + FROZEN_TRANS +
MILK_TRANS + PC_TRANS + Cookies_TRANS,
data=TrainData, method="lssvmPoly",
trControl = fitControl , metric = "Kappa")
錯誤:
Error in [.data.frame(data, , lvls[1]) : undefined columns selected
我失去了什麼?我的任何變量是否有誤?
任何幫助,非常感謝。
更新代碼的格式,標題,錯誤消息和語法的可讀性 – Parfait
看起來像你缺少從「CUST_SALES」和「VISITS_PER_MONTH」,「_BAND」這根據您的讀入代碼,兩者都應該有「_BAND」後綴。 – Nate
SVMFit <-train(Segment_C〜MILK_TRANS,數據= TrainData,方法= 「lssvmPoly」,trControl = fitControl,度量= 「卡帕」)即使這是給我相同的錯誤 – BhavinNagda