Skip to content

Commit

Permalink
[SPARK-24973][PYTHON] Add numIter to Python ClusteringSummary
Browse files Browse the repository at this point in the history
## What changes were proposed in this pull request?

Add numIter to Python version of ClusteringSummary

## How was this patch tested?

Modified existing UT test_multiclass_logistic_regression_summary

Author: Huaxin Gao <huaxing@us.ibm.com>

Closes #21925 from huaxingao/spark-24973.
  • Loading branch information
huaxingao authored and srowen committed Jul 31, 2018
1 parent e82784d commit 42dfe4f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions python/pyspark/ml/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ def clusterSizes(self):
"""
return self._call_java("clusterSizes")

@property
@since("2.4.0")
def numIter(self):
"""
Number of iterations.
"""
return self._call_java("numIter")


class GaussianMixtureModel(JavaModel, JavaMLWritable, JavaMLReadable):
"""
Expand Down
3 changes: 3 additions & 0 deletions python/pyspark/ml/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1888,6 +1888,7 @@ def test_gaussian_mixture_summary(self):
self.assertTrue(isinstance(s.cluster, DataFrame))
self.assertEqual(len(s.clusterSizes), 2)
self.assertEqual(s.k, 2)
self.assertEqual(s.numIter, 3)

def test_bisecting_kmeans_summary(self):
data = [(Vectors.dense(1.0),), (Vectors.dense(5.0),), (Vectors.dense(10.0),),
Expand All @@ -1903,6 +1904,7 @@ def test_bisecting_kmeans_summary(self):
self.assertTrue(isinstance(s.cluster, DataFrame))
self.assertEqual(len(s.clusterSizes), 2)
self.assertEqual(s.k, 2)
self.assertEqual(s.numIter, 20)

def test_kmeans_summary(self):
data = [(Vectors.dense([0.0, 0.0]),), (Vectors.dense([1.0, 1.0]),),
Expand All @@ -1918,6 +1920,7 @@ def test_kmeans_summary(self):
self.assertTrue(isinstance(s.cluster, DataFrame))
self.assertEqual(len(s.clusterSizes), 2)
self.assertEqual(s.k, 2)
self.assertEqual(s.numIter, 1)


class KMeansTests(SparkSessionTestCase):
Expand Down

0 comments on commit 42dfe4f

Please sign in to comment.