Skip to content

Instantly share code, notes, and snippets.

@vb100
Created July 16, 2017 19:14
Show Gist options
  • Save vb100/282e6753ad23524c762d9ac582a85193 to your computer and use it in GitHub Desktop.
Save vb100/282e6753ad23524c762d9ac582a85193 to your computer and use it in GitHub Desktop.
Polynomial Regression Template for Machine learning in R programming language. Prediction calculation.
# Regression Template
# Importing the dataset
dataset = read.csv('Position_Salaries.csv')
dataset = dataset[2:3] # Take into consideration onle 2 and 3 columns
# Splitting the datase into the Training set and Test set
#install.packages('caTools')
#library(caTools)
#set.seed(123)
#split = sample.split(dataset$DependentVariable, SplitRatio = 0.8)
#training_set = subset(dataset, split == TRUE)
#test_se = subset(dataset, split == FALSE)
# Feature Scaling
# training_set = scale(training_set)
# test_set = scale(test_set)
# Fitting the Regression Model to the dataset
# Create a regressor here
# Predicting a new result
y_pred = predict(regressor, data.frame(Level = 6.5))
# Visualising the Regression Model results
library(ggplot2)
ggplot() +
geom_point(aes(x = dataset$Level, y = dataset$Salary),
colour = 'red') +
geom_line(aes(x = dataset$Level, y = predict(regressor, newdata = )),
colour = 'blue') +
ggtitle('Truth of Bluff (Regression Model)') +
xlab('Level') +
ylab('Salary')
# Visualising the Regression Model results (for higher resolution and smoother curve)
library(ggplot2)
x_grid = seq(min(dataset$Level), max(dataset$Level), 0.1)
ggplot() +
geom_point(aes(x = x_grid, y =data.frame(Level = x_grid)),
colour = 'red') +
geom_line(aes(x = dataset$Level, y = predict(regressor, newdata = )),
colour = 'blue') +
ggtitle('Truth of Bluff (Regression Model)') +
xlab('Level') +
ylab('Salary')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment