使用Python的Databricks中的XGBoost

时间:2019-02-07 19:38:48

标签: pyspark xgboost databricks

因此,最近我一直在研究Mlib Databricks集群,并发现根据文档XGBoost可用于我的集群版本(5.1)。该集群运行的是Python 2。

我感到XGBoost4J仅适用于Scala和Java。 所以我的问题是:如何在不丢失分发功能的情况下将xgboost模块导入此环境?

下面是我的代码示例

from pyspark.ml import Pipeline
from pyspark.ml.feature import StringIndexer
from pyspark.ml.feature import VectorAssembler
import xgboost as xgb # Throws error because module is not installed and it should

# Transform class to classIndex to make xgboost happy
stringIndexer = StringIndexer(inputCol="species", outputCol="species_index").fit(newInput)
labelTransformed = stringIndexer.transform(newInput).drop("species")

# Compose feature columns as vectors
vectorCols = ["sepal_length", "sepal_width", "petal_length", "petal_width", "species_index"]
vectorAssembler = VectorAssembler(inputCols=vectorCols, outputCol="features")
xgbInput = vectorAssembler.transform(labelTransformed).select("features", "species_index")

2 个答案:

答案 0 :(得分:1)

您可以尝试使用spark-sklearn分发xgboost的python或scikit-learn版本,但是该分发与xgboost4j分发不同。我听说databricks上的xgboost4j的pyspark API即将推出,请继续关注。

答案 1 :(得分:1)

顺便提一下,相关的拉取请求here