【问题标题】:ValueError: y should be a 1d array, got an array of shape (9121, 14) insteadValueError: y 应该是一维数组,得到一个形状为 (9121, 14) 的数组
【发布时间】:2021-10-15 20:05:51
【问题描述】:

我正在运行这些代码行:

import tensorflow
import keras
from keras.utils import np_utils
import pickle

# Get the data into the correct format for Keras 
X_train = np.array(X_train)
y_train = np.array(y_train)
X_test = np.array(X_test)
y_test = np.array(y_test)

# One hot encode the target 
lb = LabelEncoder()
y_train = np_utils.to_categorical(lb.fit_transform(y_train))
y_test = np_utils.to_categorical(lb.fit_transform(y_test))

print(X_train.shape)
print(lb.classes_)
#print(y_train[0:10])
#print(y_test[0:10])

# Pickle the lb object for future use 
filename = 'labels'
outfile = open(filename,'wb')
pickle.dump(lb,outfile)
outfile.close()

我收到了这个错误:

我不确定我在这里做错了什么。谁能帮我解决这个问题?

【问题讨论】:

    标签: python arrays keras


    【解决方案1】:

    您需要在 LabelEncoder 中传递一维标签数组。 LabelEncoder 用于形状为 (n_samples,)) 的一维数据

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-05
      • 1970-01-01
      • 2022-01-09
      • 2021-10-06
      • 2021-08-20
      • 2019-07-09
      相关资源
      最近更新 更多