train_test_split(random_state) [sklearn]

X_train,X_test,y_train,y_test = train_test_split(
iris_dataset[‘data’],iris_dataset[‘target’],random_state=0)

在SKILEARN中,train_test_split方法有一个参数叫random_state,它的用途是在随机划分训练集和测试集时候,划分的结果并不是那么随机,也即,确定下来random_state是某个值后,重复调用这个函数,划分结果是确定的。

train_test_split splits arrays or matrices into random train and test subsets. That means that everytime you run it without specifying random_state, you will get a different result, this is expected behaviour. For example:

Run 1:

a, b = np.arange(10).reshape((5, 2)), range(5) >>> train_test_split(a, b) [array([[6, 7], [8, 9], [4, 5]]), array([[2, 3], [0, 1]]), [3, 4, 2], [1, 0]]
Run 2

train_test_split(a, b) [array([[8, 9], [4, 5], [0, 1]]), array([[6, 7], [2, 3]]), [4, 2, 0], [3, 1]]
If you use random_state=some_number, then you can guarantee that your split will be always the same. This is useful if you want reproducible results, for example in testingor for consistency in the documentation (so that everybody can see the same numbers) . I would say, set the random_state to some fixed number while you test stuff, but then remove it in production if you need a random (and not a fixed) split.

Regarding your second question, a pseudo random number generator is a number generator that generates almost truly random numbers. Why they are not truly random is out of the scope of this question and should not matter in your case, take a look here form more details.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值