Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_full_gain(self):
target = lambda x: x % 7
gain = OnlineInformationGain(target, target)
entropy = OnlineEntropy(target)
for i in xrange(50):
gain.add(i)
entropy.add(i)
self.assertEqual(gain.get_gain(), entropy.get_entropy())
self.assertGreaterEqual(gain.get_gain(), 0)
def test_valid_values(self):
entropy = OnlineEntropy(lambda x: x % 10)
for i in xrange(150):
entropy.add(i)
self.assertGreaterEqual(entropy.get_entropy(), 0.0)
def test_starts_in_zero(self):
entropy = OnlineEntropy(lambda x: None)
self.assertEqual(entropy.get_entropy(), 0)
def __init__(self, attribute, target):
self.attribute = attribute
self.H = OnlineEntropy(target)
self.G = defaultdict(lambda: OnlineEntropy(target))
self.G = defaultdict(lambda: OnlineEntropy(target))