2014-07-17 5 views
9

मैंने आर कैरेट के साथ एक पेड़ मॉडल को प्रशिक्षित किया है। अब मैं एक भ्रम मैट्रिक्स उत्पन्न करने के लिए कोशिश कर रहा हूँ और निम्न त्रुटि प्राप्त हो रही है: जब भ्रम की स्थिति पैदा करने मैट्रिक्सConfusionMatrix में त्रुटि डेटा और संदर्भ कारकों में स्तरों की समान संख्या होनी चाहिए R CARET

Error in confusionMatrix.default(predictionsTree, testdata$catgeory) : the data and reference factors must have the same number of levels

prob <- 0.5 #Specify class split 
singleSplit <- createDataPartition(modellingData2$category, p=prob, 
            times=1, list=FALSE) 
cvControl <- trainControl(method="repeatedcv", number=10, repeats=5) 
traindata <- modellingData2[singleSplit,] 
testdata <- modellingData2[-singleSplit,] 
treeFit <- train(traindata$category~., data=traindata, 
       trControl=cvControl, method="rpart", tuneLength=10) 
predictionsTree <- predict(treeFit, testdata) 
confusionMatrix(predictionsTree, testdata$catgeory) 

त्रुटि तब होती है। दोनों वस्तुओं पर स्तर समान हैं। मैं समझ नहीं सकता कि समस्या क्या है। उनकी संरचना और स्तर नीचे दिए गए हैं। वे वही होना चाहिए। किसी भी मदद की सराहना की जाएगी क्योंकि यह मुझे क्रैक कर रहा है !!

> str(predictionsTree) 
Factor w/ 30 levels "16-Merchant Service Charge",..: 28 22 22 22 22 6 6 6 6 6 ... 
> str(testdata$category) 
Factor w/ 30 levels "16-Merchant Service Charge",..: 30 30 7 7 7 7 7 30 7 7 ... 

> levels(predictionsTree) 
[1] "16-Merchant Service Charge" "17-Unpaid Cheque Fee"   "18-Gov. Stamp Duty"   "Misc"       "26-Standard Transfer Charge" 
[6] "29-Bank Giro Credit"   "3-Cheques Debit"    "32-Standing Order - Debit" "33-Inter Branch Payment"  "34-International"    
[11] "35-Point of Sale"    "39-Direct Debits Received" "4-Notified Bank Fees"   "40-Cash Lodged"    "42-International Receipts" 
[16] "46-Direct Debits Paid"  "56-Credit Card Receipts"  "57-Inter Branch"    "58-Unpaid Items"    "59-Inter Company Transfers" 
[21] "6-Notified Interest Credited" "61-Domestic"     "64-Charge Refund"    "66-Inter Company Transfers" "67-Suppliers"     
[26] "68-Payroll"     "69-Domestic"     "73-Credit Card Payments"  "82-CHAPS Fee"     "Uncategorised" 

> levels(testdata$category) 
[1] "16-Merchant Service Charge" "17-Unpaid Cheque Fee"   "18-Gov. Stamp Duty"   "Misc"       "26-Standard Transfer Charge" 
[6] "29-Bank Giro Credit"   "3-Cheques Debit"    "32-Standing Order - Debit" "33-Inter Branch Payment"  "34-International"    
[11] "35-Point of Sale"    "39-Direct Debits Received" "4-Notified Bank Fees"   "40-Cash Lodged"    "42-International Receipts" 
[16] "46-Direct Debits Paid"  "56-Credit Card Receipts"  "57-Inter Branch"    "58-Unpaid Items"    "59-Inter Company Transfers" 
[21] "6-Notified Interest Credited" "61-Domestic"     "64-Charge Refund"    "66-Inter Company Transfers" "67-Suppliers"     
[26] "68-Payroll"     "69-Domestic"     "73-Credit Card Payments"  "82-CHAPS Fee"     "Uncategorised"  
+0

आपकी त्रुटि में, 'श्रेणी'' वर्तनी 'वर्तनी है। यदि समस्या से संबंधित नहीं है, तो समान (स्तर (पूर्वानुमान (ट्री), स्तर (testdata $ श्रेणी)) का आउटपुट क्या है? – fxi

+0

हाय के लिए धन्यवाद, मैंने मूर्खतापूर्ण वर्तनी गलती की है .... दोह !!! मैंने समान फ़ंक्शन चलाया और इसे आउटपुट किया [1] TRUE ......... अब जब मैं भ्रम चलाता हूं तो मुझे निम्न त्रुटि मिल रही है मैट्रिक्स फ़ंक्शन ..... तालिका में त्रुटि (डेटा, संदर्भ, dnn = डीएनएन, ...): सभी तर्कों में एक ही लंबाई – user2987739

+0

एक और गलत वर्तनी 'catgeory' की जांच करनी चाहिए,' लंबाई (testdata $ श्रेणी) 'और 'लंबाई (भविष्यवाणियां ट्री' की जांच करें, दोनों वैक्टरों का सारांश भी देखें। यदि आप बस एक साधारण भ्रम मैट्रिक्स चाहते हैं: 'तालिका (भविष्यवाणियां, testdata $ श्रेणी) ' – fxi

उत्तर

1

शायद आपका मॉडल एक निश्चित कारक की भविष्यवाणी नहीं कर रहा है। यह देखने के लिए कि क्या समस्या है, भ्रम के बजाय तालिका() फ़ंक्शन का उपयोग करें।

+1

आप इसे टिप्पणी के रूप में जोड़ सकते हैं। –

-2

परीक्षण डेटा में अनुपलब्ध मान हो सकते हैं, "भविष्यवाणियों < - एनएएस को हटाने के लिए पूर्वानुमान (पेड़फिट, टेस्टडाटा)" से पहले निम्नलिखित पंक्ति जोड़ें। मुझे एक ही त्रुटि थी और अब यह मेरे लिए काम करता है।

testdata <- testdata[complete.cases(testdata),] 
0

लंबाई समस्या आप में चला रहे हैं शायद प्रशिक्षण सेट में NAS की उपस्थिति के कारण है - या तो मामले हैं, जिनके पूरे नहीं हुए हैं ड्रॉप, या तो आरोपित है कि आप अनुपलब्ध मान नहीं है।

0

na.action विकल्प के लिए na.pass निर्दिष्ट करने का प्रयास:

predictionsTree <- predict(treeFit, testdata,na.action = na.pass) 
0

मैं एक ही मुद्दा था, लेकिन आगे चला गया और इतने की तरह डेटा फ़ाइल को पढ़ने के बाद इसे बदल ..

data = na.omit(data)

सभी सूचक के लिए

धन्यवाद !

संबंधित मुद्दे

 संबंधित मुद्दे