所以最近我一直在使用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")
您可以尝试使用spark-sklearn来分发xgboost的python或scikit-learn版本,但该分发与xgboost4j分发不同。我听说databricks上的xgboost4j的pyspark api即将推出,敬请期待。
顺便说一句,相关的拉动请求可以找到here