Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo
R Machine Learning By Example

Book Description

Understand the fundamentals of machine learning with R and build your own dynamic algorithms to tackle complicated real-world problems successfully

About This Book

  • Get to grips with the concepts of machine learning through exciting real-world examples

  • Visualize and solve complex problems by using power-packed R constructs and its robust packages for machine learning

  • Learn to build your own machine learning system with this example-based practical guide

  • Who This Book Is For

    If you are interested in mining useful information from data using state-of-the-art techniques to make data-driven decisions, this is a go-to guide for you. No prior experience with data science is required, although basic knowledge of R is highly desirable. Prior knowledge in machine learning would be helpful but is not necessary.

    What You Will Learn

  • Utilize the power of R to handle data extraction, manipulation, and exploration techniques

  • Use R to visualize data spread across multiple dimensions and extract useful features

  • Explore the underlying mathematical and logical concepts that drive machine learning algorithms

  • Dive deep into the world of analytics to predict situations correctly

  • Implement R machine learning algorithms from scratch and be amazed to see the algorithms in action

  • Write reusable code and build complete machine learning systems from the ground up

  • Solve interesting real-world problems using machine learning and R as the journey unfolds

  • Harness the power of robust and optimized R packages to work on projects that solve real-world problems in machine learning and data science

  • In Detail

    Data science and machine learning are some of the top buzzwords in the technical world today. From retail stores to Fortune 500 companies, everyone is working hard to making machine learning give them data-driven insights to grow their business. With powerful data manipulation features, machine learning packages, and an active developer community, R empowers users to build sophisticated machine learning systems to solve real-world data problems.

    This book takes you on a data-driven journey that starts with the very basics of R and machine learning and gradually builds upon the concepts to work on projects that tackle real-world problems.

    You’ll begin by getting an understanding of the core concepts and definitions required to appreciate machine learning algorithms and concepts. Building upon the basics, you will then work on three different projects to apply the concepts of machine learning, following current trends and cover major algorithms as well as popular R packages in detail. These projects have been neatly divided into six different chapters covering the worlds of e-commerce, finance, and social-media, which are at the very core of this data-driven revolution. Each of the projects will help you to understand, explore, visualize, and derive insights depending upon the domain and algorithms.

    Through this book, you will learn to apply the concepts of machine learning to deal with data-related problems and solve them using the powerful yet simple language, R.

    Style and approach

    The book is an enticing journey that starts from the very basics to gradually pick up pace as the story unfolds. Each concept is first defined in the larger context of things succinctly, followed by a detailed explanation of their application. Each topic is explained with the help of a project that solves a real real-world problem involving hands-on work thus giving you a deep insight into the world of machine learning.

    Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at If you purchased this book elsewhere, you can visit and register to have the code file.

    Table of Contents

    1. R Machine Learning By Example
      1. Table of Contents
      2. R Machine Learning By Example
      3. Credits
      4. About the Authors
      5. About the Reviewer
        1. eBooks, discount offers, and more
          1. Why subscribe?
      7. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Conventions
        5. Reader feedback
        6. Customer support
          1. Downloading the example code
          2. Downloading the color images of this book

          3. Errata
          4. Piracy
          5. Questions
      8. 1. Getting Started with R and Machine Learning
        1. Delving into the basics of R
          1. Using R as a scientific calculator
          2. Operating on vectors
          3. Special values
        2. Data structures in R
          1. Vectors
            1. Creating vectors
            2. Indexing and naming vectors
          2. Arrays and matrices
            1. Creating arrays and matrices
            2. Names and dimensions
            3. Matrix operations
          3. Lists
            1. Creating and indexing lists
            2. Combining and converting lists
          4. Data frames
            1. Creating data frames
            2. Operating on data frames
        3. Working with functions
          1. Built-in functions
          2. User-defined functions
          3. Passing functions as arguments
        4. Controlling code flow
          1. Working with if, if-else, and ifelse
          2. Working with switch
          3. Loops
        5. Advanced constructs
          1. lapply and sapply
          2. apply
          3. tapply
          4. mapply
        6. Next steps with R
          1. Getting help
          2. Handling packages
        7. Machine learning basics
          1. Machine learning – what does it really mean?
          2. Machine learning – how is it used in the world?
          3. Types of machine learning algorithms
            1. Supervised machine learning algorithms
            2. Unsupervised machine learning algorithms
            3. Popular machine learning packages in R
        8. Summary
      9. 2. Let's Help Machines Learn
        1. Understanding machine learning
        2. Algorithms in machine learning
          1. Perceptron
        3. Families of algorithms
          1. Supervised learning algorithms
            1. Linear regression
            2. K-Nearest Neighbors (KNN)
              1. Collecting and exploring data
              2. Normalizing data
              3. Creating training and test data sets
              4. Learning from data/training the model
              5. Evaluating the model
          2. Unsupervised learning algorithms
            1. Apriori algorithm
            2. K-Means
        4. Summary
      10. 3. Predicting Customer Shopping Trends with Market Basket Analysis
        1. Detecting and predicting trends
        2. Market basket analysis
          1. What does market basket analysis actually mean?
          2. Core concepts and definitions
          3. Techniques used for analysis
          4. Making data driven decisions
        3. Evaluating a product contingency matrix
          1. Getting the data
          2. Analyzing and visualizing the data
          3. Global recommendations
          4. Advanced contingency matrices
        4. Frequent itemset generation
          1. Getting started
          2. Data retrieval and transformation
          3. Building an itemset association matrix
          4. Creating a frequent itemsets generation workflow
          5. Detecting shopping trends
        5. Association rule mining
          1. Loading dependencies and data
          2. Exploratory analysis
          3. Detecting and predicting shopping trends
          4. Visualizing association rules
        6. Summary
      11. 4. Building a Product Recommendation System
        1. Understanding recommendation systems
        2. Issues with recommendation systems
        3. Collaborative filters
          1. Core concepts and definitions
          2. The collaborative filtering algorithm
            1. Predictions
            2. Recommendations
            3. Similarity
        4. Building a recommender engine
          1. Matrix factorization
          2. Implementation
          3. Result interpretation
        5. Production ready recommender engines
          1. Extract, transform, and analyze
          2. Model preparation and prediction
          3. Model evaluation
        6. Summary
      12. 5. Credit Risk Detection and Prediction – Descriptive Analytics
        1. Types of analytics
        2. Our next challenge
        3. What is credit risk?
        4. Getting the data
        5. Data preprocessing
          1. Dealing with missing values
          2. Datatype conversions
        6. Data analysis and transformation
          1. Building analysis utilities
          2. Analyzing the dataset
          3. Saving the transformed dataset
        7. Next steps
          1. Feature sets
          2. Machine learning algorithms
        8. Summary
      13. 6. Credit Risk Detection and Prediction – Predictive Analytics
        1. Predictive analytics
        2. How to predict credit risk
        3. Important concepts in predictive modeling
          1. Preparing the data
          2. Building predictive models
          3. Evaluating predictive models
        4. Getting the data
        5. Data preprocessing
        6. Feature selection
        7. Modeling using logistic regression
        8. Modeling using support vector machines
        9. Modeling using decision trees
        10. Modeling using random forests
        11. Modeling using neural networks
        12. Model comparison and selection
        13. Summary
      14. 7. Social Media Analysis – Analyzing Twitter Data
        1. Social networks (Twitter)
        2. Data mining @social networks
          1. Mining social network data
          2. Data and visualization
            1. Word clouds
            2. Treemaps
            3. Pixel-oriented maps
            4. Other visualizations
        3. Getting started with Twitter APIs
          1. Overview
          2. Registering the application
          3. Connect/authenticate
          4. Extracting sample tweets
        4. Twitter data mining
          1. Frequent words and associations
          2. Popular devices
          3. Hierarchical clustering
          4. Topic modeling
        5. Challenges with social network data mining
        6. References
        7. Summary
      15. 8. Sentiment Analysis of Twitter Data
        1. Understanding Sentiment Analysis
          1. Key concepts of sentiment analysis
            1. Subjectivity
            2. Sentiment polarity
            3. Opinion summarization
            4. Feature extraction
          2. Approaches
          3. Applications
          4. Challenges
        2. Sentiment analysis upon Tweets
          1. Polarity analysis
          2. Classification-based algorithms
            1. Labeled dataset
            2. Support Vector Machines
            3. Ensemble methods
              1. Boosting
              2. Cross-validation
        3. Summary
      16. Index