Beispiel #1
0
 def testBinarySVMDefaultWeights(self):
     target_column = target_column_lib.binary_svm_target()
     predictions = constant_op.constant([[-0.5], [1.2]])
     labels = constant_op.constant([0, 1])
     loss = target_column.loss(predictions, labels, {})
     # Prediction for first example is in the right side of the hyperplane (i.e.,
     # < 0) but it is within the [-1,1] margin. There is a 0.5 loss incurred by
     # this example. The 2nd prediction is outside the margin so it incurs no
     # loss at all. The overall (normalized) loss is therefore 0.5/(1+1) = 0.25.
     with session.Session() as sess:
         self.assertAlmostEqual(0.25, sess.run(loss))
 def testBinarySVMDefaultWeights(self):
   target_column = target_column_lib.binary_svm_target()
   predictions = constant_op.constant([[-0.5], [1.2]])
   labels = constant_op.constant([0, 1])
   loss = target_column.loss(predictions, labels, {})
   # Prediction for first example is in the right side of the hyperplane (i.e.,
   # < 0) but it is within the [-1,1] margin. There is a 0.5 loss incurred by
   # this example. The 2nd prediction is outside the margin so it incurs no
   # loss at all. The overall (normalized) loss is therefore 0.5/(1+1) = 0.25.
   with session.Session() as sess:
     self.assertAlmostEqual(0.25, sess.run(loss))
 def testBinarySVMWithWeights(self):
   target_column = target_column_lib.binary_svm_target(
       weight_column_name="weights")
   predictions = constant_op.constant([[-0.7], [0.2]])
   labels = constant_op.constant([0, 1])
   features = {"weights": constant_op.constant([2.0, 10.0])}
   loss = target_column.loss(predictions, labels, features)
   training_loss = target_column.training_loss(predictions, labels, features)
   # Prediction for both examples are in the right side of the hyperplane but
   # within the margin. The (weighted) loss incurred is 2*0.3=0.6 and 10*0.8=8
   # respectively. The overall (normalized) loss is therefore 8.6/12.
   with session.Session() as sess:
     self.assertAlmostEqual(8.6 / 12, sess.run(loss), places=3)
     self.assertAlmostEqual(8.6 / 2, sess.run(training_loss), places=3)
Beispiel #4
0
 def testBinarySVMWithWeights(self):
     target_column = target_column_lib.binary_svm_target(
         weight_column_name="weights")
     predictions = constant_op.constant([[-0.7], [0.2]])
     labels = constant_op.constant([0, 1])
     features = {"weights": constant_op.constant([2.0, 10.0])}
     loss = target_column.loss(predictions, labels, features)
     training_loss = target_column.training_loss(predictions, labels,
                                                 features)
     # Prediction for both examples are in the right side of the hyperplane but
     # within the margin. The (weighted) loss incurred is 2*0.3=0.6 and 10*0.8=8
     # respectively. The overall (normalized) loss is therefore 8.6/12.
     with session.Session() as sess:
         self.assertAlmostEqual(8.6 / 12, sess.run(loss), places=3)
         self.assertAlmostEqual(8.6 / 2, sess.run(training_loss), places=3)