DanD
DanD

Reputation: 1

Error in code while working towards creating ROC curve

I want to plot a ROC curve in R. I created a logistic Regg predictive model -modl4 already.
The code I executed towards creating the plot is:

train$predicted <- modl4$fitted.values

but this code is fetching error and the error says rows are mismatching. (Not able to copy actual error message from remote server).

2nd need is to have a single line of code to replace the NA values in a factor variable column with mode of that variable. IS THIS POSSIBLE?
(Please excuse my silly questions, I recently started working on R)

Any pointers will be highly appreciated.

Upvotes: 0

Views: 101

Answers (1)

Mahdiar
Mahdiar

Reputation: 104

It would be easier if you could provide a reproducible example of your code. You have probably assigned train model to a different vector and that's why the rows are mismatching.

You can replace NA with variables in one column. If I understand your question correctly, you have a column called factor in your data frame.

For the second question, you can find the mode with this function:

# Create the function.
getmode <- function(v) {
   uniqv <- unique(v)
   uniqv[which.max(tabulate(match(v, uniqv)))]
}

Then use the:

df$factor[df$factor=='NA'] <- getmode(df$factor)

This should work!

Upvotes: 1

Related Questions