Package smile.spark
package smile.spark
Integration between SMILE machine learning and Apache Spark.
This package bridges the local, in-memory SMILE data model with the distributed Spark SQL and Spark ML abstractions. It is organized around four capabilities:
- DataFrame conversion — move data between a Spark SQL
Dataset<Row>and a SMILEDataFramein either direction, so data prepared in Spark can be fed to SMILE algorithms and SMILE results can be pushed back to Spark. - Spark ML pipeline integration — drop any SMILE classifier or
regression model into a Spark ML
Pipelinethrough theEstimator/Modelpairs in this package. - Distributed hyperparameter optimization — evaluate a list of hyperparameter configurations in parallel across Spark executors.
- Type mapping — translate Spark SQL types to and from SMILE data types, including nullability, arrays, structs, and Spark ML vectors.
Key classes
SparkDataFrames- Converts a Spark
Dataset<Row>into a SMILEDataFrame, either by collecting it to the driver or by streaming it lazily asTuples. SmileDataFrames- Converts a SMILE
DataFrameinto a distributed SparkDataset<Row>. SparkRowTuple- Adapts a Spark
Rowto the SMILETupleinterface, delegating field access to the underlying row. DataTypeUtils- Bidirectional mapping between Spark SQL data types and SMILE data types, used to translate schemas during conversion.
SmileClassifier/SmileClassificationModel- A Spark ML
Estimator/Modelpair that trains and applies any SMILEClassifierfrom a lambdaTrainer. SmileRegressor/SmileRegressionModel- The regression counterpart, wrapping any SMILE
Regressionmodel as a Spark MLRegressorand its fitted model. SparkHPO- Distributed cross-validation and train/test hyperparameter search for classification and regression, parallelized over Spark executors.
Quick start
// Spark DataFrame -> SMILE DataFrame
DataFrame smileDf = SparkDataFrames.toSmile(sparkDf);
// Wrap any SMILE classifier as a Spark ML estimator and fit it
SmileClassifier classifier = new SmileClassifier()
.setTrainer((x, y) -> smile.classification.KNN.fit(x, y, 5))
.setFeaturesCol("features")
.setLabelCol("label");
SmileClassificationModel model = classifier.fit(trainingData);
Dataset<Row> predictions = model.transform(testData);
Dependencies
The module depends on smile-core and on the Spark libraries
(spark-core, spark-sql, spark-mllib, and
hadoop-common), which are provided and expected to be
supplied by the Spark runtime environment. All operations require an active
SparkSession.
-
ClassDescriptionBidirectional conversion utilities between Apache Spark SQL data types and SMILE data types.A Spark ML
Modelproduced bySmileClassifier.A Spark MLEstimatorthat trains a SMILE classification model.Functional interface for training a SMILE classifier on double feature arrays.A Spark MLModelproduced bySmileRegressor.A Spark MLEstimatorthat trains a SMILE regression model.Functional interface for training a SMILE regression model on double feature arrays.Distributed hyperparameter optimization (HPO) across an Apache Spark cluster.SparkHPO.ClassificationTrainer<T, M extends Classifier<T>>Functional interface for training a parameterized classifier on array samples.Functional interface for training a parameterized DataFrame classifier.Functional interface for training a parameterized DataFrame regression model.SparkHPO.RegressionTrainer<T, M extends Regression<T>>Functional interface for training a parameterized regression model on array samples.An adapter wrapping an Apache SparkRowas a SMILETuple.