Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,11 @@ class LogisticRegressionModel private[spark] (
*/
@Since("1.6.0")
override def write: MLWriter = new LogisticRegressionModel.LogisticRegressionModelWriter(this)

override def toString: String = {
s"LogisticRegressionModel: " +
s"uid = ${super.toString}, numClasses = $numClasses, numFeatures = $numFeatures"
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2751,6 +2751,12 @@ class LogisticRegressionSuite extends MLTest with DefaultReadWriteTest {
assert(model.getFamily === family)
}
}

test("toString") {
val model = new LogisticRegressionModel("logReg", Vectors.dense(0.1, 0.2, 0.3), 0.0)
val expected = "LogisticRegressionModel: uid = logReg, numClasses = 2, numFeatures = 3"
assert(model.toString === expected)
}
}

object LogisticRegressionSuite {
Expand Down
5 changes: 5 additions & 0 deletions python/pyspark/ml/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ class LogisticRegression(JavaEstimator, HasFeaturesCol, HasLabelCol, HasPredicti
True
>>> blorModel.intercept == model2.intercept
True
>>> model2
LogisticRegressionModel: uid = ..., numClasses = 2, numFeatures = 2

.. versionadded:: 1.3.0
"""
Expand Down Expand Up @@ -562,6 +564,9 @@ def evaluate(self, dataset):
java_blr_summary = self._call_java("evaluate", dataset)
return BinaryLogisticRegressionSummary(java_blr_summary)

def __repr__(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So my question here is why we aren't calling the Java/Scala toString method directly as we do in the mllib one and in many of the other models in regression.py for the ml one?

return self._call_java("toString")


class LogisticRegressionSummary(JavaWrapper):
"""
Expand Down
3 changes: 3 additions & 0 deletions python/pyspark/mllib/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ def load(cls, sc, path):
model.setThreshold(threshold)
return model

def __repr__(self):
return self._call_java("toString")


class LogisticRegressionWithSGD(object):
"""
Expand Down