Skip to content

Commit

Permalink
Fixed issues with the updated PEP8 E127/128. Added NotImplementedErro…
Browse files Browse the repository at this point in the history
…r exception for points method on Space class.
  • Loading branch information
joelcox committed Jun 21, 2012
1 parent 70d8e7d commit 0ab7b43
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
3 changes: 1 addition & 2 deletions miner/classification.py
Expand Up @@ -16,8 +16,7 @@ def classify(self, record):

if len(record) != self.matrix.dimension:
raise IndexError('Amount of attributes (%s) does not match \
matrix dimension (%s)' %
(len(record), self.matrix.dimension))
matrix dimension (%s)' % (len(record), self.matrix.dimension))

# Normalize the record using the known mean and std of the columns,
# but only if the matrix is normalized
Expand Down
9 changes: 5 additions & 4 deletions miner/utils.py
Expand Up @@ -47,8 +47,7 @@ def records(self, records):

if attributes != self.dimension:
raise IndexError('Amount of attributes (%s) does not match \
matrix dimension (%s)' %
(array.shape[1], self.dimension))
matrix dimension (%s)' % (array.shape[1], self.dimension))

self.array = array

Expand All @@ -58,8 +57,7 @@ def classes(self, classes):

if len(classes) != len(self.array):
raise IndexError('Amount of classes (%s) does not match the \
amount of records (%s)' %
(len(classes), len(self.array)))
amount of records (%s)' % (len(classes), len(self.array)))

self.class_labels = classes

Expand All @@ -83,6 +81,9 @@ def normalize(self):
element = self.array[row_index, column_index]
self.array[row_index, column_index] = (element - mean) / std

def points(self, records):
raise NotImplementedError


class CappedOrderedList(object):
"""A list with a fixed size that maintains order"""
Expand Down
5 changes: 2 additions & 3 deletions tests/test_kmeans.py
Expand Up @@ -29,6 +29,5 @@ def test_assign_points(self):
self.kmeans.compute_distances()
self.kmeans.assign_points()

self.assertEquals(self.kmeans.clusters,
[{'points': [0, 1, 2]},
{'points': [3, 4, 5]}])
self.assertEquals(self.kmeans.clusters, [{'points': [0, 1, 2]},
{'points': [3, 4, 5]}])
4 changes: 4 additions & 0 deletions tests/test_matrix.py
Expand Up @@ -34,6 +34,10 @@ def test_classes(self):
self.matrix.classes(['A', 'B'])
self.assertEqual(self.matrix.class_labels, ['A', 'B'])

def test_points_not_implemented(self):
self.assertRaises(NotImplementedError, self.matrix.points,
[[1, 0], [0, 1]])

def test_normalize(self):
self.matrix.records([[1.0, 2, 30], [2, 8, 6], [4, 5, 100]])
self.matrix.normalize()
Expand Down

0 comments on commit 0ab7b43

Please sign in to comment.