-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
3,653 additions
and
2,390 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
pmml-sparkml-xgboost/src/main/java/org/jpmml/sparkml/xgboost/HasSparkMLXGBoostOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright (c) 2023 Villu Ruusmann | ||
* | ||
* This file is part of JPMML-SparkML | ||
* | ||
* JPMML-SparkML is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* JPMML-SparkML is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with JPMML-SparkML. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package org.jpmml.sparkml.xgboost; | ||
|
||
import org.jpmml.sparkml.HasSparkMLOptions; | ||
import org.jpmml.xgboost.HasXGBoostOptions; | ||
|
||
public interface HasSparkMLXGBoostOptions extends HasSparkMLOptions, HasXGBoostOptions { | ||
|
||
String OPTION_INPUT_FLOAT = "input_float"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
pmml-sparkml-xgboost/src/test/resources/XGBoostHousing.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import java.io.File | ||
|
||
import ml.dmlc.xgboost4j.scala.spark.{TrackerConf, XGBoostRegressor} | ||
import org.apache.spark.ml.Pipeline | ||
import org.apache.spark.ml.feature._ | ||
import org.apache.spark.sql.types.FloatType | ||
import org.jpmml.sparkml.{DatasetUtil, PipelineModelUtil} | ||
|
||
var df = DatasetUtil.loadCsv(spark, new File("csv/Housing.csv")) | ||
|
||
DatasetUtil.storeSchema(df, new File("schema/Housing.json")) | ||
|
||
val cat_cols = Array("CHAS", "RAD", "TAX") | ||
val cont_cols = Array("CRIM", "ZN", "INDUS", "NOX", "RM", "AGE", "DIS", "PTRATIO", "B", "LSTAT") | ||
|
||
val assembler = new VectorAssembler().setInputCols(cat_cols ++ cont_cols).setOutputCol("featureVector") | ||
val indexer = new VectorIndexer().setInputCol(assembler.getOutputCol).setOutputCol("catFeatureVector") | ||
|
||
val trackerConf = TrackerConf(0, "scala") | ||
val regressor = new XGBoostRegressor(Map("objective" -> "reg:squarederror", "num_round" -> 101, "num_workers" -> 1, "tracker_conf" -> trackerConf)).setMissing(-1).setLabelCol("MEDV").setFeaturesCol(indexer.getOutputCol) | ||
|
||
val pipeline = new Pipeline().setStages(Array(assembler, indexer, regressor)) | ||
val pipelineModel = pipeline.fit(df) | ||
|
||
PipelineModelUtil.storeZip(pipelineModel, new File("pipeline/XGBoostHousing.zip")) | ||
|
||
var xgbDf = pipelineModel.transform(df) | ||
xgbDf = xgbDf.selectExpr("prediction as MEDV") | ||
xgbDf = DatasetUtil.castColumn(xgbDf, "MEDV", FloatType) | ||
|
||
DatasetUtil.storeCsv(xgbDf, new File("csv/XGBoostHousing.csv")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.