1)sklearn学习之train_test_split

代码

from __future__ import print_function
import numpy as np
from sklearn.model_selection import train_test_split

X, y = np.arange(10).reshape((5, 2)), range(5)

print(X)
#  [[ 0 1]
#  [ 2 3]
#  [ 4 5]
#  [ 6 7]
#  [ 8 9]]


print(y)
#  range(0, 5), [0, 1, 2, 3, 4]

X_train, X_test, y_train, y_test = train_test_split(X, y,
        test_size = 0.4, random_state = 22)
print(X_train)
#  [[6 7]
#   [0 1]
#  [8 9]]

print(y_train)
#  [3, 0, 4]

print(X_test)
#  [[2 3]
#  [4 5]]

print(y_test)
#  [1, 2]
发布了758 篇原创文章 · 获赞 35 · 访问量 60万+

猜你喜欢

转载自blog.csdn.net/kelsel/article/details/84843258