列車

2017-04-14 24 views
0

入圍中插入符號錯誤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

我失去了什麼?我的任何變量是否有誤?

任何幫助,非常感謝。

+0

更新代碼的格式,標題,錯誤消息和語法的可讀性 – Parfait

+0

看起來像你缺少從「CUST_SALES」和「VISITS_PER_MONTH」,「_BAND」這根據您的讀入代碼,兩者都應該有「_BAND」後綴。 – Nate

+0

SVMFit <-train(Segment_C〜MILK_TRANS,數據= TrainData,方法= 「lssvmPoly」,trControl = fitControl,度量= 「卡帕」)即使這是給我相同的錯誤 – BhavinNagda

回答

0

變量名稱在下面statement-- SVMFit < -train(Segment_C〜TENURE定義不正確+ CUST_SALES + VISITS_PER_MONTH + FROZEN_TRANS + MILK_TRANS + PC_TRANS + Cookies_TRANS,數據= TrainData,方法= 「lssvmPoly」,trControl = fitControl,度量=「卡帕」)

原始數據不包含變種命名爲「任期」。 除了CUST_SALES,VISITS_PER_MONTH:原始變量名是CUST_SALES_BAND和VISITS_PER_MONTH_BAND

+0

三江源。那對我來說太愚蠢了。謝謝。 – BhavinNagda

+0

看看名字(Extrapolation_Data)CUSTOMER_NO 商店 DISTINCT_VISITS_BAND CUST_SALES 新舊程度 TOTAL_ITEMS ITEMS_PER_MONTH_BAND VISITS_PER_MONTH_BAND BDF_TRANS PF_TRANS PROCESS_FOOD_TRANS FROZEN_TRANS LAUNDRY_TRANS DISTINCT_ITEMS DISTINCT_CLASSES_BAND DISTINCT_DEPTS LAUNDRY_TRANS_1 ExoticFruitandVegetables_TRANS Kellogs_TRANS Pastry_TRANS 個Organics_TRANS Almonds_TRANS GingellyOil_TRANS Dove_TRANS PeanutButter_TRANS OliveOil_TRANS ChocolateSpread_TRANS GarbageBag_TRANS ToiletPaper_TRANS IceTea_TRANS CarCare_TRANS Muesli_TRANS CannedFood_TRANS – BhavinNagda

+0

Maybelline_TRANS ImportedCigarettes_TRANS 管家。Plugin_TRANS Moti_TRANS Loreal_TRANS Gala_TRANS 段 DISTINCT_VISITS DISTINCT_MONTH_VISITS CUST_SALES_BAND TENURE ITEMS_PER_MONTH VISITS_PER_MONTH STAPLES_TRANS HPC_TRANS FV_TRANS BREAD_EGGS_TRANS MILK_TRANS PC_TRANS DISTINCT_CLASSES DISTINCT_SUBCLASSES DISTINCT_DIVISIONS Cookies_TRANS Healthbiscuit_TRANS 個BasmatiRice_TRANS Dessert_TRANS PaperandTissue_TRANS Pears_TRANS Yoghurt_TRANS Mayonnaise_TRANS HealthDietFood_TRANS ShowerGel_TRANS Continental_TRANS ReadytoEat_TRANS MOP_TRANS ShowerandBath_TRANS – BhavinNagda