Hi @iFeanyi, thanks for posting your plumber question here.
What you are seeing I think is sending character values when the model expect numeric values? If this is the case, you might need to convert them to numeric with as.numeric.
Otherwise, if you expect character values and your models expect factors, keep in mind that when you do
newdf <- data.frame(
math.score = c(math.score),
reading.score = c(reading.score),
writing.score = c(writing.score)
)
the levels will be computed from your input data and will not be the same as your training data. You might want to force the input to use your training data levels using
levels(x) <- ...check your model object if it contains the levels somewhere
Another thing, you could move model loading out of the endpoint function, if it does not need to be executed each time the API is called.
You can just put it after the endpoint function.
newdata <- function(math.score,reading.score,writing.score){
newdf <- data.frame(
math.score = c(math.score),
reading.score = c(reading.score),
writing.score = c(writing.score)
)
prediction <- predict(modelsvm,newdf)
return(paste(prediction[[1]]))
}
modelsvm <- readRDS("student_performance.rds")
Hopefully this gets you on the right path.
Have a great day.