Book Image

R Machine Learning By Example

By : Raghav Bali
Book Image

R Machine Learning By Example

By: Raghav Bali

Overview of this book

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.
Table of Contents (15 chapters)
R Machine Learning By Example
Credits
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Preface

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 make machine learning give them data-driven insights to grow their businesses. 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.

What this book covers

Chapter 1, Getting Started with R and Machine Learning, acquaints you with the book and helps you reacquaint yourself with R and its basics. This chapter also provides you with a short introduction to machine learning.

Chapter 2, Let's Help Machines Learn, dives into machine learning by explaining the concepts that form its base. You are also presented with various types of learning algorithms, along with some real-world examples.

Chapter 3, Predicting Customer Shopping Trends with Market Basket Analysis, starts off with our first project, e-commerce product recommendations, predictions, and pattern analysis, using various machine learning techniques. This chapter specifically deals with market basket analysis and association rule mining to detect customer shopping patterns and trends and make product predictions and suggestions using these techniques. These techniques are used widely by retail companies and e-commerce stores such as Target, Macy's, Flipkart, and Amazon for product recommendations.

Chapter 4, Building a Product Recommendation System, covers the second part of our first project on e-commerce product recommendations, predictions, and pattern analysis. This chapter specifically deals with analyzing e-commerce product reviews and ratings by different users, using algorithms and techniques such as user-collaborative filtering to design a recommender system that is production ready.

Chapter 5, Credit Risk Detection and Prediction – Descriptive Analytics, starts off with our second project, applying machine learning to a complex financial scenario where we deal with credit risk detection and prediction. This chapter specifically deals with introducing the main objective, looking at a financial credit dataset for 1,000 people who have applied for loans from a bank. We will use machine learning techniques to detect people who are potential credit risks and may not be able to repay a loan if they take it from the bank, and also predict the same for the future. The chapter will also talk in detail about our dataset, the main challenges when dealing with data, the main features of the dataset, and exploratory and descriptive analytics on the data. It will conclude with the best machine learning techniques suitable for tackling this problem.

Chapter 6, Credit Risk Detection and Prediction – Predictive Analytics, starts from where we left off in the previous chapter about descriptive analytics with looking at using predictive analytics. Here, we specifically deal with using several machine learning algorithms to detect and predict which customers would be potential credit risks and might not be likely to repay a loan to the bank if they take it. This would ultimately help the bank make data-driven decisions as to whether to approve the loan or not. We will be covering several supervised learning algorithms and compare their performance. Different metrics for evaluating the efficiency and accuracy of various machine learning algorithms will also be covered here.

Chapter 7, Social Media Analysis – Analyzing Twitter Data, introduces the world of social media analytics. We begin with an introduction to the world of social media and the process of collecting data through Twitter's APIs. The chapter will walk you through the process of mining useful information from tweets, including visualizing Twitter data with real-world examples, clustering and topic modeling of tweets, the present challenges and complexities, and strategies to address these issues. We show by example how some powerful measures can be computed using Twitter data.

Chapter 8, Sentiment Analysis of Twitter Data, builds upon the knowledge of Twitter APIs to work on a project for analyzing sentiments in tweets. This project presents multiple machine learning algorithms for the classification of tweets based on the sentiments inferred. This chapter will also present these results in a comparative manner and help you understand the workings and difference in results of these algorithms.

What you need for this book

This software applies to all the chapters of the book:

  • Windows / Mac OS X / Linux

  • R 3.2.0 (or higher)

  • RStudio Desktop 0.99 (or higher)

For hardware, there are no specific requirements, since R can run on any PC that has Mac, Linux, or Windows, but a physical memory of minimum 4 GB is preferred to run some of the iterative algorithms smoothly.

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 of machine learning will be helpful but is not necessary.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."

Any command-line input or output is written as follows:

# comparing cluster labels with actual iris  species labels.
table(iris$Species, clusters$cluster)

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "From recommendations related to Who to follow on Twitter to Other movies you might enjoy on Netflix to Jobs you may be interested in on LinkedIn, recommender engines are everywhere and not just on e-commerce platforms."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for this book from your account at http://www.packtpub.com. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

You can download the code files by following these steps:

  1. Log in or register to our website using your e-mail address and password.

  2. Hover the mouse pointer on the SUPPORT tab at the top.

  3. Click on Code Downloads & Errata.

  4. Enter the name of the book in the Search box.

  5. Select the book for which you're looking to download the code files.

  6. Choose from the drop-down menu where you purchased this book from.

  7. Click on Code Download.

Once the file is downloaded, please make sure that you unzip or extract the folder using the latest version of:

  • WinRAR / 7-Zip for Windows

  • Zipeg / iZip / UnRarX for Mac

  • 7-Zip / PeaZip for Linux

Downloading the color images of this book


We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/RMachineLearningByExample_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.