Data Science Desktop Survival Guide
by Graham Williams |
|||||
Step 8: Save the Model to File |
We save the model, together with the dataset and other variables, into a binary R file.
mddate <- "_" %s+% format(Sys.time(), "%Y%m%d_%H%M%S")
mdrdata <- dsname %s+% "_" %s+% mtype %s+% mddate %s+% ".RData" save(ds, dsname, dspath, dsdate, nobs, vars, target, risk, id, ignore, omit, inputi, inputs, numi, numc, cati, catc, form, seed, tr, te, actual_tr, risk_tr, actual_te, risk_te, per, con, model, mtype, file=mdrdata)
The dataset, its meta-data and the model are now stored in weatherAUS_rpart_20210125_063504.RData. We can then load this later and replicate the process.
|
(load(mdrdata))
Note that by using generic variable names we can load different model files and perform common operations on them without changing the names within a script. However, do note that each time we load such a saved model file we overwrite any other variables of the same name. We have also defined some additional meta-data variables relating to modelling and these will be useful to include in the data file with the dataset, separate to the saved model. We augment the original data file with the modelling meta data and save that to a new file.
|
mddate <- "_" %s+% format(Sys.time(), "%Y%m%d_%H%M%S")
mdrdata <- dsname %s+% "_meta" %s+% mddate %s+% ".RData" save(ds, dsname, dspath, dsdate, nobs, vars, target, risk, id, ignore, omit, inputi, inputs, numi, numc, cati, catc, form, seed, tr, te, actual_tr, risk_tr, actual_te, risk_te, per, con, file=mdrdata)
The dataset and its meta-data are now stored on our computer in the current folder in a file with the name weatherAUS_meta_20210125_063506.RData.
|