Skip to content

Commit 8ab9e89

Browse files
committed
Fix Python3 error
1 parent a9817df commit 8ab9e89

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

mllib/src/main/scala/org/apache/spark/mllib/api/python/PythonMLLibAPI.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,7 @@ private[python] class PythonMLLibAPI extends Serializable {
975975
val model = new StreamingKMeansModel(
976976
clusterCenters.asScala.toArray, clusterWeights.asScala.toArray)
977977
.update(data, decayFactor, timeUnit)
978-
List(model.clusterCenters, model.clusterWeights).
979-
map(_.asInstanceOf[Object]).asJava
978+
List[AnyRef](model.clusterCenters, Vectors.dense(model.clusterWeights)).asJava
980979
}
981980

982981
}

python/pyspark/mllib/tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
import array as pyarray
2626
from time import time, sleep
2727

28-
from numpy import array, array_equal, zeros, inf, all, random, sum
28+
from numpy import array, array_equal, zeros, inf, all, random
29+
from numpy import sum as array_sum
2930
from py4j.protocol import Py4JJavaError
3031

3132
if sys.version_info[:2] <= (2, 6):
@@ -908,7 +909,7 @@ def test_accuracy_for_single_center(self):
908909
self.ssc.start()
909910
self._ssc_wait(t, 10.0, 0.01)
910911
self.assertEquals(stkm.latestModel.getClusterWeights, [25.0])
911-
realCenters = sum(array(centers), axis=0)
912+
realCenters = array_sum(array(centers), axis=0)
912913
for i in range(d):
913914
modelCenters = stkm.latestModel.centers[0][i]
914915
self.assertAlmostEqual(centers[0][i], modelCenters, 1)

0 commit comments

Comments
 (0)