HyukjinKwon opened a new pull request, #686:
URL: https://github.com/apache/spark-connect-rust/pull/686
### What changes were proposed in this pull request?
This completes four native classification families of the Rust client
(`spark_connect::ml`) to the `pyspark.ml` 4.3.0 API: NaiveBayes,
MultilayerPerceptron, FM and OneVsRest. It builds on the server-side objects of
#667 and the shared traits and `ml_params!` of #680. Each family's code is in
its own file under `crates/spark-connect/src/ml/classification_api/`.
- `NaiveBayesModel`:
- `pi`, `theta` and `sigma`;
- single-vector `predict`, `predictRaw` and `predictProbability`;
- `numClasses`, `numFeatures`, and `load`.
- `MultilayerPerceptronClassificationModel`:
- `weights`, the same prediction and classification members, and `load`;
- `summary()` and `has_summary()` for the training summary, which only a
fitted model has, as in PySpark;
- `evaluate(&df)`.
- `FMClassificationModel`:
- `factors`, `linear` and `intercept`, the same prediction members, and
`load`;
- the binary training summary, with its ROC, PR and by-threshold
DataFrames;
- `evaluate(&df)`.
- `OneVsRestModel`:
- `models()` returns each binary submodel as its own typed model
(`SubModel`, one variant per native classifier);
- `classifier()` returns the classifier it was fitted with.
- Each estimator's `fit` returns its typed model. As in PySpark, the summary
dataset of a training summary is the training DataFrame.
- Params: the setters and getters of all eight classes are generated with
`ml_params!` from PySpark's param table (`scripts/gen_rust_params_table.py`),
and replace the hand-written accessors.
- The names follow PySpark: `features_col` / `set_features_col` replace
`feature_col` / `set_feature_col`. None of these classes shipped in v4.2.0.
- The completeness test (`tests/ml_params_table.rs`) now lists the eight
classes as converted.
- The Python binding is unchanged in this PR. The PyO3 classes come later,
on the Params API base of #681.
OneVsRest persistence is not included. Its writer runs on the client in
PySpark, together with the other meta-estimators.
### Why are the changes needed?
The native classes could fit and transform, but they had no model
inspection, summaries, single-vector prediction or persistence. Without those,
they cannot replace `pyspark.ml`. This is part of completing the native ML
classes before the 4.3.0 release.
### Does this PR introduce _any_ user-facing change?
Yes, for the Rust API, all relative to the unreleased master:
- The typed models and their members, the summaries and `load`.
- The param accessors renamed to PySpark's names (`features_col`).
`docs/compatibility.md` describes each family.
### How was this patch tested?
- An offline golden test (`classification_misc_api_golden.rs`) replays the
commands and results of official PySpark 4.3.0
(`tests/golden/classification_*.json`) through the shared replay server. It
checks every member's request and value, and the fit, save and load commands.
- A live test (`e2e_classification_misc_api.rs`) fits on the golden datasets
and compares each value with the golden within 1e-9 relative.
- The existing NaiveBayes and remaining-classifier tests pass with the
renamed accessors.
- The crate's offline tests pass, and so do the live tests against a Spark
4.3.0 Connect server.
- `cargo fmt --check` and `cargo +1.100.0 clippy --workspace --all-targets
-- -D warnings` 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]