Go to TogaWare.com Home Page. Data Science Desktop Survival Guide
by Graham Williams
Duck Duck Go



CLICK HERE TO VISIT THE UPDATED SURVIVAL GUIDE

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))
##  [1] "ds"        "dsname"    "dspath"    "dsdate"    "nobs"      "vars" ...
##  [7] "target"    "risk"      "id"        "ignore"    "omit"      "inputi...
## [13] "inputs"    "numi"      "numc"      "cati"      "catc"      "form" ...
## [19] "seed"      "tr"        "te"        "actual_tr" "risk_tr"   "actual...
## [25] "risk_te"   "per"       "con"       "model"     "mtype"

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.


Support further development by purchasing the PDF version of the book.
Other online resources include the GNU/Linux Desktop Survival Guide.
Books available on Amazon include Data Mining with Rattle and Essentials of Data Science.
Popular open source software includes rattle and wajig.
Hosted by Togaware, a pioneer of free and open source software since 1984.
Copyright © 2000-2020 Togaware Pty Ltd. . Creative Commons ShareAlike V4.