forked from aimacode/aima-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_learning.py
More file actions
37 lines (22 loc) · 919 Bytes
/
test_learning.py
File metadata and controls
37 lines (22 loc) · 919 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from learning import parse_csv, weighted_mode, weighted_replicate, DataSet, \
PluralityLearner, NaiveBayesLearner, NearestNeighborLearner
from utils import DataFile
def test_parse_csv():
Iris = DataFile('iris.csv').read()
assert parse_csv(Iris)[0] == [5.1, 3.5, 1.4, 0.2, 'setosa']
def test_weighted_mode():
assert weighted_mode('abbaa', [1, 2, 3, 1, 2]) == 'b'
def test_weighted_replicate():
assert weighted_replicate('ABC', [1, 2, 1], 4) == ['A', 'B', 'B', 'C']
def test_plurality_learner():
zoo = DataSet(name="zoo")
pL = PluralityLearner(zoo)
assert pL([]) == "mammal"
def test_naive_bayes():
iris = DataSet(name="iris")
nB = NaiveBayesLearner(iris)
assert nB([5, 3, 1, 0.1]) == "setosa"
def test_k_nearest_neighbors():
iris = DataSet(name="iris")
kNN = NearestNeighborLearner(iris, k=3)
assert kNN([5, 3, 1, 0.1]) == "setosa"