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
b9a4a734
Commit
b9a4a734
authored
May 27, 2011
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
StatRed ass3: Started work on part 3.
parent
443e0415
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
7 deletions
+9
-7
statred/ass3/classifiers.py
statred/ass3/classifiers.py
+9
-7
No files found.
statred/ass3/classifiers.py
View file @
b9a4a734
from
pylab
import
argmin
,
argmax
,
tile
,
unique
,
argwhere
,
array
,
mean
,
\
newaxis
,
dot
,
pi
,
e
,
matrix
from
svm
import
svm_model
,
svm_problem
,
svm_parameter
,
LINEAR
class
NNb
:
def
__init__
(
self
,
X
,
c
):
...
...
@@ -42,8 +43,8 @@ class MEC:
self
.
estimate
()
def
estimate
(
self
):
"""Estimate the mean and covariance matrix
each class in the learning
set."""
"""Estimate the mean and covariance matrix
for each class in the
learning
set."""
self
.
class_data
=
[]
for
c
in
self
.
classes
:
indices
=
argwhere
(
array
(
map
(
lambda
x
:
x
if
x
==
c
else
0
,
...
...
@@ -56,16 +57,17 @@ class MEC:
self
.
class_data
.
append
((
mu
,
S
,
coeff
))
def
classify
(
self
,
x
):
"""Use the sum of all entries in the pdf matrix to determine the class
with the greatest probability."""
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
px
=
svm_problem
(
c
.
tolist
(),
X
.
T
)
pm
=
svm_parameter
(
kernel_type
=
LINEAR
)
self
.
model
=
svm_model
(
px
,
pm
)
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
)]
return
self
.
model
.
predict
(
x
)
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