python - logistic regression debugging tensorflow -
i trying learn tensorflow , trying simple logistic regression model. here code stitched diffrent examples find.
with tf.session() sess: # training data input = tf.constant(tra) target = tf.constant(np.transpose(data[:,1]).astype(np.float64)) # set model weights w = tf.variable(np.random.randn(10, 1).astype(np.float64)) # construct model mat=tf.matmul(input,w) pred = tf.sigmoid(mat) # compute error yerror = tf.sub(pred, target) # going minimize l2 loss. l2 loss sum of # squared error our estimates of y. penalizes large errors # lot, small errors little. loss = tf.nn.l2_loss(yerror) # gradient descent update_weights = tf.train.gradientdescentoptimizer(0.05).minimize(loss) # initializing variables tf.initialize_all_variables().run() _ in range(50): # repeatedly run operations, updating tensorflow variable. sess.run(update_weights) print(loss.eval()) so code runs error dose not improve after each 'sess.run(update_weights)' itteration , have tried diffrent step sizes.
i wonder if setup corret?
i bit unsure how debugg since the calculation of done @ run command. traning data fine. if of see doing wrong in whole session build or give suggestions on how can debugg this.
help appreciated.
while doing reasonable thing regression, won't work in classification task. also, not typically intended logistic regression. logistic regression, maximize log prob(correct label|input) summed on data samples. done conveniently having softmax layer.
there useful mathematical properties come it, debugging. instance, if input totally random, loss should log (n). if set weights zero, should loss. if label samples, 1/3 positive, , 2/3 negative in binary classification, model doesn't take input account (just bias term) should return log(2/3), can debug getting extent.
Comments
Post a Comment