Difficulties in create a confusion matrix in R for Yes or No
I am new to regression and confusion matrix and trying to create a confusion matrix from logistic binary regression model. I am trying to create a confusion matrix from Yes or No values from the column, Survived. I am using a default dataset, Titanic. I received an error when trying to perform Confusion Matrix
The dataset, Titanic content is found here. Titanic Content
Here is the R code below.
example$Class- as.factor(example$Class)
example$Sex- as.factor(example$Sex)
example$Age- as.factor(example$Age)
example$Survived- as.factor(example$Survived)
trainRowNum - createDataPartition(example$Survived, #The outcome variable
#proportion of example to form the training set
p=0.3,
#Don't store the result in a list
list=FALSE);
# Step 2: Create the training mydataset
trainData - example[trainRowNum,]
# Step 3: Create the test mydataset
testData - example[-trainRowNum,]
mod.surv.lg - glm(Survived~., family=binomial(), data=trainData);
#Provide a summary of the model
summary(mod.surv.lg)
p - predict(mod.surv.lg, testData,type=response)
p_class - ifelse(p 0.5,Yes,No)
table(p_class)
p_class
table(p_class, testData[[Survived]])
confusionMatrix(p_class, testData$Survived);
I received an error when performing confusionMatrix function
[1] No Yes
0 rows (or 0-length row.names)
Warning message:
In Ops.factor(predictedScores, threshold) : ‘’ not meaningful for factors
Topic rstudio regression logistic-regression confusion-matrix r
Category Data Science