Skip to content

Instantly share code, notes, and snippets.

@robjhyndman
Created December 7, 2016 08:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save robjhyndman/9fa152c585442bb076eb42a30a020091 to your computer and use it in GitHub Desktop.
Save robjhyndman/9fa152c585442bb076eb42a30a020091 to your computer and use it in GitHub Desktop.
Time series cross-validation diagrams
par(mar=c(0,0,0,0))
plot(0,0,xlim=c(0,28),ylim=c(0,1),
xaxt="n",yaxt="n",bty="n",xlab="",ylab="",type="n")
i <- 1
for(j in 1:20)
{
test <- (6+j):26
train <- 1:(5+j)
arrows(0,1-j/20,27,1-j/20,0.05)
points(train,rep(1-j/20,length(train)),pch=19,col="blue")
if(length(test) >= i)
points(test[i], 1-j/20, pch=19, col="red")
if(length(test) >= i)
points(test[-i], rep(1-j/20,length(test)-1), pch=19, col="gray")
else
points(test, rep(1-j/20,length(test)), pch=19, col="gray")
}
text(28,.95,"time")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment