0
votes

I uses Caret to get a prediction for electricity usage per day. I am wondering if there is a way to plot both predicted data and the actual data to inspect the difference.

I check this post, but I didn't find the solution I want. how to plot actual and predicted values?

Assume two list of numbers.

actual <- [1,2,3,4]
predicted <- [1.3,2,3.1,4]

Is there a simply way to plot the two line to observe the difference? Thanks!

1
Do you mean just plot(actual, predicted)? Also what you've provided is not valid R code. Literal arrays should look like actual <- c(1,2,3,4)MrFlick
Maybe something like plot(day, actual); points(day, predicted, col = "blue"). It is better to explain the question clearly with an example, when possible.Suren

1 Answers

0
votes

you mentioned using caret, so there must be some model you're trying to fit. if correct, there exists a model object and you could use plotObsVsPred function. Here is a simplified example from help link:

# regression example
library(mlbench)
data(BostonHousing)

plsFit <- train(BostonHousing[1:100, -c(4, 14)], 
                BostonHousing$medv[1:100], 
                "pls")

predVals <- extractPrediction(list(plsFit), 
                              testX = BostonHousing[101:200, -c(4, 14)], 
                              testY = BostonHousing$medv[101:200]) 

plotObsVsPred(predVals)

enter image description here