Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import numpy as np
- def evaluate_measures(sample):
- n_samples = len(sample)
- n_classes = 0
- classes = dict()
- for c in sample:
- if c in classes:
- classes[c] += 1
- else:
- classes[c] = 1
- n_classes += 1
- probs = np.zeros(n_classes)
- for i, c in zip(range(n_classes), classes):
- probs[i] = classes[c] / n_samples
- gini = 1
- entropy = 0
- error = 1
- for p in probs:
- gini -= p * p
- entropy -= p * np.log(p)
- error = min(error, 1 - p)
- measures = {'gini': gini, 'entropy': entropy, 'error': error}
- return measures
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement