@@ -175,7 +175,8 @@ class LinearSVC @Since("2.2.0") (
175175 instr.logParams(this , labelCol, weightCol, featuresCol, predictionCol, rawPredictionCol,
176176 regParam, maxIter, fitIntercept, tol, standardization, threshold, aggregationDepth, blockSize)
177177
178- val instances = extractInstances(dataset).setName(" training instances" )
178+ val instances = extractInstances(dataset)
179+ .setName(" training instances" )
179180
180181 val (summarizer, labelSummarizer) = if ($(blockSize) == 1 ) {
181182 if (dataset.storageLevel == StorageLevel .NONE ) {
@@ -201,7 +202,7 @@ class LinearSVC @Since("2.2.0") (
201202 val sparsity = 1 - summarizer.numNonzeros.toArray.map(_ * scale).sum
202203 instr.logNamedValue(" sparsity" , sparsity.toString)
203204 if (sparsity > 0.5 ) {
204- logWarning(s " sparsity of input dataset is $sparsity, " +
205+ instr. logWarning(s " sparsity of input dataset is $sparsity, " +
205206 s " which may hurt performance in high-level BLAS. " )
206207 }
207208 }
@@ -242,7 +243,7 @@ class LinearSVC @Since("2.2.0") (
242243 Note that the intercept in scaled space and original space is the same;
243244 as a result, no scaling is needed.
244245 */
245- val rawCoefficients = if ($(blockSize) == 1 ) {
246+ val ( rawCoefficients, objectiveHistory) = if ($(blockSize) == 1 ) {
246247 trainOnRows(instances, featuresStd, regularization, optimizer)
247248 } else {
248249 trainOnBlocks(instances, featuresStd, regularization, optimizer)
@@ -266,7 +267,7 @@ class LinearSVC @Since("2.2.0") (
266267 instances : RDD [Instance ],
267268 featuresStd : Array [Double ],
268269 regularization : Option [L2Regularization ],
269- optimizer : BreezeOWLQN [Int , BDV [Double ]]): Array [Double ] = {
270+ optimizer : BreezeOWLQN [Int , BDV [Double ]]): ( Array [Double ], Array [ Double ]) = {
270271 val numFeatures = featuresStd.length
271272 val numFeaturesPlusIntercept = if ($(fitIntercept)) numFeatures + 1 else numFeatures
272273
@@ -278,22 +279,22 @@ class LinearSVC @Since("2.2.0") (
278279 val states = optimizer.iterations(new CachedDiffFunction (costFun),
279280 Vectors .zeros(numFeaturesPlusIntercept).asBreeze.toDenseVector)
280281
281- val scaledObjectiveHistory = mutable.ArrayBuilder .make[Double ]
282+ val arrayBuilder = mutable.ArrayBuilder .make[Double ]
282283 var state : optimizer.State = null
283284 while (states.hasNext) {
284285 state = states.next()
285- scaledObjectiveHistory += state.adjustedValue
286+ arrayBuilder += state.adjustedValue
286287 }
287288 bcFeaturesStd.destroy()
288289
289- if (state == null ) null else state.x.toArray
290+ ( if (state == null ) null else state.x.toArray, arrayBuilder.result)
290291 }
291292
292293 private def trainOnBlocks (
293294 instances : RDD [Instance ],
294295 featuresStd : Array [Double ],
295296 regularization : Option [L2Regularization ],
296- optimizer : BreezeOWLQN [Int , BDV [Double ]]): Array [Double ] = {
297+ optimizer : BreezeOWLQN [Int , BDV [Double ]]): ( Array [Double ], Array [ Double ]) = {
297298 val numFeatures = featuresStd.length
298299 val numFeaturesPlusIntercept = if ($(fitIntercept)) numFeatures + 1 else numFeatures
299300
@@ -321,16 +322,16 @@ class LinearSVC @Since("2.2.0") (
321322 val states = optimizer.iterations(new CachedDiffFunction (costFun),
322323 Vectors .zeros(numFeaturesPlusIntercept).asBreeze.toDenseVector)
323324
324- val scaledObjectiveHistory = mutable.ArrayBuilder .make[Double ]
325+ val arrayBuilder = mutable.ArrayBuilder .make[Double ]
325326 var state : optimizer.State = null
326327 while (states.hasNext) {
327328 state = states.next()
328- scaledObjectiveHistory += state.adjustedValue
329+ arrayBuilder += state.adjustedValue
329330 }
330331 blocks.unpersist()
331332 bcFeaturesStd.destroy()
332333
333- if (state == null ) null else state.x.toArray
334+ ( if (state == null ) null else state.x.toArray, arrayBuilder.result)
334335 }
335336}
336337
0 commit comments