减少神经网络损失的问题

时间:2020-05-29 06:25:57

标签: python tensorflow keras neural-network

我有一个很大的数据和一个二进制分类问题,我想用神经网络训练它,我的神经网络结构使用了10多种组合,从3层到20层不等,我也尝试过拟合模型在较小的样本上进行调试,但我的损失丝毫没有减少!在每种组合,每种样本量的历元数之后,它卡在0.4上!但是奇怪的是,精度也不会降低,大约为0.8,这不是很差! 由于我是使用NN的新手,因此对于解决问题有什么建议吗? 我使用keras顺序模型库。

这是我设计的神经网络:

#Normalizing the data
from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X = sc.fit_transform(X)
print(X)

from keras import utils
y = utils.to_categorical(y)
print(y)

from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size = 0.9)

#Dependencies
import keras
from keras.models import Sequential
from keras.layers import Dense
# Neural network
model = Sequential()
model.add(Dense(24, input_dim=25, activation='relu'))
model.add(Dense(22, activation='relu'))
model.add(Dense(20, activation='sigmoid'))
model.add(Dense(18, activation='selu'))
model.add(Dense(18, activation='sigmoid'))
model.add(Dense(16, activation='relu'))
model.add(Dense(16, activation='sigmoid'))
model.add(Dense(14, activation='tanh'))
model.add(Dense(12, activation='relu'))
model.add(Dense(10, activation='sigmoid'))
model.add(Dense(8, activation='sigmoid'))
model.add(Dense(8, activation='selu'))
model.add(Dense(7, activation='relu'))
model.add(Dense(5, activation='relu'))
model.add(Dense(4, activation='sigmoid'))
model.add(Dense(2, activation='sigmoid'))
model.add(Dense(2, activation='sigmoid'))

opt = keras.optimizers.Adam(learning_rate=0.01)
model.compile(loss='categorical_crossentropy', optimizer = opt , metrics=['accuracy'])

history = model.fit(X_train, y_train, epochs=5000, batch_size=1000)

0 个答案:

没有答案