Skip to content

Commit

Permalink
Fix predictive analystics module (#11)
Browse files Browse the repository at this point in the history
* removed parallel processing

* removed multivariate option for test release

* added imputation of missing values

* fixed prediction plot display

The actual observations were not shown as first factor in prediction plot as they were a separate column from the predictions. This commit merges them in one column

* fixed bunch of stuff

* some bug fixes

- default values for forecast settings are now set based on data, previous values were set arbitrary and large and broke small dataset
- additionally pre-processing now only happens if at least one covariate is present - previously pre-processing threw an error when no covariates (only time variable) was provided
- additionally engineered lags and time-based variables are now in model dependency to recompute models once changed
- lastly lag values are now considered when forecast evaluation plan is created
  • Loading branch information
petersen-f authored Sep 18, 2023
1 parent 2acec73 commit 87dc42f
Show file tree
Hide file tree
Showing 6 changed files with 192 additions and 175 deletions.
6 changes: 2 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,15 @@ Imports:
jaspBase,
jaspGraphs,
bsts,
parallel,
bssm,
precrec,
future,
future.apply,
reshape2,
Boom,
lubridate,
prophet,
BART,
EBMAforecast
EBMAforecast,
imputeTS
Suggests:
testthat
Remotes:
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
import(jaspBase)
export(predictiveAnalytics)
export(multiVarControl)
9 changes: 5 additions & 4 deletions R/modelFunctions.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#### bsts functions
.bstsFitHelper <- function(trainData,formula,method,niter=250,keepModel =F, ...){
.bstsFitHelper <- function(trainData,formula,method,niter=500,keepModel =F, ...){
trainData$time <- as.numeric(trainData$time)
ss <- list()
y <- trainData[[all.vars(formula)[1]]]
Expand Down Expand Up @@ -44,7 +44,7 @@


colnames(trainData)[colnames(trainData)=="time"] <- "ds"
m <- prophet::prophet(...,weekly.seasonality = F)
m <- prophet::prophet(...,weekly.seasonality = F,changepoint.range = 0.9)
if(formula != as.formula("y ~ time")){
for(reg in labels(terms(formula))[-1])
m <- prophet::add_regressor(m,reg)
Expand Down Expand Up @@ -204,7 +204,8 @@


reg_vars <- colnames(trainData)[colnames(trainData)!="y" & colnames(trainData) %in% labels(terms(formula))]
model <- xgboost::xgboost(data = as.matrix(trainData[,reg_vars]),nrounds = nrounds,nthread=1,
options(datatable.verbose=TRUE)
model <- xgboost::xgboost(data = as.matrix(trainData[,reg_vars]),nrounds = nrounds,nthread=1,verbose=0,
label = trainData$y, metrics = list("rmse"), objective = "reg:squarederror",...)


Expand All @@ -231,7 +232,7 @@

reg_vars <- colnames(trainData)[colnames(trainData)!="y" & colnames(trainData) %in% labels(terms(formula))]

model <- BART::wbart(x.train = trainData[,reg_vars],y.train = trainData$y,sparse = T,nkeeptreedraws = 100,ndpost = 100,nskip=100)
model <- BART::wbart(x.train = trainData[,reg_vars],y.train = trainData$y,sparse = T,nkeeptreedraws = 100,ndpost = 500,nskip=100)

return(list(model=model))
}
Expand Down
Loading

0 comments on commit 87dc42f

Please sign in to comment.