【R 语言 数据抽样】将样本总体分为样本集和测试集

方法1:

rm(list=ls())
gc()
german_credit <- read.csv("C:/pic/credit/german_credit.csv",sep = ",")

names(german_credit)

# 需要将样本总体分为样本集和测试集
# 简单随机抽样
smp1<-sample(nrow(german_credit),300,replace=F)
train_data=german_credit[-smp1,]
test_data=german_credit[smp1,]

方法二:

library(caret)
train1 <-createDataPartition(y=german_credit$Creditability,p=0.75,list=FALSE)
train <- german_credit[train1, ]
test <- german_credit[-train1, ]
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页