in Education by
I've trained a Linear Regression model with R caret. I'm now trying to generate a confusion matrix and keep getting the following error: Error in confusionMatrix.default(pred, testing$Final): the data and reference factors must have the same number of levels EnglishMarks <- read.csv("E:/Subject Wise Data/EnglishMarks.csv", header=TRUE) inTrain<-createDataPartition(y=EnglishMarks$Final,p=0.7,list=FALSE) training<-EnglishMarks[inTrain,] testing<-EnglishMarks[-inTrain,] predictionsTree <- predict(treeFit, testdata) confusionMatrix(predictionsTree, testdata$catgeory) modFit<-train(Final~UT1+UT2+HalfYearly+UT3+UT4,method="lm",data=training) pred<-format(round(predict(modFit,testing))) confusionMatrix(pred,testing$Final) The error occurs when generating the confusion matrix. The levels are the same on both objects. I can’t figure out what the problem is. Their structure and levels are given below. They should be the same. Any help would be greatly appreciated as its making me cracked!! > strpred) chr[1:148] " 85"" 84"" 87"" 65" "88" "84" "82" "84" "65" "78" "78" "88" "85" "86" "77" ... > str(testing$Final) int [1:148] 88 85 86 70 85 85 79 85 62 77 ... > levels(pred) NULL > levels(testing$Final) NULL Select the correct answer from above options

1 Answer

0 votes
by
 
Best answer
Whenever you try to build a confusion matrix, make sure that both the true values and the prediction values are of “factor” data-type. Here both pred and testing$Final must be of datatype factor. Here testing$Final is of type int, convert it to factor and then build the confusion matrix. confusionMatrix(factor(pred, levels=1:490), factor(testing$final, levels=1:490)) We have to keep in mind that both levels should be the same. table(factor(pred, levels=min(test):max(test)), factor(test, levels=min(test):max(test)))// table is name the confusion matrix It should give you exactly the same confusion matrix as with the function. You can also read the Artificial Intelligence Tutorial and join AI Course to get a sparkling start for your AI journey. If you want to make your career in Artificial Intelligence then go through this video:

Related questions

0 votes
    I'm learning the difference between the various machine learning algorithms. I understand that the implementations of ... for that? Select the correct answer from above options...
asked Jan 25, 2022 in Education by JackTerrance
0 votes
    It is a principal question, regarding the theory of neural networks: Why do we have to normalize the input for ... is not normalized? Select the correct answer from above options...
asked Jan 27, 2022 in Education by JackTerrance
0 votes
    I am receiving the error: ValueError: Wrong number of items passed 3, placement implies 1, and I am struggling to ... 'sigma'] = sigma Select the correct answer from above options...
asked Feb 1, 2022 in Education by JackTerrance
0 votes
    Is there any method to find out the number of layers and the number of neurons per layer? As input I solely have ... I can't try this. Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I saw a few examples of a neural network but they work for a fixed set of inputs. How can I deal with ... property of neural networks? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I'm trying to write a program that takes text(article) as input and outputs the polarity of this text, ... open-source implementation. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm Working on document classification tasks in java. Both algorithms came highly recommended, what are the ... Processing tasks? Select the correct answer from above options...
asked Feb 2, 2022 in Education by JackTerrance
0 votes
    What is the difference between back-propagation and feed-forward neural networks? By googling and reading, I found ... feed-forward? Select the correct answer from above options...
asked Jan 31, 2022 in Education by JackTerrance
0 votes
    I know the basics of feedforward neural networks, and how to train them using the backpropagation algorithm, but I'm ... , even better. Select the correct answer from above options...
asked Feb 8, 2022 in Education by JackTerrance
0 votes
    I'm looking for some examples of robot/AI programming using Lisp. Are there any good online examples available ... in nature)? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    It always amazed me how the Akinator app could guess a character by asking just several questions. So I wonder ... more about them? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm teaching a kid programming, and am introducing some basic artificial intelligence concepts at the moment. To begin ... and boxes)? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    Nominally a good problem to have, but I'm pretty sure it is because something funny is going on... As ... labeled data vectors/instances (transformed video frames of individuals--...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I am searching for information on algorithms to process text sentences or to follow a structure when creating sentences ... be great. Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    I'm looking to try and write a chess AI. Is there something I can use on the .NET framework (or maybe ... making a chess game? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
...