X_train,X_test, y_train, y_test =cross_validation.train_test_split(train_data,train_target,test_size=0.4, random_state=0)
cross_validatio为交叉验证
种子不同,产生不同的随机数;种子相同,即使实例不同也产生相同的随机数。
import numpy as np
from sklearn.model_selection import train_test_split
X,y=np.arange(10).reshape((5,2)),range
X=np.array([[0,1],[2,3],[4,5],[6,7],[8,9]])
y=[0,1,2,3,4]
print(X)
print(y)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=0)
print(X_train)
print(y_train)
print(X_test)
print(y_test)
结果为
[[0 1]
[2 3]
[4 5]
[6 7]
[8 9]]
[0, 1, 2, 3, 4]
[[2 3]
[6 7]
[8 9]]
[1, 3, 4]
[[4 5]
[0 1]]
[2, 0]