Machine Learning with R Second Edition
Table of Contents
Machine Learning with R Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Introducing Machine Learning
The origins of machine learning
Uses and abuses of machine learning
Machine learning successes
The limits of machine learning
Machine learning ethics
How machines learn
Data storage
Abstraction
Generalization
Evaluation
Machine learning in practice
Types of input data
Types of machine learning algorithms
Matching input data to algorithms
Machine learning with R
Installing R packages
Loading and unloading R packages
Summary
2. Managing and Understanding Data
R data structures
Vectors
Factors
Lists
Data frames
Matrixes and arrays
Managing data with R
Saving, loading, and removing R data structures
Importing and saving data from CSV files
Exploring and understanding data
Exploring the structure of data
Exploring numeric variables
Measuring the central tendency β mean and median
Measuring spread β quartiles and the five-number summary
Visualizing numeric variables β boxplots
Visualizing numeric variables β histograms
Understanding numeric data β uniform and normal distributions
Measuring spread β variance and standard deviation
Exploring categorical variables
Measuring the central tendency β the mode
Exploring relationships between variables
Visualizing relationships β scatterplots
Examining relationships β two-way cross-tabulations
Summary
3. Lazy Learning β Classification Using Nearest Neighbors
Understanding nearest neighbor classification
The k-NN algorithm
Measuring similarity with distance
Choosing an appropriate k
Preparing data for use with k-NN
Why is the k-NN algorithm lazy?
Example β diagnosing breast cancer with the k-NN algorithm
Step 1 β collecting data
Step 2 β exploring and preparing the data
Transformation β normalizing numeric data
Data preparation β creating training and test datasets
Step 3 β training a model on the data
Step 4 β evaluating model performance
Step 5 β improving model performance
Transformation β z-score standardization
Testing alternative values of k
Summary
4. Probabilistic Learning β Classification Using Naive Bayes
Understanding Naive Bayes
Basic concepts of Bayesian methods
Understanding probability
Understanding joint probability
Computing conditional probability with Bayes' theorem
The Naive Bayes algorithm
Classification with Naive Bayes
The Laplace estimator
Using numeric features with Naive Bayes
Example β filtering mobile phone spam with the Naive Bayes algorithm
Step 1 β collecting data
Step 2 β exploring and preparing the data
Data preparation β cleaning and standardizing text data
Data preparation β splitting text documents into words
Data preparation β creating training and test datasets
Visualizing text data β word clouds
Data preparation β creating indicator features for frequent words
Step 3 β training a model on the data
Step 4 β evaluating model performance
Step 5 β improving model performance
Summary
5. Divide and Conquer β Classification Using Decision Trees and Rules
Understanding decision trees
Divide and conquer
The C5.0 decision tree algorithm
Choosing the best split
Pruning the decision tree
Example β identifying risky bank loans using C5.0 decision trees
Step 1 β collecting data
Step 2 β exploring and preparing the data
Data preparation β creating random training and test datasets
Step 3 β training a model on the data
Step 4 β evaluating model performance
Step 5 β improving model performance
Boosting the accuracy of decision trees
Making mistakes more costlier than others
Understanding classification rules
Separate and conquer
The 1R algorithm
The RIPPER algorithm
Rules from decision trees
What makes trees and rules greedy?
Example β identifying poisonous mushrooms with rule learners
Step 1 β collecting data
Step 2 β exploring and preparing the data
Step 3 β training a model on the data
Step 4 β evaluating model performance
Step 5 β improving model performance
Summary
6. Forecasting Numeric Data β Regression Methods
Understanding regression
Simple linear regression
Ordinary least squares estimation
Correlations
Multiple linear regression
Example β predicting medical expenses using linear regression
Step 1 β collecting data
Step 2 β exploring and preparing the data
Exploring relationships among features β the correlation matrix
Visualizing relationships among features β the scatterplot matrix
Step 3 β training a model on the data
Step 4 β evaluating model performance
Step 5 β improving model performance
Model specification β adding non-linear relationships
Transformation β converting a numeric variable to a binary indicator
Model specification β adding interaction effects
Putting it all together β an improved regression model
Understanding regression trees and model trees
Adding regression to trees
Example β estimating the quality of wines with regression trees and model trees
Step 1 β collecting data
Step 2 β exploring and preparing the data
Step 3 β training a model on the data
Visualizing decision trees
Step 4 β evaluating model performance
Measuring performance with the mean absolute error
Step 5 β improving model performance
Summary
7. Black Box Methods β Neural Networks and Support Vector Machines
Understanding neural networks
From biological to artificial neurons
Activation functions
Network topology
The number of layers
The direction of information travel
The number of nodes in each layer
Training neural networks with backpropagation
Example β Modeling the strength of concrete with ANNs
Step 1 β collecting data
Step 2 β exploring and preparing the data
Step 3 β training a model on the data
Step 4 β evaluating model performance
Step 5 β improving model performance
Understanding Support Vector Machines
Classification with hyperplanes
The case of linearly separable data
The case of nonlinearly separable data
Using kernels for non-linear spaces
Exam...