Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions examples/src/main/r/ml/ml.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,16 @@ unlink(modelPath)

############################ fit models with spark.lapply #####################################
# Perform distributed training of multiple models with spark.lapply
costs <- exp(seq(from = log(1), to = log(1000), length.out = 5))
train <- function(cost) {
stopifnot(requireNamespace("e1071", quietly = TRUE))
model <- e1071::svm(Species ~ ., data = iris, cost = cost)
summary(model)
algorithms <- c("Hartigan-Wong", "Lloyd", "MacQueen")
train <- function(algorithm) {
model <- kmeans(x = iris[1:4], centers = 3, algorithm = algorithm)
model$withinss
}

model.summaries <- spark.lapply(costs, train)
model.withinss <- spark.lapply(algorithms, train)

# Print the summary of each model
print(model.summaries)
# Print the within-cluster sum of squares for each model
print(model.withinss)

# Stop the SparkSession now
sparkR.session.stop()