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

Linear regression


Building a linear regression model is very similar to building a logistic regression model. In simple linear regression, we predict the value of a dependent variable based on the value of other independent variables. In case of multiple linear regression, we will predict the dependent variable based on two or more independent variables.

Let's learn the implementation of linear regression using R. First, we need to divide the dataset into training and testing data. The code that is used to split the dataset is very similar to the code explained in the Sampling the dataset section. You can use the following code on the dataset that was created to explore the linear regression:

# divide into sample
training_positions<- sample(nrow(wdata), size=floor((nrow(wdata)*0.7)))
# Split into train and test based on the sample size
traindata<-wdata[training_positions,]
testdata<-wdata[-training_positions,]
nrow(traindata)
nrow(testdata)

The preceding code splits the dataset into...