HyukjinKwon opened a new pull request, #684:
URL: https://github.com/apache/spark-connect-rust/pull/684

   This PR is stacked on #683 (SPARK-61701, the regression models). Please 
review its last commit only: the first one is #683's.
   
   ### What changes were proposed in this pull request?
   
   Part of the native ML parity work. This PR adds the typed clustering models 
to the Rust `spark_connect::ml` API, the same way #683 adds the regression 
ones. Each clustering estimator now fits its typed model, which has the members 
of PySpark 4.3.0's model class:
   
   - **KMeansModel and BisectingKMeansModel**: `cluster_centers()`, 
`num_features`, `predict` (of a cluster index), `compute_cost(&dataset)` of a 
bisecting model, and the training summary of a fit.
     - `cluster_centers()` returns the rows of the server's 
`clusterCenterMatrix`, as PySpark reads them.
   - **GaussianMixtureModel**: `weights`, `gaussians_df()`, `gaussians()`, 
`predict`, `predict_probability`, and the training summary of a fit.
     - `gaussians()` gives a `MultivariateGaussian` for each collected row of 
`gaussiansDF`, as PySpark builds them client-side.
   - **Training summaries**: they implement `ClusteringSummary`.
     - `KMeansSummary` and `BisectingKMeansSummary` add `training_cost`.
     - `GaussianMixtureSummary` adds `probability_col`, `probability` and 
`log_likelihood`.
     - The summary dataset is the model's transform of the training dataset, 
with no params. That is PySpark's default `_summary_dataset`, which runs before 
the fit copies the estimator's params to the model.
   - **LDA models**: `LDAModel`, `LocalLDAModel` and `DistributedLDAModel` 
implement `LDAModelApi` (`describe_topics`, `topics_matrix`, `log_likelihood`, 
`log_perplexity`, `vocab_size`, `estimated_doc_concentration`, 
`is_distributed`).
     - As in PySpark's `LDA._create_model`, a fit is local or distributed 
according to its optimizer. `LDAModel::into_local()` and `into_distributed()` 
return the model as its own class.
     - A distributed model has `to_local()`, `training_log_likelihood`, 
`log_prior` and `get_checkpoint_files`.
   - **Persistence**:
     - Every estimator and model has `load(&session, path)`.
     - `PowerIterationClustering` has the algorithm's uid, and `write()` and 
`load` save and load it as PySpark does: as the params of the server's 
`PowerIterationClusteringWrapper`.
   - **Params**: the 11 classes get generated `ml_params!` rows, as the 
regression ones do, and are converted in `tests/ml_params_table/clustering.rs`.
     - The seed of a fitted `LDAModel` defaults to Spark's default for the 
class of its server-side model.
   - **Docs**: `docs/compatibility.md` has a new section, "Native clustering 
models (Rust API)".
   
   ### Why are the changes needed?
   
   So that the native Rust ML API has the members of pyspark.ml's clustering 
models.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, in the unreleased native Rust ML API, as #683 does for regression.
   - The inherent `fit` of KMeans, BisectingKMeans, GaussianMixture and LDA 
returns the typed model.
   - The members, summaries and persistence above are new.
   - The accessors of `featuresCol` are renamed.
   
   ### How was this patch tested?
   
   - New live tests in `e2e_ml_clustering_api.rs` (4 tests), against a Spark 
4.3.0 Connect server:
     - the KMeans and bisecting members and summaries;
     - the Gaussian mixture members and summary;
     - the local and distributed LDA models, their conversion and persistence;
     - the save and load of PowerIterationClustering.
   - New unit test of the matrix row layout.
   - The existing live and golden suites of the 5 families pass.
   - `tests/ml_params_table.rs` passes with the 11 classes converted. Clippy 
(`-D warnings`) and fmt are clean.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   
   Generated-by: Claude Opus 5.5
   
   This pull request and its description were written by Isaac.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to