Skip to content
Closed
Changes from 1 commit
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
Prev Previous commit
use singleton objects for label parsers
  • Loading branch information
mengxr committed Apr 8, 2014
commit ac444093df8bf395de8bfb7e8cbe9ab5bf7b2fee
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,23 @@ trait LabelParser extends Serializable {
* Label parser for binary labels, which outputs 1.0 (positive) if the value is greater than 0.5,
* or 0.0 (negative) otherwise. So it works with +1/-1 labeling and +1/0 labeling.
*/
class BinaryLabelParser extends LabelParser {
object BinaryLabelParser extends LabelParser {
/** Gets the default instance of BinaryLabelParser. */
def getInstance(): LabelParser = this

/**
* Parses the input label into positive (1.0) if the value is greater than 0.5,
* or negative (0.0) otherwise.
*/
override def parse(labelString: String): Double = if (labelString.toDouble > 0.5) 1.0 else 0.0
}

object BinaryLabelParser extends BinaryLabelParser {
/** Gets the default instance of BinaryLabelParser. */
def getInstance(): BinaryLabelParser = this
}

/**
* Label parser for multiclass labels, which converts the input label to double.
*/
class MulticlassLabelParser extends LabelParser {
override def parse(labelString: String): Double = labelString.toDouble
}

object MulticlassLabelParser extends MulticlassLabelParser {
object MulticlassLabelParser extends LabelParser {
/** Gets the default instance of MulticlassLabelParser. */
def getInstance(): MulticlassLabelParser = this
def getInstance(): LabelParser = this

override def parse(labelString: String): Double = labelString.toDouble
}