Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
uva
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
uva
Commits
443e0415
Commit
443e0415
authored
May 27, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
StatRed ass3: Bug fix.
parent
bd525558
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
12 deletions
+17
-12
statred/ass3/classifiers.py
statred/ass3/classifiers.py
+10
-0
statred/ass3/classify.py
statred/ass3/classify.py
+7
-12
No files found.
statred/ass3/classifiers.py
View file @
443e0415
...
...
@@ -59,3 +59,13 @@ class MEC:
p
=
[
coeff
*
e
**
(
-
.
5
*
dot
(
x
-
mu
,
dot
(
S
.
I
,
array
([
x
-
mu
]).
T
)).
tolist
()[
0
][
0
])
for
mu
,
S
,
coeff
in
self
.
class_data
]
return
self
.
classes
[
argmax
([
i
.
sum
()
for
i
in
p
])]
class
SVM
:
def
__init__
(
self
,
X
,
c
):
self
.
n
,
self
.
N
=
X
.
shape
self
.
X
,
self
.
c
=
X
,
c
def
classify
(
self
,
x
):
d
=
self
.
X
-
tile
(
x
.
reshape
(
self
.
n
,
1
),
self
.
N
);
dsq
=
sum
(
d
*
d
,
0
)
return
self
.
c
[
argmin
(
dsq
)]
statred/ass3/classify.py
View file @
443e0415
from
pylab
import
loadtxt
,
arange
,
loadtxt
,
permutation
,
transpose
,
\
zeros
,
sum
,
plot
,
subplot
,
array
,
scatter
,
logical_and
,
figure
,
\
savefig
,
seed
from
pylab
import
loadtxt
,
arange
,
loadtxt
,
permutation
,
zeros
,
sum
,
\
plot
,
subplot
,
array
,
scatter
,
logical_and
,
figure
,
savefig
,
seed
from
sys
import
argv
,
exit
import
classifiers
...
...
@@ -17,7 +16,7 @@ if method == 'knnb':
k
=
int
(
argv
[
2
])
if
argc
==
4
:
seed
(
int
(
argv
[
3
]))
elif
method
not
in
[
'nnb'
,
'mec'
]:
elif
method
not
in
[
'nnb'
,
'mec'
,
'svm'
]:
print
'Unknown classification method "%s"'
%
argv
[
1
]
exit
()
elif
argc
==
3
:
...
...
@@ -38,15 +37,11 @@ L = ind[0:90] # learning set indices
T
=
ind
[
90
:]
# test set indices
# Learning set
X
=
XC
[
L
,
0
:
4
]
args
=
[
X
,
XC
[
L
,
-
1
]]
if
method
==
'nnb'
:
method_class
=
classifiers
.
NNb
elif
method
==
'knnb'
:
method_class
=
classifiers
.
kNNb
args
=
[
XC
[
L
,
0
:
4
].
T
,
XC
[
L
,
-
1
]]
if
method
==
'knnb'
:
args
.
append
(
k
)
elif
method
==
'mec'
:
method_class
=
classifiers
.
MEC
method_class
=
{
'nnb'
:
classifiers
.
NNb
,
'knnb'
:
classifiers
.
kNNb
,
'mec'
:
classifiers
.
MEC
,
'svm'
:
classifiers
.
SVM
}[
method
]
classifier
=
method_class
(
*
args
)
# Classification of test set
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment