Converting R Markdown to HtML

I need help with converting R markdown to HTML.I was able to do it but this error

processing file: MODEL-EVALUATION-AND-DEPLOYMENT.Rmd
|............... | 30% [unnamed-chunk-4]
Quitting from lines 48-61 [unnamed-chunk-4] (MODEL-EVALUATION-AND-DEPLOYMENT.Rmd)
Error in table():
! all arguments must have the same length
Backtrace:

  1. base::table(Actual = advise_invest$answered, Predicted = predictions)

Execution halted

Thanks!

All that's usually required is the line

output: html_document

in the YAML header at the top.

I was able to do it , however I'm getting error while saving the knit

processing file: MODEL-EVALUATION-AND-DEPLOYMENT.Rmd
|............... | 30% [unnamed-chunk-4]
Quitting from lines 48-61 [unnamed-chunk-4] (MODEL-EVALUATION-AND-DEPLOYMENT.Rmd)
Error in table():
! all arguments must have the same length
Backtrace:

  1. base::table(Actual = advise_invest$answered, Predicted = predictions)

Execution halted

This is almost certainly an error in the R code that has nothing to do with markdown or html. If you post the whole chunk someone might be able to spot something.

tree_model <- tree(answered ~ ., data = advise_invest)
predictions <- predict(tree_model, type = "class")

results <- data.frame(Actual = advise_invest$answered, Predicted = predictions)

conf_matrix <-table(Actual = advise_invest$answered,Predicted = predictions)

TP <- conf_matrix[2, 2] # True Positives
FP <- conf_matrix[1, 2] # False Positives
TN <- conf_matrix[1, 1] # True Negatives
FN <- conf_matrix[2, 1] # False Negatives

cat("Number of True Positives (TP):", TP, "\n")

Quitting from lines 48-62 [unnamed-chunk-4] (MODEL-EVALUATION-AND-DEPLOYMENT.Rmd)
Error in data.frame():
! arguments imply differing number of rows: 29501, 29499
Backtrace:

  1. base::data.frame(Actual = advise_invest$answered, Predicted = predictions)

Execution halted

This doesn't look anything like the code displayed in the error message. In any event, it's not a complete R command.

I suspect this is a presence of NAs issue. Most likely predict simply skips outputting thosez so the data.frame construction has an incongruous volume of rows to insert.

This problem might be addressed in one of two ways.

Dropping na rows , so that the data.frames balance.
Or having the NA concretely appear on the prediction side

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.