README (original) (raw)
sparkxgb
Overview
sparkxgb is a sparklyr extension that provides an interface to XGBoost on Spark.
Installation
Development version
You can install the development version of sparkxgb
with:
Example
sparkxgb supports the familiar formula interface for specifying models:
library(sparkxgb)
library(sparklyr)
library(dplyr)
sc <- spark_connect(master = "local")
iris_tbl <- sdf_copy_to(sc, iris)
xgb_model <- xgboost_classifier(
iris_tbl,
Species ~ .,
num_class = 3,
num_round = 50,
max_depth = 4
)
xgb_model %>%
ml_predict(iris_tbl) %>%
select(Species, predicted_label, starts_with("probability_")) %>%
glimpse()
#> Rows: ??
#> Columns: 5
#> Database: spark_connection
#> $ Species <chr> "setosa", "setosa", "setosa", "setosa", "setosa…
#> $ predicted_label <chr> "setosa", "setosa", "setosa", "setosa", "setosa…
#> $ probability_setosa <dbl> 0.9971547, 0.9948581, 0.9968392, 0.9968392, 0.9…
#> $ probability_versicolor <dbl> 0.002097376, 0.003301427, 0.002284616, 0.002284…
#> $ probability_virginica <dbl> 0.0007479066, 0.0018403779, 0.0008762418, 0.000…
It also provides a Pipelines API, which means you can use a xgboost_classifier
or xgboost_regressor
in a pipeline as any Estimator
, and do things like hyperparameter tuning: