Skip to content

Commit

Permalink
minor style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MechCoder committed Jun 19, 2015
1 parent 51052d3 commit 7722d16
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions python/pyspark/mllib/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,16 +893,16 @@ def test_model_params(self):
self.assertIsNone(stkm.latestModel())
self.assertRaises(ValueError, stkm.trainOn, [0.0, 1.0])

stkm.setInitialCenters([[0.0, 0.0], [1.0, 1.0]], [1.0, 1.0])
stkm.setInitialCenters(
centers=[[0.0, 0.0], [1.0, 1.0]], weights=[1.0, 1.0])
self.assertEquals(
stkm.latestModel().centers, [[0.0, 0.0], [1.0, 1.0]])
self.assertEquals(stkm.latestModel().clusterWeights, [1.0, 1.0])

def test_accuracy_for_single_center(self):
"""Test that the parameters obtained are correct for a single center."""
numBatches, numPoints, k, d, r, seed = 5, 5, 1, 5, 0.1, 0
"""Test that parameters obtained are correct for a single center."""
centers, batches = self.streamingKMeansDataGenerator(
numBatches, numPoints, k, d, r, seed)
batches=5, numPoints=5, k=1, d=5, r=0.1, seed=0)
stkm = StreamingKMeans(1)
stkm.setInitialCenters([[0., 0., 0., 0., 0.]], [0.])
input_stream = self.ssc.queueStream(
Expand All @@ -914,7 +914,7 @@ def test_accuracy_for_single_center(self):
self._ssc_wait(t, 10.0, 0.01)
self.assertEquals(stkm.latestModel().clusterWeights, [25.0])
realCenters = array_sum(array(centers), axis=0)
for i in range(d):
for i in range(5):
modelCenters = stkm.latestModel().centers[0][i]
self.assertAlmostEqual(centers[0][i], modelCenters, 1)
self.assertAlmostEqual(realCenters[i], modelCenters, 1)
Expand All @@ -934,8 +934,8 @@ def test_trainOn_model(self):
"""Test the model on toy data with four clusters."""
stkm = StreamingKMeans()
initCenters = [[1.0, 1.0], [-1.0, 1.0], [-1.0, -1.0], [1.0, -1.0]]
weights = [1.0, 1.0, 1.0, 1.0]
stkm.setInitialCenters(initCenters, weights)
stkm.setInitialCenters(
centers=initCenters, weights=[1.0, 1.0, 1.0, 1.0])

# Create a toy dataset by setting a tiny offest for each point.
offsets = [[0, 0.1], [0, -0.1], [0.1, 0], [-0.1, 0]]
Expand All @@ -958,10 +958,10 @@ def test_trainOn_model(self):

def test_predictOn_model(self):
"""Test that the model predicts correctly on toy data."""
initCenters = [[1.0, 1.0], [-1.0, 1.0], [-1.0, -1.0], [1.0, -1.0]]
weights = [1.0, 1.0, 1.0, 1.0]
stkm = StreamingKMeans()
stkm._model = StreamingKMeansModel(initCenters, weights)
stkm._model = StreamingKMeansModel(
clusterCenters=[[1.0, 1.0], [-1.0, 1.0], [-1.0, -1.0], [1.0, -1.0]],
clusterWeights=[1.0, 1.0, 1.0, 1.0])

predict_data = [[[1.5, 1.5]], [[-1.5, 1.5]], [[-1.5, -1.5]], [[1.5, -1.5]]]
predict_data = [sc.parallelize(batch, 1) for batch in predict_data]
Expand Down

0 comments on commit 7722d16

Please sign in to comment.