2016-11-21 60 views
-1
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 =準確性 ^交換兩個可變由Scala語言

+4

[在scala中使用def,val和var]可能的重複(http://stackoverflow.com/questions/4437373/use-of-def-val-and-var-in-scala) –

回答

2

VAL是不可改變的變量,一旦設置你不能改變它們。這是由設計。另一方面,你可以改變它們。