Skip to content

About

Data and files for classification example

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

forested_data

Model results for the forested classification example in Applied Machine Learning for Tabular Data. The book loads the files in results/ at a pinned commit of this repo; it doesn't fit these models itself.

Layout

Path Contents
R/forested_data.R Data split and spatial resamples → processed-data/forested_data.RData (needs CENSUS_API_KEY)
R/forested_plot_sf.R Small spatial example for plots → processed-data/forested_plot_sf.RData
R/setup.R Sourced by every script: packages, data, metrics, save_results()
R/compare-<key>.R Model comparisons (tidyposterior) → results/forested_<key>_results.RData and forested_<key>_compare.RData
R/recipes-linear.R Recipes shared by the logistic, glmnet, and PLS scripts
R/model-<key>.R One model each → results/forested_<key>_res.RData (or _res_set)
R/demo-<key>.R Non-model outputs used in the book → results/forested_<key>.RData
R/qc_names.R Naming and file-size checks
processed-data/ Data used by all scripts
results/ Committed results, plus each script's .Rout log
timings.log Run times appended by make
rproj.toml, rproj.lock, .Renviron, .rvenvlib/ rig project: dependencies, pinned versions, library setup

Naming rules, the script template, and how to add a model are in CONVENTIONS.md.

Environment

Installing rig

Install rig 0.11.1 or later following rig's install instructions (macOS, Linux). On macOS with Homebrew, that's brew install r-rig. Then install the R version in rproj.toml (currently 4.6), e.g. rig add 4.6.2.

If rig --version shows an older version, there's probably a second copy earlier on your PATH; check with which -a rig, remove the old one, and open a new terminal.

To uninstall rig:

  • Homebrew: brew uninstall r-rig.
  • Install script (install.sh): rig self uninstall --force (docs).
  • Older macOS installer (.pkg): sudo rm /usr/local/bin/rig and sudo pkgutil --forget com.gaborcsardi.rig.

Uninstalling rig doesn't remove the R versions it installed (rig rm <version>) or its cache (rig cache clean).

Project library

R and packages are managed with rig (0.11.1 or later) as a project: rproj.toml lists the dependencies and rproj.lock pins every version, including the GitHub branches (by commit). Set up the project library in .rvenv/ with:

make env             # rig proj sync, catboost (macOS), libtorch

The committed .Renviron points R at that library, so make, R, Rscript, and IDEs started at the repo root all use it (R --vanilla doesn't).

  • catboost isn't on CRAN. make env installs its macOS binary from the GitHub release (pinned by URL and SHA-256 in the Makefile) with R CMD INSTALL --no-staged-install, since the binary fails R's staged-install check and rig can't pass that option. On Linux (e.g. a GPU machine for the deep learning models) it's skipped, so everything except R/model-ctb.R runs there.
  • Census key: make data needs CENSUS_API_KEY which can be obtained at https://api.census.gov/data/key_signup.html. Put it in the gitignored .Renviron.local (or the shell environment), not in .Renviron.

Adding packages

rig reads dependencies only from rproj.toml; it doesn't scan the scripts. Add a package with rig proj add, which updates rproj.toml and rproj.lock and installs it:

rig proj add kernlab                          # CRAN (or Bioconductor)
rig proj add tidymodels/tabby@brulee-pfn      # GitHub branch, tag, or commit
rig proj remove kernlab
  • Add packages that are only suggested by others but needed at run time (e.g. lme4 and splines2 for some recipe steps); rig won't pick them up.
  • A GitHub package's Remotes: field wins over a CRAN version in rproj.toml, so check rproj.lock for unexpected git+ sources.
  • Use rig proj add --no-sync, then make env. Without --no-sync, rig proj add syncs the library and removes catboost (it isn't in the lock file); make env puts it back. --no-sync also keeps from changing the library while make is running.

Commit rproj.toml and rproj.lock together.

Updating the lock file

rproj.lock keeps every version it has pinned until asked to change. GitHub branches are pinned to the commit they were at when added, so new commits on the branch aren't picked up automatically.

rig proj lock -P tabby -P rbe   # re-resolve some packages (new branch commits, newer CRAN versions)
rig proj lock --upgrade         # re-resolve everything
make env                        # install what changed

Results made before an update used the old versions; rerun the affected models if that matters.

To change the R version, edit R = ">= ..." and r-versions in rproj.toml, install that R with rig add, then run rig proj lock, rm -rf .rvenv, and make env (a sync alone keeps packages built for the old R).

Running

make help            # list targets
make list            # keys, scripts, and result files
make trees           # one group, full data
make                 # everything missing or out of date, full data (hours)
make check           # naming and size checks

Scripts run serially from the repo root. make prints a timestamped line when each script starts and finishes, writes the script's .Rout log to results/, and appends the run time to timings.log.

About

Data and files for classification example

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages