本文整理汇总了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)