How to find Train Data Set and Test Data Set in R

Hi All, We will learn today how to find train and train sets from a data in R:

First we will use “kernlab” library to load the “spam” data

library(kernlab) # to call the library kernlab

data(spam) # to load the spam data

spamids <- sample(1:dim(spam)[1], 300) # select sample 300 ids

spamtrain <- spam[-spamids, ] # remove sample spamids and select the rest as training set

spamtest <- spam[spamids, ] # select spamids only and set it as a test set

So you got spamtrain as the training dataset to build a model with this data

And you got spamtest as the test dataset to validate a model built on training dataset

Happy Learning! Continue following our blogs, news, events, jobs and more. Keep yourself updated.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.