
.g()
.us()
setScienceIfNot("Acc_vs_Anal_2015", load=FALSE)

lib(ggplot)
library(h2o)

loadIfNotExists("DT.model_scores")
# loadFromJesus("DT.model_scores", over=TRUE)


DT.model_scores[order(validation_MSE, decreasing=TRUE)]
DT.acc_v_anal.crop[date>="2014-10-01" & storeid %in% c(1, 7, 286), sumn(revenue.acc), keyby=list(storeid, date)]

iT.oct <- 10894241.23
formnumb(iT.oct)

minDate.check <- as.Date("2013-01-01")
maxDate.check <- max(DT.GL$accounting_month)
iT.GL <- DT.GL[store_name == "iTunes"  & accounting_month >= minDate.check, lapply(.SD, sumn), keyby=list(date=accounting_month), .SDcols=c("Statement_ThisMonth_T", "Statement_ThisMonth", "Total_ThisMonth", "Statement_ThisMonth_I")]
iT.OA <- DT.acc_v_anal.crop[date>=minDate.check & date <= maxDate.check & storeid %in% c(1), lapply(.SD, sumn), keyby=list(date), .SDcols=c("revenue.acc", "revenue.anal")]

DT.iT <- merge(iT.OA, iT.GL, all=TRUE)[!(is.na(revenue.acc) & is.na(revenue.anal))]

DT.Plot.iT <- DT.iT[, list(date, Statement_Revenue=c(Statement_ThisMonth, Statement_ThisMonth), OA_Revenue = c(revenue.acc, revenue.anal), OA_Source=rep(c("OA Acc", "OA Anal"), each=.N))]

ggplot(data=DT.Plot.iT, aes(x=Statement_Revenue, shape=OA_Source, color=as.numeric(date))) + geom_point(aes(y=OA_Revenue)) + gg_xyline() + scale_color_continuous()
# ----------------------------------- #

setcolorderpt(DT.model_scores, startCols=c("plot_file", "model_name", "transform_to", "TargetVar", "predCol", "Explanitory"), endCols=c("train_MSE", "validation_MSE"))
formnumb( DT.model_scores[order(validation_MSE, decreasing=TRUE)][, ll := seq(.N), by = transform_to][ll < 10])

 DT.model_scores[, rank.VMSE := rank(validation_MSE), by=transform_to]
 DT.model_scores[, rank.ABS  := rank(abs(short_abs)), by=transform_to]
 DT.model_scores[, rank.PERC := rank(abs(short_perc - 1)), by=transform_to]



formnumb( DT.model_scores[rank.PERC <= 6 | rank.ABS <= 6][order(abs(short_perc))], perc_auto=FALSE, round=FALSE)

x <- c(0, -10, 10, 100, 1001, -100001)
selfname_(x)
rank(abs(x))
rank(abs(x))
(x[order(rank((x)))])


