|
11 | 11 | import math |
12 | 12 | import random |
13 | 13 |
|
14 | | -from statistics import mean |
| 14 | +# XXX statistics.mode is not quite the same as the old utils.mode: |
| 15 | +# it insists on there being a unique most-frequent value. Code using mode |
| 16 | +# needs to be revisited, or we need to restore utils.mode. |
| 17 | +from statistics import mean, mode |
15 | 18 | from collections import defaultdict |
16 | 19 |
|
17 | 20 | # ______________________________________________________________________________ |
@@ -391,7 +394,7 @@ def split_by(attr, examples): |
391 | 394 | def information_content(values): |
392 | 395 | "Number of bits to represent the probability distribution in values." |
393 | 396 | probabilities = normalize(removeall(0, values)) |
394 | | - return sum(-p * log2(p) for p in probabilities) |
| 397 | + return sum(-p * math.log2(p) for p in probabilities) |
395 | 398 |
|
396 | 399 | # ______________________________________________________________________________ |
397 | 400 |
|
@@ -439,7 +442,6 @@ def NeuralNetLearner(dataset, hidden_layer_sizes=[3], |
439 | 442 | epoches: Number of passes over the dataset |
440 | 443 | """ |
441 | 444 |
|
442 | | - examples = dataset.examples |
443 | 445 | i_units = len(dataset.inputs) |
444 | 446 | o_units = 1 # As of now, dataset.target gives only one index. |
445 | 447 |
|
@@ -586,7 +588,6 @@ def BackPropagationLearner(dataset, net, learning_rate, epoches): |
586 | 588 |
|
587 | 589 | def PerceptronLearner(dataset, learning_rate=0.01, epoches=100): |
588 | 590 | """Logistic Regression, NO hidden layer""" |
589 | | - examples = dataset.examples |
590 | 591 | i_units = len(dataset.inputs) |
591 | 592 | o_units = 1 # As of now, dataset.target gives only one index. |
592 | 593 | hidden_layer_sizes = [] |
|
0 commit comments