I"ve trained a linear Regression design with R caret. I"m now trying to generate a man matrix and keep getting the adhering to error:

Error in confusionMatrix.default(pred, testing$Final): the data and reference components must have actually the same number of levels







confusionMatrix(predictionsTree, testdata$catgeory)




The error occurs as soon as generating the confusion matrix. The levels are the same on both objects. Ns can’t figure out what the difficulty is. Their structure and also levels are offered below. They need to be the same. Any help would be substantially appreciated as its do me cracked!!

> strpred)

chr<1:148> " 85"" 84"" 87"" 65" "88" "84" "82" "84" "65" "78" "78" "88" "85""86" "77" ...

You are watching: The data must contain some levels that overlap the reference.

> str(testing$Final)

int <1:148> 88 85 86 70 85 85 79 85 62 77 ...

> levels(pred)


> levels(testing$Final)


Please log in in or register to add a comment.

Please log in in or register to price this question.

1 Answer

0 votes
answeredJun 25, 2019by vinita(108k points)editedSep 18, 2019by vinita

Whenever you try to construct a man matrix, make sure that both the true values and the forecast values space of “factor” data-type.

Here both pred and also testing$Final have to be of datatype factor. Right here testing$Final is of form int, convert it to factor and then develop the man matrix.

confusionMatrix(factor(pred, levels=1:490), factor(testing$final, levels=1:490))

We have to keep in mind the both levels need to be the same.

table(factor(pred, levels=min(test):max(test)), factor(test, levels=min(test):max(test)))// table is name the man matrix

It should provide you exactly the very same confusion matrix similar to the function.

You can also read the artificial Intelligence Tutorial and join AI course to get a sparkling begin for your AI journey.

See more: _____ Increase In Importance As Managers Rise Through The Management Hierarchy.

If you want to make her career in synthetic Intelligence then go through this video:

Please log in or it is registered to include a comment.

Related questions

0 votes
2 answers
Error in Confusion matrix : the data and reference determinants must have actually the same number of levels
askedJul 26, 2019in maker Learningby ParasSharma1(19k points)
0 votes
1 answer
Why am ns receiving this error: `data` and also `reference` need to be determinants with the same levels
askedMay 20, 2020in Data Scienceby blackindya(18.4k points)
0 votes
1 answer
How to interpret scikit"s find out confusion matrix and also classification report?
askedJul 18, 2019in machine Learningby ParasSharma1(19k points)
0 votes
1 answer
Right naming of confusion matrix in scikit
askedJul 29, 2019in Pythonby Rajesh Malhotra(19.9k points)
0 votes
1 answer
How to compose a confusion procession in Python?
askedJul 5, 2019in an equipment Learningby ParasSharma1(19k points)
Welcome to urbanbreathnyc.com Community. Gain your technical queries reply by optimal developers!

28.4k questions

29.7k answers


93.5k users

Popular Questions
Browse Categories

Post Graduate Programs

Certification in Digital Marketing |Certification in huge Data analysis |Certification in Cloud & Devops |Certification in complete Stack net Development

Popular master Courses

Big Data and also Data science Master’s course |Data scientific research Architect Master’s program |Cloud and also DevOps Architect Master’s food |Artificial knowledge Engineer Master’s food |Microsoft Azure Certification Master’s Training

Popular Courses

Data science Course digital |Big Data Hadoop Certification cultivate |Machine learning Course virtual |Artificial intelligence Course and Training |Salesforce Certification Training: Administrator and App Builder |Tableau Training and Certification food |Python Data scientific research Course & maintain |Ethical Hacking food |Business Analyst food |Courses in Cyber Security