2017-04-14 9 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

アップデートコードのフォーマット、タイトル、エラーメッセージが表示されている、とあなたは「CUST_SALES」と「VISITS_PER_MONTH」から「_BANDを」欠けているように、読みやすく – Parfait

+0

ための文法が見え、どちらも、あなたの読み込みコードに基づいて "_BAND"接尾辞を持つ必要があります。 – Nate

+0

SVMFit <-train(Segment_C〜MILK_TRANS、data = TrainData、method = "lssvmPoly"、trControl = fitControl、metric = "Kappa")これは私にも同じエラー – BhavinNagda

答えて

0

変数名誤っ以下statement-- SVMFit < -train(Segment_C〜保有+ CUST_SALES + VISITS_PER_MONTH + FROZEN_TRANS + MILK_TRANS + PC_TRANS + Cookies_TRANS、データ= TrainData、方法= "lssvmPoly"、trControl =で定義されていますfitControl、metric = "Kappa")

元のデータにはvarが含まれていません。 「Tenure」と名付けられた。 だけでなく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 任期 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

関連する問題