【发布时间】:2020-05-27 07:40:02
【问题描述】:
我更改了数据类型,但无法解决错误。
我尝试过 One-Hot Encoding,但它也不起作用。
不知道怎么回事:(
seed = 0
np.random.seed(seed)
tf.set_random_seed(seed)
df = pd.read_csv('HW01_dataset_tae.txt', sep=',' ,header=None, names = ["Native", "Instructor", "Course", "Semester", "Class Size", "Evaluation"])
dataset = df.values # dataframe to int64
X = dataset[:,0:5] # attribute
Y_Eva = dataset[:,5] # class
e = LabelEncoder()
e.fit(Y_Eva)
Y = e.transform(Y_Eva)
K = 10
kFold = StratifiedKFold(n_splits=K, shuffle=True, random_state=seed)
accuracy = []
for train_index, test_index in kFold.split(X,Y):
model = Sequential()
model.add(Dense(16, input_dim=5, activation='relu'))
model.add(Dense(10, activation='relu'))
model.add(Dense(3, activation='softmax'))
model.compile(loss='mean_squared_error',
optimizer='adam',
metrics=['accuracy'])
model.fit(X[train_index], Y[train_index], epochs=100, batch_size=2)
错误;检查目标时出错:预期 dense_2 的形状为 (3,),但得到的数组的形状为 (1,)
在此处检测到; model.fit(X[train_index], Y[train_index], epochs=100, batch_size=2).
我喊什么?
【问题讨论】: