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.