本文整理匯總了Python中NN.trainNN方法的典型用法代碼示例。如果您正苦於以下問題:Python NN.trainNN方法的具體用法?Python NN.trainNN怎麽用?Python NN.trainNN使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類NN
的用法示例。
在下文中一共展示了NN.trainNN方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: checkNNGradients
# 需要導入模塊: import NN [as 別名]
# 或者: from NN import trainNN [as 別名]
print "Part 7: Implement Regularization\n"
print "Checking Backpropagation\n"
LEARN_RATE = 3
from checkNNGradients import checkNNGradients
checkNNGradients(LEARN_RATE)
J, _ = NN.nnCostFunction(W, conf.INPUT_LAYER_SIZE, conf.HIDDEN_LAYER_SIZE,
conf.NUM_LABELS, X, y, LEARN_RATE)
print ("Cost at parameters (loaded from w1.txt and w2.txt): %f"
"\n(this value should be about 0.576051)\n") % J
print "Part 8: Training NN\n"
def costFunc(p):
return NN.nnCostFunction(p, conf.INPUT_LAYER_SIZE,
conf.HIDDEN_LAYER_SIZE, conf.NUM_LABELS,
X, y, conf.PART8_LEARN_RATE)
nn_params = NN.trainNN(costFunc, init_W, conf.MAX_ITER)
W1 = np.reshape(nn_params[:conf.HIDDEN_LAYER_SIZE *
(conf.INPUT_LAYER_SIZE + 1)],
(conf.HIDDEN_LAYER_SIZE, (conf.INPUT_LAYER_SIZE + 1)))
W2 = np.reshape(nn_params[conf.HIDDEN_LAYER_SIZE *
(conf.INPUT_LAYER_SIZE + 1):],
(conf.NUM_LABELS, (conf.HIDDEN_LAYER_SIZE + 1)))
print "Part 9: Implement Predict\n"
pred = NN.predict(W1, W2, X)
print "Training Set Accuracy: %f\n" % ((pred == y).mean() * 100)