亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

tensowflow keras - model.predict 給出所有相同的輸出

tensowflow keras - model.predict 給出所有相同的輸出

開滿天機 2022-09-06 16:35:39
型。預測給出所有相同的輸出驗證和測試精度< 60%我嘗試將最后一個隱藏層更改為softmax,但它仍然沒有解決這個問題。任何反饋將不勝感激。我也嘗試過使用超參數,但我仍然找不到任何修復程序。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貢獻1880條經驗 獲得超4個贊

您的問題來自以下代碼行:。tf.keras.layers.Dense(output_size, activation='sigmoid')

問題是你正在使用2個神經元的“”激活,而不是1個神經元。sigmoid

使用 或 .2 neurons + activation = 'softmax'1 neuron + activation='sigmoid'


查看完整回答
反對 回復 2022-09-06
?
幕布斯7119047

TA貢獻1794條經驗 獲得超8個贊

如果,看起來,您正在嘗試使用單熱編碼標簽進行分類,那么您的代碼存在兩個問題。

首先,你使用了錯誤的損失;均方誤差 (MSE) 用于回歸問題,而不是分類問題。更改模型編譯以使用二進制交叉熵損失,即:

model.compile(optimizer='sgd', loss='binary_crossentropy', metrics=['accuracy'])

其次,正如其他答案中已經提示的那樣,將最后一層的激活函數更改為 ,即:softmax

tf.keras.layers.Dense(output_size, activation='softmax')

這是單熱編碼標簽的正確方法。


查看完整回答
反對 回復 2022-09-06
  • 2 回答
  • 0 關注
  • 166 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號