Simple Sales Prediction

10_visualized
20160616

# Visualized : plot

• The black dots represent the monthly sales figures.
• The blue line is the line fitted by R's lm() function through the sales dots.
• The red dot is the predicted sale for month 13.
• In each case the red dot lies on the blue line, which proves the correctness.

## The R code

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 df=read.table("predicion.csv",sep=",",na.strings="null") df=df[!is.na(df\$V3),] names(df)= c("shop","product","unit","month") dev.off() shops=unique(df\$shop) products=unique(df\$product) dev.new(width=8, height=16) par( mfcol=c(6,2) ) for ( sh in shops) { for ( pr in products) { y=df[ df\$shop==sh & df\$product==pr,"unit"] x=df[ df\$shop==sh & df\$product==pr,"month"] plot(x,y,pch=19,main=paste(sh,pr)) fit=lm( y~x) abline(fit,col="blue",lwd=3) xx=13 yy=y[x==xx] points( xx,yy,pch=19, col="red",lwd=5) }}

Notes by Data Munging Ninja. Generated on nini:/home/willem/sync/20151223_datamungingninja/simplesalesprediction at 2016-06-25 10:02