Explain a simple linear regression in R

289    Asked by ranjan_6399 in Data Science , Asked on Jan 15, 2020
Answered by Ranjana Admin

# Simple Linear Regression

# Importing the dataset

dataset = read.csv('Salary_Data.csv')

# Splitting the dataset into the Training set and Test set

# install.packages('caTools')

library(caTools)

set.seed(123)

split = sample.split(dataset$Salary, SplitRatio = 2/3)

training_set = subset(dataset, split == TRUE)

test_set = subset(dataset, split == FALSE)

# Feature Scaling

# training_set = scale(training_set)

# test_set = scale(test_set)

# Fitting Simple Linear Regression to the Training set

regressor = lm(formula = Salary ~ YearsExperience,

               data = training_set)

# Predicting the Test set results

y_pred = predict(regressor, newdata = test_set)



Your Answer

Interviews

Parent Categories