以鸢尾花为例:
将上面的写到一个函数中:
import numpy as np
def train_test_split(X,y,test_ratio=0.2,seed=None):
"""将数据 X 和 y 按照test_ratio分割成X_train, X_test, y_train, y_test"""
assert X.shape[0] == y.shape[0], \
"the size of X must be equal to the size of y"
assert 0.0 <= test_ratio <= 1.0, \
"test_ration must be valid"
if seed