Get Data -iris, divide the training set and test set
from sklearn.datasets Import load_iris # 1. acquired data set (IRIS) IRIS = load_iris () # Print ( "IRIS data set content:", iris) # Data, target, target_name Print ( " training data set shape: " , IRIS .data.shape) Print ( " target shape: " , iris.target.shape) Print ( " target name: " , iris.target_names) # 2. partitioned data set from sklearn.model_selection Import train_test_split # test_size, train_size, random_stat x_train, x_test, y_train, y_test = train_test_split(iris.data, iris.target,test_size=0.25) print("训练集x-y:", x_train.shape, y_train.shape) print("测试集x-y:", x_test.shape, y_test.shape)
operation result:
Shape training data set: (150, 4 ) the target shape: ( 150 ,) the target name: [ ' setosa ' ' versicolor ' ' virginica. ' ] Training set X -Y: (112, 4), (112 ,) the test set X -Y: (38 is,. 4) (38 is,)