Skip to content

Instantly share code, notes, and snippets.

@islandjoe
Created December 8, 2018 11:30
Show Gist options
  • Save islandjoe/5b6311f83a4df0fc60cc428d156173ca to your computer and use it in GitHub Desktop.
Save islandjoe/5b6311f83a4df0fc60cc428d156173ca to your computer and use it in GitHub Desktop.
Data preprocessing template for Machine Learning in R
# Import dataset:
dataset = read.csv('Data.csv')
#dataset = dataset[, 2:3]

# Split dataset into training and test sets:
#install.packages('caTools')
library(caTools)
set.seed(101)
split = sample.split(dataset$Purchased, SplitRatio = 0.8)
training_set = subset(dataset, split = TRUE)
test_set     = subset(dataset, split = FALSE)

# Feature scaling:
#trainining_set[, 2:3] = scale(trainining_set[, 2:3]
#test_set[, 2:3]       = scale(test_set[, 2:3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment