Skip to content
Snippets Groups Projects
Commit 9a5bbe05 authored by Alain's avatar Alain Committed by Sean Owen
Browse files

[MINOR] [MLLIB] Refactor toString method in MLLIB

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
parent f5473c2b
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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)"
}
}
......
......@@ -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 {
......
......@@ -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"
}
/**
......
......@@ -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 {
......
......@@ -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"
}
}
......@@ -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% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment