Skip to content

Commit

Permalink
[MINOR] [MLLIB] Refactor toString method in MLLIB
Browse files Browse the repository at this point in the history
1. predict(predict.toString) has already output prefix “predict” thus it’s duplicated to print ", predict = " again
2. there are some extra spaces

Author: Alain <aihe@usc.edu>

Closes #5687 from AiHe/tree-node-issue-2 and squashes the following commits:

9862b9a [Alain] Pass scala coding style checking
44ba947 [Alain] Minor][MLLIB] Format toString method in MLLIB
bdc402f [Alain] [Minor][MLLIB] Fix a formatting bug in toString method in Node
426eee7 [Alain] [Minor][MLLIB] Fix a formatting bug in toString method in Node.scala
  • Loading branch information
Alain authored and srowen committed Apr 26, 2015
1 parent f5473c2 commit 9a5bbe0
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 12 deletions.
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, " +
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())

0 comments on commit 9a5bbe0

Please sign in to comment.