Research breakthrough possible @S-Logix pro@slogix.in

Office Address

  • 2nd Floor, #7a, High School Road, Secretariat Colony Ambattur, Chennai-600053 (Landmark: SRM School) Tamil Nadu, India
  • pro@slogix.in
  • +91- 81240 01111

Social List

How to split data into train and test using caret package in R?

Description

To split the data into train and test in R using caret package in R programming.

Process

   R Package : caret

   R Function : createDataPartition(x ,p= ,list= )

x -- a vector of outcomes.

p -- the percentage of data that goes to training

List -- Logical-should the results be in a list (TRUE)

Sapmle Code

#Test and Split sample
#Loading required Packages
#install.packages(“caret”)
library(“caret”)

#Read the data
library(“xlsx”)
input<-read.xlsx(“mtcars.xlsx”,sheetIndex = 1)
print(input)

#Split Data
set.seed(123)
my_data<-mtcars$mpg

#Train set
my_train<-createDataPartition(my_data,p=0.7,list=FALSE)
train<-input[my_train,]
print(train)

#Test Data
my_test<-createDataPartition(my_data[-my_train],list=FALSE)
test<-input[-my_train,][my_test,]
print(test)

Screenshots
How to split data into train and test using caret package in R
Loading required Packages
split data into train and test using caret package in R