Book Image

R Data Mining

Book Image

R Data Mining

Overview of this book

R is widely used to leverage data mining techniques across many different industries, including finance, medicine, scientific research, and more. This book will empower you to produce and present impressive analyses from data, by selecting and implementing the appropriate data mining techniques in R. It will let you gain these powerful skills while immersing in a one of a kind data mining crime case, where you will be requested to help resolving a real fraud case affecting a commercial company, by the mean of both basic and advanced data mining techniques. While moving along the plot of the story you will effectively learn and practice on real data the various R packages commonly employed for this kind of tasks. You will also get the chance of apply some of the most popular and effective data mining models and algos, from the basic multiple linear regression to the most advanced Support Vector Machines. Unlike other data mining learning instruments, this book will effectively expose you the theory behind these models, their relevant assumptions and when they can be applied to the data you are facing. By the end of the book you will hold a new and powerful toolbox of instruments, exactly knowing when and how to employ each of them to solve your data mining problems and get the most out of your data. Finally, to let you maximize the exposure to the concepts described and the learning process, the book comes packed with a reproducible bundle of commented R scripts and a practical set of data mining models cheat sheets.
Table of Contents (22 chapters)
Title Page
About the Author
About the Reviewers
Customer Feedback


You have probably heard that R is a fabulous tool that is gaining in popularity everyday among data analysts and data scientists, and that it is renowned for its ability to deliver highly flexible and professional results, paired with astonishing data visualizations. All this sounds great, but how can you learn to use R as a data mining tool? This book will guide you from the very beginning of this journey; you will not need to bring anything with you except your curiosity, since we will discover everything we need along the way.

The book will help you develop these powerful skills through immersion in a crime case that requires the use of data mining skills to solve, where you will be asked to help resolve a real fraud case affecting a commercial company using both basic and advanced data mining techniques.

At the end of our trip into the R world, you will be able to identify data mining problems, analyze them, and correctly address them with the main data mining techniques (and some advanced ones), producing astonishing final reports to convey messages and narrate the stories you found within your data.

What this book covers

Chapter 1,Why to Choose R for Your Data Mining and Where to Start, gives you some relevant facts about R's history, its main strengths and weaknesses, and how to install the language on your computer and write basic code.

Chapter 2, A First Primer on Data Mining -Analyzing Your Bank Account Data, applies R to our data.

Chapter 3, The Data Mining Process - the CRISP-DM Methodology, teaches you to organize and conduct a data mining project through the CRISP-DM methodology.

Chapter 4, Keeping the Home Clean – The Data Mining Architecture, defines the static part of our data mining projects, the data mining architecture.

Chapter 5, How to Address a Data Mining Problem – Data Cleaning and Validation, covers data quality and data validation, where you will find out which metrics define the level of quality of our data and discover a set of checks that can be employed to assess this quality.

Chapter 6, Looking into Your Data Eyes – Exploratory Data Analysis, teaches you about the concept of exploratory data analysis and how it can be included within the data analysis process.

Chapter 7, Our First Guess – A Linear Regression, lets us estimate a simple linear regression model and check whether its assumptions have been satisfied.

Chapter 8, A Gentle Introduction to Model Performance Evaluation, covers the tools used to define and measure the performance of data mining models.

Chapter 9, Don't Give Up – Power Up Your Regression Including Multiple Variables, predicts the output of our response variable when more than one exploratory variable is involved.

Chapter 10, A Different Outlook to Problems with Classification Models, looks into classification models, the need of them and they are uses.

Chapter 11, The Final Clash – Random Forest and Ensemble Learning, in this chapter we will learn how to apply ensemble learning to estimated classification models.

Chapter 12, Looking for the Culprit – Text Data Mining with R, shows how to prepare the data frame for text mining activities, removing irrelevant words and transforming it from a list of sentences to a list of words. You also learn to perform sentiment analyses, wordcloud development, and n-gram analyses on it.

Chapter 13, Sharing Your Stories with Your Stakeholders through R Markdown, employs R markdown and shiny, two powerful instruments made available within the RStudio ecosystem.

Chapter 14, Epilogue, is the unique background story made to learn the topics in a very engaging manner.

Appendix, Dealing with Dates, Relative Paths, and Functions, includes additional information to get things running in R.

What you need for this book

You will easily be able to sail through the chapters by employing R and UNIX or Windows. The version used is R 3.4.0.

Who this book is for

If you are a budding data scientist or a data analyst with basic knowledge of R, and you want to get into the intricacies of data mining in a practical manner, this is the book for you. No previous experience of data mining is required.


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, path names, dummy URLs, user input, and Twitter handles are shown as follows: "Finally, ggplot2 gives you the ability to highly customize your plot, adding every kind of graphical or textual annotation to it."

A block of code is set as follows:


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: "In order to download new modules, we will go to Files | Settings | Project Name | Project Interpreter."


Warnings or important notes appear like this.


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 email [email protected], 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

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 If you purchased this book elsewhere, you can visit and register to have the files emailed directly to you. You can download the code files by following these steps:

  1. Log in or register to our website using your email 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

The code bundle for the book is also hosted on GitHub at We also have other code bundles from our rich catalog of books and videos available at Check them out!

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


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, 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 and enter the name of the book in the search field. The required information will appear under the Errata section.


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 [email protected] with a link to the suspected pirated material. We appreciate your help in protecting our authors and our ability to bring you valuable content.


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