Skip to content

Commit

Permalink
Remove duplicate test data in xgboost-predictor-example
Browse files Browse the repository at this point in the history
  • Loading branch information
komiya-atsushi committed May 5, 2017
1 parent 1065bc3 commit 56b2683
Show file tree
Hide file tree
Showing 29 changed files with 40 additions and 5,111 deletions.
1 change: 1 addition & 0 deletions xgboost-predictor-examples/build.gradle
Expand Up @@ -3,5 +3,6 @@ apply plugin: 'scala'
dependencies {
compile project(":xgboost-predictor")
compile project(":xgboost-predictor-spark${scalaSuffix}")
compile project(":xgboost-predictor-test")
compile group: 'org.apache.spark', name: "spark-mllib${scalaSuffix}", version: sparkVersion
}
@@ -1,6 +1,7 @@
package biz.k11i.xgboost.demo;

import biz.k11i.xgboost.Predictor;
import biz.k11i.xgboost.TestHelper;
import biz.k11i.xgboost.util.FVec;

import java.io.File;
Expand All @@ -17,7 +18,7 @@
public class Example {
public static void main(String[] args) throws IOException {
List<SimpleEntry<Integer, FVec>> data = loadData();
Predictor predictor = new Predictor(Example.class.getResourceAsStream("model/binary-logistic.model"));
Predictor predictor = new Predictor(TestHelper.getResourceAsStream("model/gbtree/v47/binary-logistic.model"));

predictAndLogLoss(predictor, data);

Expand Down Expand Up @@ -74,7 +75,7 @@ static void predictLeafIndex(Predictor predictor, List<SimpleEntry<Integer, FVec
static List<SimpleEntry<Integer, FVec>> loadData() throws IOException {
List<SimpleEntry<Integer, FVec>> result = new ArrayList<>();

for (String line : Files.readAllLines(new File(Example.class.getResource("model/agaricus.txt.test").getPath()).toPath(), StandardCharsets.UTF_8)) {
for (String line : Files.readAllLines(new File(TestHelper.getResourcePath("data/agaricus.txt.0.test")).toPath(), StandardCharsets.UTF_8)) {
String[] values = line.split(" ");

Map<Integer, Float> map = new HashMap<>();
Expand Down

This file was deleted.

This file was deleted.

Binary file not shown.
Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

@@ -1,5 +1,6 @@
package biz.k11i.xgboost.spark.demo

import biz.k11i.xgboost.TemporaryFileResource
import biz.k11i.xgboost.spark.model.XGBoostBinaryClassification
import org.apache.spark.SparkConf
import org.apache.spark.ml.evaluation.BinaryClassificationEvaluator
Expand All @@ -10,9 +11,18 @@ object BinaryClassificationExample {
val sparkConf = new SparkConf().setAppName("BinaryClassificationExample")
.setMaster("local")
val sparkSession = SparkSession.builder().config(sparkConf).getOrCreate()
val tempFileResource = new TemporaryFileResource

val modelPath = getResourcePath("/biz/k11i/xgboost/demo/model/spark/agaricus.model.spark")
val testDataPath = getResourcePath("/biz/k11i/xgboost/demo/model/spark/agaricus.txt.test")
try {
run(sparkSession, tempFileResource)
} finally {
tempFileResource.close()
}
}

def run(sparkSession: SparkSession, tempFileResource: TemporaryFileResource) {
val modelPath = tempFileResource.getAsPath("model/gbtree/spark/agaricus.model.spark").toString
val testDataPath = tempFileResource.getAsPath("data/agaricus.txt.1.test").toString

val binaryClassifier = XGBoostBinaryClassification.load(modelPath)
.setRawPredictionCol("rawPrediction")
Expand All @@ -36,6 +46,4 @@ object BinaryClassificationExample {

println(s"AUC: $areaUnderROC")
}

def getResourcePath(name: String): String = getClass.getResource(name).getPath
}
@@ -1,5 +1,6 @@
package biz.k11i.xgboost.spark.demo

import biz.k11i.xgboost.TemporaryFileResource
import biz.k11i.xgboost.spark.model.XGBoostMultiClassification
import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession
Expand All @@ -9,9 +10,18 @@ object MultiClassificationExample {
val sparkConf = new SparkConf().setAppName("MultiClassificationExample")
.setMaster("local")
val sparkSession = SparkSession.builder().config(sparkConf).getOrCreate()
val tempFileResource = new TemporaryFileResource

val modelPath = getResourcePath("/biz/k11i/xgboost/demo/model/spark/iris.model.spark")
val testDataPath = getResourcePath("/biz/k11i/xgboost/demo/model/spark/iris.test")
try {
run(sparkSession, tempFileResource)
} finally {
tempFileResource.close()
}
}

def run(sparkSession: SparkSession, tempFileResource: TemporaryFileResource) {
val modelPath = tempFileResource.getAsPath("model/gbtree/spark/iris.model.spark").toString
val testDataPath = tempFileResource.getAsPath("data/iris.test").toString

val multiclassClassifier = XGBoostMultiClassification.load(modelPath)
.setRawPredictionCol("rawPrediction")
Expand All @@ -22,6 +32,4 @@ object MultiClassificationExample {
.select("rawPrediction", "probability", "prediction", "label")
.show(false)
}

def getResourcePath(name: String): String = getClass.getResource(name).getPath
}
@@ -1,5 +1,6 @@
package biz.k11i.xgboost.spark.demo

import biz.k11i.xgboost.TemporaryFileResource
import biz.k11i.xgboost.spark.model.XGBoostRegression
import org.apache.spark.SparkConf
import org.apache.spark.ml.evaluation.RegressionEvaluator
Expand All @@ -10,9 +11,18 @@ object RegressionExample {
val sparkConf = new SparkConf().setAppName("RegressionExample")
.setMaster("local")
val sparkSession = SparkSession.builder().config(sparkConf).getOrCreate()
val tempFileResource = new TemporaryFileResource

val modelPath = getResourcePath("/biz/k11i/xgboost/demo/model/spark/housing.model.spark")
val testDataPath = getResourcePath("/biz/k11i/xgboost/demo/model/spark/housing.test")
try {
run(sparkSession, tempFileResource)
} finally {
tempFileResource.close()
}
}

def run(sparkSession: SparkSession, tempFileResource: TemporaryFileResource) {
val modelPath = tempFileResource.getAsPath("model/gbtree/spark/housing.model.spark").toString
val testDataPath = tempFileResource.getAsPath("data/housing.test").toString

val regressor = XGBoostRegression.load(modelPath)
val df = sparkSession.sqlContext.read
Expand All @@ -32,6 +42,4 @@ object RegressionExample {

println(s"RMSE: $rmse")
}

def getResourcePath(name: String): String = getClass.getResource(name).getPath
}

0 comments on commit 56b2683

Please sign in to comment.