用scala语言交换两个变量

时间:2016-11-21 22:09:59

标签: scala if-statement scala-collections scalatest

val numClasses = 5
val categoricalFeaturesInfo = Map[Int, Int]()
val impurity = "gini"
val maxDepth = 0
val maxBins = 32
val greaccuracy = 0
for( maxDepth <- 0 to 30){
val model = DecisionTree.trainClassifier(trainData, numClasses,  categoricalFeaturesInfo, impurity, maxDepth, maxBins)
val metrics = getMetrics(model, cvData)
val accuracy = metrics.precision
if (accuracy >  greaccuracy){
greaccuracy =  accuracy
}
}
println("Accuracy = "+greaccuracy)

请任何帮助  错误:重新分配给val                greaccuracy =准确性                            ^

1 个答案:

答案 0 :(得分:2)

val是不可变的变量,一旦设置就无法更改它们。这是设计的。 var另一方面你可以改变它们。