import\ skimage.io\ as\ io#我改了两个文件\nimport\ numpy\ as\ np\npath\ =\ "D:/data\ python/face\ image/face_img/AF*.jpg"\ #数据集的路径\npictures\ =\ io.ImageCollection(path)\ndata\ =\ []\nfor\ i\ in\ range(len(pictures)):\n\ \ \ data.append(np.ravel(pictures[i].reshape((1,pictures[i].shape[0]*pictures[i].shape[1]*pictures[i].shape[2]))))\nlabel\ =\ []\nfor\ i\ in\ range(len(data)):\n\ \ \ label.append(int(i/10))\ndata=\np.matrix(data)\nlabel=\np.matrix(label).T\n帮我写一段代码,划分测试集为30%内容:from\ sklearn.model_selection\ import\ train_test_split\n\n#\ Splitting\ the\ data\ into\ training\ and\ testing\ sets\nX_train,\ X_test,\ y_train,\ y_test\ =\ train_test_split(data,\ label,\ test_size=\0.3,\ random_state=\42)\n\n#\ Print\ the\ shapes\ of\ the\ training\ and\ testing\ sets\nprint("Training\ set\ shape:\ ",\ X_train.shape)\nprint("Testing\ set\ shape:\ ",\ X_test.shape)\nprint("Training\ label\ shape:\ ",\ y_train.shape)\nprint("Testing\ label\ shape:\ ",\ y_test.shape)


原文地址: https://www.cveoy.top/t/topic/pN91 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录