#拆分训练集和测试集 x_train, x_test, y_train, y_test = train_test_split 参数都是什么意思呢?

#拆分训练集和测试集

x_train, x_test, y_train, y_test = train_test_split(

    x, y, test_size=0.2, random_state=42)

完整模板:

train_X,test_X,train_y,test_y = train_test_split(train_data,train_target,test_size=0.3,random_state=5)

参数解释:

train_data:待划分样本数据

train_target:待划分样本数据的结果(标签)

test_size:测试数据占样本数据的比例,若整数则样本数量

random_state:设置随机数种子,保证每次都是同一个随机数。若为0或不填,则每次得到数据都不一样

猜你喜欢

转载自blog.csdn.net/weixin_42859280/article/details/110391992