Repository: spark
Updated Branches:
  refs/heads/master c9ae79fba -> 20ea54cc7


[SPARK-2461] [PySpark] Add a toString method to GeneralizedLinearModel

Add a toString method to GeneralizedLinearModel, also change `__str__` to 
`__repr__` for some classes, to provide better message in repr.

This PR is based on #1388, thanks to sryza!

closes #1388

Author: Sandy Ryza <[email protected]>
Author: Davies Liu <[email protected]>

Closes #2625 from davies/string and squashes the following commits:

3544aad [Davies Liu] fix LinearModel
0bcd642 [Davies Liu] Merge branch 'sandy-spark-2461' of github.com:sryza/spark
1ce5c2d [Sandy Ryza] __repr__ back to __str__ in a couple places
aa9e962 [Sandy Ryza] Switch __str__ to __repr__
a0c5041 [Sandy Ryza] Add labels back in
1aa17f5 [Sandy Ryza] Match existing conventions
fac1bc4 [Sandy Ryza] Fix PEP8 error
f7b58ed [Sandy Ryza] SPARK-2461. Add a toString method to GeneralizedLinearModel


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/20ea54cc
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/20ea54cc
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/20ea54cc

Branch: refs/heads/master
Commit: 20ea54cc7a5176ebc63bfa9393a9bf84619bfc66
Parents: c9ae79f
Author: Sandy Ryza <[email protected]>
Authored: Mon Oct 6 14:05:45 2014 -0700
Committer: Josh Rosen <[email protected]>
Committed: Mon Oct 6 14:05:45 2014 -0700

----------------------------------------------------------------------
 .../spark/mllib/regression/GeneralizedLinearAlgorithm.scala    | 2 ++
 python/pyspark/mllib/regression.py                             | 3 +++
 python/pyspark/serializers.py                                  | 6 +++---
 python/pyspark/sql.py                                          | 2 +-
 4 files changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/20ea54cc/mllib/src/main/scala/org/apache/spark/mllib/regression/GeneralizedLinearAlgorithm.scala
----------------------------------------------------------------------
diff --git 
a/mllib/src/main/scala/org/apache/spark/mllib/regression/GeneralizedLinearAlgorithm.scala
 
b/mllib/src/main/scala/org/apache/spark/mllib/regression/GeneralizedLinearAlgorithm.scala
index d0fe417..00dfc86 100644
--- 
a/mllib/src/main/scala/org/apache/spark/mllib/regression/GeneralizedLinearAlgorithm.scala
+++ 
b/mllib/src/main/scala/org/apache/spark/mllib/regression/GeneralizedLinearAlgorithm.scala
@@ -75,6 +75,8 @@ abstract class GeneralizedLinearModel(val weights: Vector, 
val intercept: Double
   def predict(testData: Vector): Double = {
     predictPoint(testData, weights, intercept)
   }
+
+  override def toString() = "(weights=%s, intercept=%s)".format(weights, 
intercept)
 }
 
 /**

http://git-wip-us.apache.org/repos/asf/spark/blob/20ea54cc/python/pyspark/mllib/regression.py
----------------------------------------------------------------------
diff --git a/python/pyspark/mllib/regression.py 
b/python/pyspark/mllib/regression.py
index cbdbc09..8fe8c6d 100644
--- a/python/pyspark/mllib/regression.py
+++ b/python/pyspark/mllib/regression.py
@@ -66,6 +66,9 @@ class LinearModel(object):
     def intercept(self):
         return self._intercept
 
+    def __repr__(self):
+        return "(weights=%s, intercept=%s)" % (self._coeff, self._intercept)
+
 
 class LinearRegressionModelBase(LinearModel):
 

http://git-wip-us.apache.org/repos/asf/spark/blob/20ea54cc/python/pyspark/serializers.py
----------------------------------------------------------------------
diff --git a/python/pyspark/serializers.py b/python/pyspark/serializers.py
index 2672da3..099fa54 100644
--- a/python/pyspark/serializers.py
+++ b/python/pyspark/serializers.py
@@ -211,7 +211,7 @@ class BatchedSerializer(Serializer):
         return (isinstance(other, BatchedSerializer) and
                 other.serializer == self.serializer)
 
-    def __str__(self):
+    def __repr__(self):
         return "BatchedSerializer<%s>" % str(self.serializer)
 
 
@@ -279,7 +279,7 @@ class CartesianDeserializer(FramedSerializer):
         return (isinstance(other, CartesianDeserializer) and
                 self.key_ser == other.key_ser and self.val_ser == 
other.val_ser)
 
-    def __str__(self):
+    def __repr__(self):
         return "CartesianDeserializer<%s, %s>" % \
                (str(self.key_ser), str(self.val_ser))
 
@@ -306,7 +306,7 @@ class PairDeserializer(CartesianDeserializer):
         return (isinstance(other, PairDeserializer) and
                 self.key_ser == other.key_ser and self.val_ser == 
other.val_ser)
 
-    def __str__(self):
+    def __repr__(self):
         return "PairDeserializer<%s, %s>" % (str(self.key_ser), 
str(self.val_ser))
 
 

http://git-wip-us.apache.org/repos/asf/spark/blob/20ea54cc/python/pyspark/sql.py
----------------------------------------------------------------------
diff --git a/python/pyspark/sql.py b/python/pyspark/sql.py
index 974b5e2..114644a 100644
--- a/python/pyspark/sql.py
+++ b/python/pyspark/sql.py
@@ -201,7 +201,7 @@ class ArrayType(DataType):
         self.elementType = elementType
         self.containsNull = containsNull
 
-    def __str__(self):
+    def __repr__(self):
         return "ArrayType(%s,%s)" % (self.elementType,
                                      str(self.containsNull).lower())
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to