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 @@ -526,7 +526,7 @@ class SparseVector(
s" ${values.size} values.")

override def toString: String =
"(%s,%s,%s)".format(size, indices.mkString("[", ",", "]"), values.mkString("[", ",", "]"))
s"($size,${indices.mkString("[", ",", "]")},${values.mkString("[", ",", "]")})"

override def toArray: Array[Double] = {
val data = new Array[Double](size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.apache.spark.SparkException
@BeanInfo
case class LabeledPoint(label: Double, features: Vector) {
override def toString: String = {
"(%s,%s)".format(label, features)
s"($label,$features)"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class InformationGainStats(
val rightPredict: Predict) extends Serializable {

override def toString: String = {
"gain = %f, impurity = %f, left impurity = %f, right impurity = %f"
.format(gain, impurity, leftImpurity, rightImpurity)
s"gain = $gain, impurity = $impurity, left impurity = $leftImpurity, " +
s"right impurity = $rightImpurity"
}

override def equals(o: Any): Boolean = o match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class Node (
var stats: Option[InformationGainStats]) extends Serializable with Logging {

override def toString: String = {
"id = " + id + ", isLeaf = " + isLeaf + ", predict = " + predict + ", " +
"impurity = " + impurity + ", split = " + split + ", stats = " + stats
s"id = $id, isLeaf = $isLeaf, predict = $predict, impurity = $impurity, " +
Copy link
Member

Choose a reason for hiding this comment

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

These can use string interpolation. I take your point though it breaks the symmetry a bit and make this toString rely on details of the subclass. How about making the Predict.toString return something more compact like s"$predict ($prob)"?

s"split = $split, stats = $stats"
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ class Predict(
val predict: Double,
val prob: Double = 0.0) extends Serializable {

override def toString: String = {
"predict = %f, prob = %f".format(predict, prob)
}
override def toString: String = s"$predict (prob = $prob)"

override def equals(other: Any): Boolean = {
other match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ case class Split(
categories: List[Double]) {

override def toString: String = {
"Feature = " + feature + ", threshold = " + threshold + ", featureType = " + featureType +
", categories = " + categories
s"Feature = $feature, threshold = $threshold, featureType = $featureType, " +
s"categories = $categories"
}
}

Expand Down Expand Up @@ -68,4 +68,3 @@ private[tree] class DummyHighSplit(feature: Int, featureType: FeatureType)
*/
private[tree] class DummyCategoricalSplit(feature: Int, featureType: FeatureType)
extends Split(feature, Double.MaxValue, featureType, List())