add test cases for Scala API

This commit is contained in:
CodingCat
2016-03-02 15:24:13 -05:00
parent f8fff6c6fc
commit 5e309f1ce8
10 changed files with 225 additions and 29 deletions

View File

@@ -18,7 +18,7 @@ package ml.dmlc.xgboost4j.scala
import ml.dmlc.xgboost4j.{DMatrix => JDMatrix, XGBoostError}
class DMatrix private(private[scala] val jDMatrix: JDMatrix) {
class DMatrix private[scala](private[scala] val jDMatrix: JDMatrix) {
/**
* init DMatrix from file (svmlight format)

View File

@@ -16,7 +16,7 @@
package ml.dmlc.xgboost4j.scala
import ml.dmlc.xgboost4j.IEvaluation
import ml.dmlc.xgboost4j.{DMatrix => JDMatrix, IEvaluation}
trait EvalTrait extends IEvaluation {
@@ -35,4 +35,8 @@ trait EvalTrait extends IEvaluation {
* @return result of the metric
*/
def eval(predicts: Array[Array[Float]], dmat: DMatrix): Float
private[scala] def eval(predicts: Array[Array[Float]], jdmat: JDMatrix): Float = {
eval(predicts, new DMatrix(jdmat))
}
}

View File

@@ -16,7 +16,9 @@
package ml.dmlc.xgboost4j.scala
import ml.dmlc.xgboost4j.IObjective
import scala.collection.JavaConverters._
import ml.dmlc.xgboost4j.{DMatrix => JDMatrix, IObjective}
trait ObjectiveTrait extends IObjective {
/**
@@ -26,5 +28,10 @@ trait ObjectiveTrait extends IObjective {
* @param dtrain training data
* @return List with two float array, correspond to first order grad and second order grad
*/
def getGradient(predicts: Array[Array[Float]], dtrain: DMatrix): java.util.List[Array[Float]]
def getGradient(predicts: Array[Array[Float]], dtrain: DMatrix): List[Array[Float]]
private[scala] def getGradient(predicts: Array[Array[Float]], dtrain: JDMatrix):
java.util.List[Array[Float]] = {
getGradient(predicts, new DMatrix(dtrain)).asJava
}
}