Book Image

R Data Science Essentials

Book Image

R Data Science Essentials

Overview of this book

With organizations increasingly embedding data science across their enterprise and with management becoming more data-driven it is an urgent requirement for analysts and managers to understand the key concept of data science. The data science concepts discussed in this book will help you make key decisions and solve the complex problems you will inevitably face in this new world. R Data Science Essentials will introduce you to various important concepts in the field of data science using R. We start by reading data from multiple sources, then move on to processing the data, extracting hidden patterns, building predictive and forecasting models, building a recommendation engine, and communicating to the user through stunning visualizations and dashboards. By the end of this book, you will have an understanding of some very important techniques in data science, be able to implement them using R, understand and interpret the outcomes, and know how they helps businesses make a decision.
Table of Contents (15 chapters)
R Data Science Essentials
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Sampling the dataset


While building the model, we need to have a training dataset that will be used to train the model, and then we will have a test dataset where the model that we built can be tested. Let's see the procedure to split the dataset into a training set and testing set:

# divide into sample
training_positions<- sample(nrow(wcdata), size=floor((nrow(wcdata)*0.7)))

The preceding code will take the sample of a specific size—in this case, it is 70% of the original dataset. We are considering 70% of the data as the training dataset and the remaining will be considered as the test dataset. The dataset will be randomly split; it is very important to split the dataset on a random basis in order to ensure consistency in the behavior mix of the data in the test set as well as the train set. We can use the set.seed() function to make sure that the output doesn't change while rerunning the code:

# Split into train and test based on the sample size
traindata<-wcdata[training_positions...