Practical Data Science with R, Second Edition

Book description

Practical Data Science with R, Second Edition is a task-based tutorial that leads readers through dozens of useful, data analysis practices using the R language. By concentrating on the most important tasks you’ll face on the job, this friendly guide is comfortable both for business analysts and data scientists. Because data is only useful if it can be understood, you’ll also find fantastic tips for organizing and presenting data in tables, as well as snappy visualizations.

Table of contents

  1. Practical Data Science with R, Second Edition
    1. Nina Zumel and John Mount
  2. Copyright
    1. Dedication
  3. Brief Table of Contents
  4. Table of Contents
  5. Praise for the First Edition
  6. front matter
    1. Foreword
    2. Preface
    3. Acknowledgments
    4. About This Book
      1. What is data science?
      2. Roadmap
      3. Audience
      4. What is not in this book?
      5. Code conventions and downloads
      6. Working with this book
        1. Downloading the book’s supporting materials/repository
      7. Book forum
    5. About the Authors
    6. About the Foreword Authors
    7. About the Cover Illustration
  7. Part 1. Introduction to data science
  8. Chapter 1. The data science process
    1. 1.1. The roles in a data science project
      1. 1.1.1. Project roles
    2. 1.2. Stages of a data science project
      1. 1.2.1. Defining the goal
      2. 1.2.2. Data collection and management
      3. 1.2.3. Modeling
      4. 1.2.4. Model evaluation and critique
      5. 1.2.5. Presentation and documentation
      6. 1.2.6. Model deployment and maintenance
    3. 1.3. Setting expectations
      1. 1.3.1. Determining lower bounds on model performance
    4. Summary
  9. Chapter 2. Starting with R and data
    1. 2.1. Starting with R
      1. 2.1.1. Installing R, tools, and examples
      2. 2.1.2. R programming
    2. 2.2. Working with data from files
      1. 2.2.1. Working with well-structured data from files or URLs
      2. 2.2.2. Using R with less-structured data
    3. 2.3. Working with relational databases
      1. 2.3.1. A production-size example
    4. Summary
  10. Chapter 3. Exploring data
    1. 3.1. Using summary statistics to spot problems
      1. 3.1.1. Typical problems revealed by data summaries
    2. 3.2. Spotting problems using graphics and visualization
      1. 3.2.1. Visually checking distributions for a single variable
      2. 3.2.2. Visually checking relationships between two variables
    3. Summary
  11. Chapter 4. Managing data
    1. 4.1. Cleaning data
      1. 4.1.1. Domain-specific data cleaning
      2. 4.1.2. Treating missing values
      3. 4.1.3. The vtreat package for automatically treating missing variables
    2. 4.2. Data transformations
      1. 4.2.1. Normalization
      2. 4.2.2. Centering and scaling
      3. 4.2.3. Log transformations for skewed and wide distributions
    3. 4.3. Sampling for modeling and validation
      1. 4.3.1. Test and training splits
      2. 4.3.2. Creating a sample group column
      3. 4.3.3. Record grouping
      4. 4.3.4. Data provenance
    4. Summary
  12. Chapter 5. Data engineering and data shaping
    1. 5.1. Data selection
      1. 5.1.1. Subsetting rows and columns
      2. 5.1.2. Removing records with incomplete data
      3. 5.1.3. Ordering rows
    2. 5.2. Basic data transforms
      1. 5.2.1. Adding new columns
      2. 5.2.2. Other simple operations
    3. 5.3. Aggregating transforms
      1. 5.3.1. Combining many rows into summary rows
    4. 5.4. Multitable data transforms
      1. 5.4.1. Combining two or more ordered data frames quickly
      2. 5.4.2. Principal methods to combine data from multiple tables
    5. 5.5. Reshaping transforms
      1. 5.5.1. Moving data from wide to tall form
      2. 5.5.2. Moving data from tall to wide form
      3. 5.5.3. Data coordinates
    6. Summary
  13. Part 2. Modeling methods
  14. Chapter 6. Choosing and evaluating models
    1. 6.1. Mapping problems to machine learning tasks
      1. 6.1.1. Classification problems
      2. 6.1.2. Scoring problems
      3. 6.1.3. Grouping: working without known targets
      4. 6.1.4. Problem-to-method mapping
    2. 6.2. Evaluating models
      1. 6.2.1. Overfitting
      2. 6.2.2. Measures of model performance
      3. 6.2.3. Evaluating classification models
      4. 6.2.4. Evaluating scoring models
      5. 6.2.5. Evaluating probability models
    3. 6.3. Local interpretable model-agnostic explanations (LIME) for explai- ining model predictions
      1. 6.3.1. LIME: Automated sanity checking
      2. 6.3.2. Walking through LIME: A small example
      3. 6.3.3. LIME for text classification
      4. 6.3.4. Training the text classifier
      5. 6.3.5. Explaining the classifier’s predictions
    4. Summary
  15. Chapter 7. Linear and logistic regression
    1. 7.1. Using linear regression
      1. 7.1.1. Understanding linear regression
      2. 7.1.2. Building a linear regression model
      3. 7.1.3. Making predictions
      4. 7.1.4. Finding relations and extracting advice
      5. 7.1.5. Reading the model summary and characterizing coefficient quality
      6. 7.1.6. Linear regression takeaways
    2. 7.2. Using logistic regression
      1. 7.2.1. Understanding logistic regression
      2. 7.2.2. Building a logistic regression model
      3. 7.2.3. Making predictions
      4. 7.2.4. Finding relations and extracting advice from logistic models
      5. 7.2.5. Reading the model summary and characterizing coefficients
      6. 7.2.6. Logistic regression takeaways
    3. 7.3. Regularization
      1. 7.3.1. An example of quasi-separation
      2. 7.3.2. The types of regularized regression
      3. 7.3.3. Regularized regression with glmnet
    4. Summary
  16. Chapter 8. Advanced data preparation
    1. 8.1. The purpose of the vtreat package
    2. 8.2. KDD and KDD Cup 2009
      1. 8.2.1. Getting started with KDD Cup 2009 data
      2. 8.2.2. The bull-in-the-china-shop approach
    3. 8.3. Basic data preparation for classification
      1. 8.3.1. The variable score frame
    4. 8.4. Advanced data preparation for classification
      1. 8.4.1. Using mkCrossFrameCExperiment()
      2. 8.4.2. Building a model
        1. Building a multivariable model
        2. Evaluating the model
    5. 8.5. Preparing data for regression modeling
    6. 8.6. Mastering the vtreat package
      1. 8.6.1. The vtreat phases
      2. 8.6.2. Missing values
      3. 8.6.3. Indicator variables
      4. 8.6.4. Impact coding
      5. 8.6.5. The treatment plan
      6. 8.6.6. The cross-frame
    7. Summary
  17. Chapter 9. Unsupervised methods
    1. 9.1. Cluster analysis
      1. 9.1.1. Distances
      2. 9.1.2. Preparing the data
      3. 9.1.3. Hierarchical clustering with hclust
      4. 9.1.4. The k-means algorithm
      5. 9.1.5. Assigning new points to clusters
      6. 9.1.6. Clustering takeaways
    2. 9.2. Association rules
      1. 9.2.1. Overview of association rules
      2. 9.2.2. The example problem
      3. 9.2.3. Mining association rules with the arules package
      4. 9.2.4. Association rule takeaways
    3. Summary
  18. Chapter 10. Exploring advanced methods
    1. 10.1. Tree-based methods
      1. 10.1.1. A basic decision tree
      2. 10.1.2. Using bagging to improve prediction
      3. 10.1.3. Using random forests to further improve prediction
      4. 10.1.4. Gradient-boosted trees
      5. 10.1.5. Tree-based model takeaways
    2. 10.2. Using generalized additive models (GAMs) to learn non-monotone relationships
      1. 10.2.1. Understanding GAMs
      2. 10.2.2. A one-dimensional regression example
      3. 10.2.3. Extracting the non-linear relationships
      4. 10.2.4. Using GAM on actual data
      5. 10.2.5. Using GAM for logistic regression
      6. 10.2.6. GAM takeaways
    3. 10.3. Solving “inseparable” problems using support vector machines
      1. 10.3.1. Using an SVM to solve a problem
      2. 10.3.2. Understanding support vector machines
      3. 10.3.3. Understanding kernel functions
      4. 10.3.4. Support vector machine and kernel methods takeaways
    4. Summary
  19. Part 3. Working in the real world
  20. Chapter 11. Documentation and deployment
    1. 11.1. Predicting buzz
    2. 11.2. Using R markdown to produce milestone documentation
      1. 11.2.1. What is R markdown?
      2. 11.2.2. knitr technical details
      3. 11.2.3. Using knitr to document the Buzz data and produce the model
    3. 11.3. Using comments and version control for running documentation
      1. 11.3.1. Writing effective comments
      2. 11.3.2. Using version control to record history
      3. 11.3.3. Using version control to explore your project
      4. 11.3.4. Using version control to share work
    4. 11.4. Deploying models
      1. 11.4.1. Deploying demonstrations using Shiny
      2. 11.4.2. Deploying models as HTTP services
      3. 11.4.3. Deploying models by export
      4. 11.4.4. What to take away
    5. Summary
  21. Chapter 12. Producing effective presentations
    1. 12.1. Presenting your results to the project sponsor
      1. 12.1.1. Summarizing the project’s goals
      2. 12.1.2. Stating the project’s results
      3. 12.1.3. Filling in the details
      4. 12.1.4. Making recommendations and discussing future work
      5. 12.1.5. Project sponsor presentation takeaways
    2. 12.2. Presenting your model to end users
      1. 12.2.1. Summarizing the project goals
      2. 12.2.2. Showing how the model fits user workflow
      3. 12.2.3. Showing how to use the model
      4. 12.2.4. End user presentation takeaways
    3. 12.3. Presenting your work to other data scientists
      1. 12.3.1. Introducing the problem
      2. 12.3.2. Discussing related work
      3. 12.3.3. Discussing your approach
      4. 12.3.4. Discussing results and future work
      5. 12.3.5. Peer presentation takeaways
    4. Summary
  22. Appendix A. Starting with R and other tools
    1. A.1. Installing the tools
      1. A.1.1. Installing Tools
      2. A.1.2. The R package system
      3. A.1.3. Installing Git
      4. A.1.4. Installing RStudio
      5. A.1.5. R resources
    2. A.2. Starting with R
      1. A.2.1. Primary features of R
      2. A.2.2. Primary R data types
    3. A.3. Using databases with R
      1. A.3.1. Running database queries using a query generator
      2. A.3.2. How to think relationally about data
    4. A.4. The takeaway
  23. Appendix B. Important statistical concepts
    1. B.1. Distributions
      1. B.1.1. Normal distribution
      2. B.1.2. Summarizing R’s distribution naming conventions
      3. B.1.3. Lognormal distribution
      4. B.1.4. Binomial distribution
      5. B.1.5. More R tools for distributions
    2. B.2. Statistical theory
      1. B.2.1. Statistical philosophy
      2. B.2.2. A/B tests
      3. B.2.3. Power of tests
      4. B.2.4. Specialized statistical tests
    3. B.3. Examples of the statistical view of data
      1. B.3.1. Sampling bias
      2. B.3.2. Omitted variable bias
    4. B.4. The takeaway
  24. Appendix C. Bibliography
  25. Practical Data Science with R
  26. Index
  27. List of Figures
  28. List of Tables
  29. List of Listings

Product information

  • Title: Practical Data Science with R, Second Edition
  • Author(s): John Mount, Nina Zumel
  • Release date: December 2019
  • Publisher(s): Manning Publications
  • ISBN: 9781617295874