Chapter 14R and Python Source Code
This chapter shows how to implement almost every method of training and applying a classifier described in Chapters 4 and 6, using risk-estimation and model-selection methods described in Chapter 7, and (at least implicitly) optimization methods described in Chapter 10. The purpose of providing the code in this chapter is to enable the reader, with minimal effort, to learn more about classification in general and the many specific methods described in this book in particular. To that end, the code is written to be both transparent and brief, so that the language of the computer does not form an obstacle between the reader and perception of the mathematical, statistical, and algorithmic ideas being implemented. This led to the following choices.
- Every piece of code is provided twice, once in R and once in Python. At the time of writing, these are the two dominant languages of applied statistics, data science, and machine learning. Functionally equivalent blocks of R and Python code are written to be as stylistically similar as possible, unless there is reason to do otherwise. R code and objects are displayed in
red typewriter text, Python code and objects are displayed inpurple typewriter text. References to code and objects that are language-agnostic are displayed inblack typewriter text. - The code itself relies on several R and Python packages. The R packages are all available at the Comprehensive R Archive Network, CRAN (
cran.r-project.org ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access