将数据集分为训练集和和测试方法
方案一:
library(ISLR)
attach(Smarket)
smp_siz = floor(0.75*nrow(Smarket))
# creates a value for dividing the data into train and test. In this case the value is defined as 75% of the number of rows in the data
setsmp_siz # shows the value of the sample size
## [1] 937
set.seed(123) # set seed to ensure you always have same random numbers generated
train_ind = sample(seq_len(nrow(Smarket)),size = smp_siz) # Randomly identifies therows equal to sample size ( defined in previous instruction) from all the rows of Smarket dataset and stores the row number in train_ind
train =Smarket[train_ind,] #creates the training dataset with row numbers stored in train_indtest=Smarket[-train_ind,] # creates the test dataset excluding the row numbers mentioned in trai