# NOT RUN {
# fit a Gradient Boosted Tree Regression Model
df <- createDataFrame(longley)
model <- spark.gbt(df, Employed ~ ., type = "regression", maxDepth = 5, maxBins = 16)
# get the summary of the model
summary(model)
# make predictions
predictions <- predict(model, df)
# save and load the model
path <- "path/to/model"
write.ml(model, path)
savedModel <- read.ml(path)
summary(savedModel)
# fit a Gradient Boosted Tree Classification Model
# label must be binary - Only binary classification is supported for GBT.
df <- createDataFrame(iris[iris$Species != "virginica", ])
model <- spark.gbt(df, Species ~ Petal_Length + Petal_Width, "classification")
# numeric label is also supported
iris2 <- iris[iris$Species != "virginica", ]
iris2$NumericSpecies <- ifelse(iris2$Species == "setosa", 0, 1)
df <- createDataFrame(iris2)
model <- spark.gbt(df, NumericSpecies ~ ., type = "classification")
# }
Run the code above in your browser using DataLab