Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
debakarr
GitHub Repository: debakarr/machinelearning
Path: blob/master/Part 2 - Regression/Multiple Linear Regression/multiple_linear_regression.R
1009 views
1
# Multiple Linear Regression
2
3
# Importing the dataset
4
dataset = read.csv('50_Startups.csv')
5
6
# Encoding categorical data
7
dataset$State = factor(dataset$State,
8
levels = c('New York', 'California', 'Florida'),
9
labels = c(1, 2, 3))
10
11
# Splitting the dataset into the Training set and Test set
12
# install.packages('caTools')
13
library(caTools)
14
set.seed(123)
15
split = sample.split(dataset$Profit, SplitRatio = 0.8)
16
training_set = subset(dataset, split == TRUE)
17
test_set = subset(dataset, split == FALSE)
18
19
# Feature Scaling
20
# training_set = scale(training_set)
21
# test_set = scale(test_set)
22
23
# Fitting Multiple Linear Regression to the Training set
24
regressor = lm(formula = Profit ~ .,
25
data = training_set)
26
27
# Predicting the Test set results
28
y_pred = predict(regressor, newdata = test_set)
29