神经网络精度优化 [英] Neural network accuracy optimization

查看:90
本文介绍了神经网络精度优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在喀拉拉邦构造了一个人工神经网络,它具有1个输入层(3个输入),一个输出层(1个输出)和两个分别具有12和3个节点的隐藏层.

I have constructed an ANN in keras which has 1 input layer(3 inputs), one output layer (1 output) and two hidden layers with with 12 and 3 nodes respectively.

我构建和训练网络的方式是:

The way i construct and train my network is:

from keras.models import Sequential
from keras.layers import Dense
from sklearn.cross_validation import train_test_split
import numpy
# fix random seed for reproducibility
seed = 7
numpy.random.seed(seed)

dataset = numpy.loadtxt("sorted output.csv", delimiter=",")
# split into input (X) and output (Y) variables
X = dataset[:,0:3]
Y = dataset[:,3]
# split into 67% for train and 33% for test
X_train, X_test, y_train, y_test = train_test_split(X, Y, test_size=0.33, random_state=seed)
# create model
model = Sequential()
model.add(Dense(12, input_dim=3, init='uniform', activation='relu'))
model.add(Dense(3, init='uniform', activation='relu'))
model.add(Dense(1, init='uniform', activation='sigmoid'))
# Compile model
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])
# Fit the model
model.fit(X_train, y_train, validation_data=(X_test,y_test), nb_epoch=150, batch_size=10)

排序后的输出csv文件如下:

Sorted output csv file looks like:

所以在150个时期之后我得到:损失:0.6932-acc:0.5000-val_loss:0.6970-val_acc:0.1429

so after 150 epochs i get: loss: 0.6932 - acc: 0.5000 - val_loss: 0.6970 - val_acc: 0.1429

我的问题是:我如何修改我的神经网络以获得更高的准确性?

My question is: how could i modify my NN in order to achieve higher accuracy?

推荐答案

尼尔·斯莱特(Neil Slater)已经提供了一长串有用的一般建议.

Neil Slater already provided a long list of helpful general advices.

在您的特定示例中,规范化很重要.如果您在代码中添加以下行

In your specific examaple, normalization is the important thing. If you add the following lines to your code

...
X = dataset[:,0:3]
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
X = scaler.fit_transform(X)

即使使用更简单的网络结构,您的玩具数据也将获得100%的准确性.没有规范化,优化器将无法正常工作.

you will get 100% accuracy on your toy data, even with much simpler network structures. Without normalization, the optimizer won't work.

这篇关于神经网络精度优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆