-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Automate Prototyping Activities - R-based Models #217
Comments
Need to install all needed r-cran-XXXXXXXXX packages in debian. Most needed : r-cran-forecast and r-cran-caret
|
Need to have a set of pyaf models that build custom R scripts to internally build the corresponding R forecasting models. This is a prototyping environment, can be slow and that's OK. All the logs coming from R should be properly saved under Training script saved in python (and used in R) under Training dataset saved in python (and used in R) under R models saved in R (and reloaded before each forecast/predict) under Forecasting/predict script saved in python (and used in R) under Forecast/predict dataset saved in python (and used in R) under mode_name should contain the type of model (TAR, TSMARS, ...) and a unique string (date , process_id , ) etc. output datasets saved by R (and used in python) under |
Sample R training script for Threshold AR models (auto-generated by pyaf for each internal model) write('', "/tmp/pyaf_prototyping/threshold_ar_20220905164142.004041_139800315743536/train.lock")
options(warn=1);
sink(file("/tmp/pyaf_prototyping/threshold_ar_20220905164142.004041_139800315743536/train.log" , open="wt"), type="output");
sink(file("/tmp/pyaf_prototyping/threshold_ar_20220905164142.004041_139800315743536/train.err" , open="wt"), type="message");
set.seed(1960)
paste("R_VERSION" , R.version.string)
df = read.csv("/tmp/pyaf_prototyping/threshold_ar_20220905164142.004041_139800315743536/training.csv", header=TRUE)
library(NTS, quietly = TRUE);
cat("R_PACKAGE_VERSION", "NTS", toString(packageVersion("NTS")) , "\n");
thresholds.est = uTAR(y=df$TGT, p1=2, p2=2, d=2, thrQ=c(0,1), Trim=c(0.1,0.9), include.mean=TRUE, method="NeSS", k0=50);
model = uTAR.est(y=df$TGT, , arorder=c(2,2), thr=thresholds.est$thr, d=2);
saveRDS(model, "/tmp/pyaf_prototyping/threshold_ar_20220905164142.004041_139800315743536/model.rds")
file.remove("/tmp/pyaf_prototyping/threshold_ar_20220905164142.004041_139800315743536/train.lock")
sink(type="output");
sink(type="message");
print('end')
|
Sample forecast/predict script for Threshold AR models (auto-generated by pyaf for each model forecast) write('', "/tmp/pyaf_prototyping/threshold_ar_20220905164840.860942_140163095026208/predict_20220905164841.627680_140163095026208.lock")
options(warn=1);
sink(file("/tmp/pyaf_prototyping/threshold_ar_20220905164840.860942_140163095026208/predict_20220905164841.627680_140163095026208.log" , open="wt"), type="output");
sink(file("/tmp/pyaf_prototyping/threshold_ar_20220905164840.860942_140163095026208/predict_20220905164841.627680_140163095026208.err" , open="wt"), type="message");
paste("R_VERSION" , R.version.string)
df = read.csv("/tmp/pyaf_prototyping/threshold_ar_20220905164840.860942_140163095026208/predict_20220905164841.627680_140163095026208_input.csv", header=TRUE)
reloaded_model = readRDS("/tmp/pyaf_prototyping/threshold_ar_20220905164840.860942_140163095026208/model.rds")
library(NTS, quietly = TRUE);
cat("R_PACKAGE_VERSION", "NTS", toString(packageVersion("NTS")) , "\n");
predicted = uTAR.pred(mode=reloaded_model, orig=0 , h=204 - sum(reloaded_model$nobs),iterations=100,ci=0.95,output=TRUE)
nempty = length(reloaded_model$data) - length(reloaded_model$residuals)
residuals = rbind(matrix(0, nempty) , matrix(reloaded_model$residuals))
data = reloaded_model$data
fitted = data + residuals
predicted = rbind(fitted, predicted$pred)
write.csv(predicted, file = "/tmp/pyaf_prototyping/threshold_ar_20220905164840.860942_140163095026208/predict_20220905164841.627680_140163095026208_output.csv")
file.remove("/tmp/pyaf_prototyping/threshold_ar_20220905164840.860942_140163095026208/predict_20220905164841.627680_140163095026208.lock")
sink(type="output");
sink(type="message");
print('end')
|
Sample MARS model using R Caret prototyping. |
Sample TAR Model using R NTS package |
R_modeling branch : https://github.com/antoinecarme/pyaf/tree/R_modeling/ Specific prototyping tests : https://github.com/antoinecarme/pyaf/tree/R_modeling/tests/caret_r_prototypes |
It is useful to have a git branch which contains all the necessary toolkit for prototyping.
Make it possible to use R/forecast from inside pyaf. "Fake" pyaf models which call R to validate a specific implementation.
This branch is not to be merged.
First application : Threshold AR models #214 and TSMARS models #215
The text was updated successfully, but these errors were encountered: