实现人脸识别性别之路---测试深度学习中的二分类返回的数据类型

#测试深度学习中的二分类返回的数据类型
import numpy as np
from sklearn.model_selection import train_test_split
import random
import tensorflow
from keras.utils import np_utils
x = np.arange(20).reshape((20,1))
fuc = []
for i in range(20):
  if i/10>=1:
    fuc.append(4)
  else:
    fuc.append(5)
  print(fuc)
X_data, X_test, y_train, y_test = train_test_split(x, fuc, test_size=0.3,random_state=random.randint(0, 100))
print(np.shape(y_train))
print(y_train)
Y_train = np_utils.to_categorical(y_train, num_classes=11)/255#num_classes表示有多少类。大于数字的总和也是可以的
print(y_train)

输出结果:

[5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]
(14,)
[5, 4, 4, 4, 4, 5, 5, 4, 5, 5, 5, 5, 5, 4]
[5, 4, 4, 4, 4, 5, 5, 4, 5, 5, 5, 5, 5, 4]
<class 'list'>
 
 
 
 
 
 
原文地址:https://www.cnblogs.com/MyUniverse/p/9465097.html