rm(list=ls()) pdf("Bias_Var_Tradeoff.pdf") k = 1:20 j = k-.8 bias = 1/j var = k^2/400 +.1 mse = bias + var plot(k,1/k,type="l",lwd=4,col="white",ylab="",xlab="",yaxt="n",cex.axis=1.5) lines(j,bias,lwd=4) lines(k,var,lwd=4,co="red") lines(k,mse,col="purple",lwd=4) text(17.3,.56,"Variance",col="red",cex=1.8) arrows(19,0.59,15.7,.7,length=.1,code=2,col="red",lwd=4) text(16.5,.18,"Bias Squared",cex=1.7) arrows(20,.15,17,.08,length=.1,code=2,lwd=4) abline(v=5.45,col="green",lty="dashed",lwd=4) text(5,.7,"MSE",col="purple",cex=1.8) arrows(5.83,.66,4,.5,length=.1,code=2,col="purple",lwd=4) title(ylab="Bias and Variance",line=1.7, cex.lab=1.8) title(xlab="Number of Features",line=2.6, cex.lab=1.8) dev.off()