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...