FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
aima-python/tests/test_learning.py at sofmonk-test_utils · sofmonk/aima-python · GitHub
sofmonk
aima-python
Repository navigation
Code
Pull requests
4
(4)
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
aima-python
/
tests
/
test_learning.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
74 lines (46 loc) · 1.95 KB
Breadcrumbs
aima-python
/
tests
/
test_learning.py
Copy path
File metadata and controls
74 lines (46 loc) · 1.95 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from
learning
import
parse_csv
,
weighted_mode
,
weighted_replicate
,
DataSet
, \
PluralityLearner
,
NaiveBayesLearner
,
NearestNeighborLearner
, \
NeuralNetLearner
,
PerceptronLearner
,
DecisionTreeLearner
from
utils
import
DataFile
def
test_exclude
():
iris
=
DataSet
(
name
=
'iris'
,
exclude
=
[
3
])
assert
iris
.
inputs
==
[
0
,
1
,
2
]
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
([
1
,
0
,
0
,
1
,
0
,
0
,
0
,
1
,
1
,
1
,
0
,
0
,
4
,
1
,
0
,
1
])
==
"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"
def
test_decision_tree_learner
():
iris
=
DataSet
(
name
=
"iris"
)
dTL
=
DecisionTreeLearner
(
iris
)
assert
dTL
([
5
,
3
,
1
,
0.1
])
==
"setosa"
def
test_neural_network_learner
():
iris
=
DataSet
(
name
=
"iris"
)
iris
.
remove_examples
(
"virginica"
)
classes
=
[
"setosa"
,
"versicolor"
,
"virginica"
]
iris
.
classes_to_numbers
()
nNL
=
NeuralNetLearner
(
iris
)
# NeuralNetLearner might be wrong. Just check if prediction is in range.
assert
nNL
([
5
,
3
,
1
,
0.1
])
in
range
(
len
(
classes
))
def
test_perceptron
():
iris
=
DataSet
(
name
=
"iris"
)
iris
.
remove_examples
(
"virginica"
)
classes
=
[
"setosa"
,
"versicolor"
,
"virginica"
]
iris
.
classes_to_numbers
()
perceptron
=
PerceptronLearner
(
iris
)
# PerceptronLearner might be wrong. Just check if prediction is in range.
assert
perceptron
([
5
,
3
,
1
,
0.1
])
in
range
(
len
(
classes
))
Back
|
FazBrowse Home
|
New Git URL