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
Show 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:
...
@@ -59,3 +59,13 @@ class MEC:
p
=
[
coeff
*
e
**
(
-
.
5
*
dot
(
x
-
mu
,
dot
(
S
.
I
,
array
([
x
-
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
]
mu
]).
T
)).
tolist
()[
0
][
0
])
for
mu
,
S
,
coeff
in
self
.
class_data
]
return
self
.
classes
[
argmax
([
i
.
sum
()
for
i
in
p
])]
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
,
\
from
pylab
import
loadtxt
,
arange
,
loadtxt
,
permutation
,
zeros
,
sum
,
\
zeros
,
sum
,
plot
,
subplot
,
array
,
scatter
,
logical_and
,
figure
,
\
plot
,
subplot
,
array
,
scatter
,
logical_and
,
figure
,
savefig
,
seed
savefig
,
seed
from
sys
import
argv
,
exit
from
sys
import
argv
,
exit
import
classifiers
import
classifiers
...
@@ -17,7 +16,7 @@ if method == 'knnb':
...
@@ -17,7 +16,7 @@ if method == 'knnb':
k
=
int
(
argv
[
2
])
k
=
int
(
argv
[
2
])
if
argc
==
4
:
if
argc
==
4
:
seed
(
int
(
argv
[
3
]))
seed
(
int
(
argv
[
3
]))
elif
method
not
in
[
'nnb'
,
'mec'
]:
elif
method
not
in
[
'nnb'
,
'mec'
,
'svm'
]:
print
'Unknown classification method "%s"'
%
argv
[
1
]
print
'Unknown classification method "%s"'
%
argv
[
1
]
exit
()
exit
()
elif
argc
==
3
:
elif
argc
==
3
:
...
@@ -38,15 +37,11 @@ L = ind[0:90] # learning set indices
...
@@ -38,15 +37,11 @@ L = ind[0:90] # learning set indices
T
=
ind
[
90
:]
# test set indices
T
=
ind
[
90
:]
# test set indices
# Learning set
# Learning set
X
=
XC
[
L
,
0
:
4
]
args
=
[
XC
[
L
,
0
:
4
].
T
,
XC
[
L
,
-
1
]]
args
=
[
X
,
XC
[
L
,
-
1
]]
if
method
==
'knnb'
:
if
method
==
'nnb'
:
method_class
=
classifiers
.
NNb
elif
method
==
'knnb'
:
method_class
=
classifiers
.
kNNb
args
.
append
(
k
)
args
.
append
(
k
)
elif
method
==
'mec'
:
method_class
=
{
'nnb'
:
classifiers
.
NNb
,
'knnb'
:
classifiers
.
kNNb
,
method_class
=
classifiers
.
MEC
'mec'
:
classifiers
.
MEC
,
'svm'
:
classifiers
.
SVM
}[
method
]
classifier
=
method_class
(
*
args
)
classifier
=
method_class
(
*
args
)
# Classification of test set
# 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