開(kāi)滿(mǎn)天機(jī)
2022-09-06 16:35:39
型。預(yù)測(cè)給出所有相同的輸出驗(yàn)證和測(cè)試精度< 60%我嘗試將最后一個(gè)隱藏層更改為softmax,但它仍然沒(méi)有解決這個(gè)問(wèn)題。任何反饋將不勝感激。我也嘗試過(guò)使用超參數(shù),但我仍然找不到任何修復(fù)程序。raw_cvs_data = np.loadtxt('data_to_train.csv',delimiter=',') raw_cvs_data_to_compute = np.loadtxt('data_to_compute.csv',delimiter=',') unscaled_inputs_all = raw_cvs_data[:,1:] targets_all = raw_cvs_data[:,0] inputs_to_compute = raw_cvs_data_to_compute[:] predicted_target=[] # balancing the dataset num_one_targets = int(np.sum(targets_all)) # count how many targets are 1 zero_targets_counter = 0 # counter for target 0 indices_to_remove = [] # remove extra input/target pairs for balance # count the number of targets 0, when get same amount of target 1 and 0, make entries where target is zero for i in range(targets_all.shape[0]): if targets_all[i] == 0: zero_targets_counter +=1 if zero_targets_counter > num_one_targets: indices_to_remove.append(i) unscaled_inputs_equal_priors = np.delete(unscaled_inputs_all,indices_to_remove, axis = 0) targets_equal_priors = np.delete(targets_all, indices_to_remove, axis = 0) #Shuffle the data shuffled_indices = np.arange(scaled_inputs.shape[0]) np.random.shuffle(shuffled_indices) #shuffle pairs shuffled_inputs = scaled_inputs[shuffled_indices] shuffled_targets = targets_equal_priors[shuffled_indices] # splitting data samples_count = shuffled_inputs.shape[0] # |training|validation|testing| 80-10-10 train_samples_count = int(0.8 * samples_count) validation_samples_count = int(0.1 *samples_count) test_samples_count = samples_count - train_samples_count - validation_samples_count train_inputs = shuffled_inputs[:train_samples_count] train_targets = shuffled_targets[:train_samples_count]
2 回答

慕村225694
TA貢獻(xiàn)1880條經(jīng)驗(yàn) 獲得超4個(gè)贊
您的問(wèn)題來(lái)自以下代碼行:。tf.keras.layers.Dense(output_size, activation='sigmoid')
問(wèn)題是你正在使用2個(gè)神經(jīng)元的“”激活,而不是1個(gè)神經(jīng)元。sigmoid
使用 或 .2 neurons + activation = 'softmax'
1 neuron + activation='sigmoid'

幕布斯7119047
TA貢獻(xiàn)1794條經(jīng)驗(yàn) 獲得超8個(gè)贊
如果,看起來(lái),您正在嘗試使用單熱編碼標(biāo)簽進(jìn)行分類(lèi),那么您的代碼存在兩個(gè)問(wèn)題。
首先,你使用了錯(cuò)誤的損失;均方誤差 (MSE) 用于回歸問(wèn)題,而不是分類(lèi)問(wèn)題。更改模型編譯以使用二進(jìn)制交叉熵?fù)p失,即:
model.compile(optimizer='sgd', loss='binary_crossentropy', metrics=['accuracy'])
其次,正如其他答案中已經(jīng)提示的那樣,將最后一層的激活函數(shù)更改為 ,即:softmax
tf.keras.layers.Dense(output_size, activation='softmax')
這是單熱編碼標(biāo)簽的正確方法。
添加回答
舉報(bào)
0/150
提交
取消