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

   ### What changes were proposed in this pull request?
   
   OneVsRest and OneVsRestModel could not be saved or loaded natively. The 
native estimator's `write` raised `CONNECT_ML.UNSUPPORTED_EXCEPTION`, since the 
server has no OneVsRest operator. PySpark saves both with its own client-side 
writers: `OneVsRestWriter`, `OneVsRestModelWriter` and 
`_OneVsRestSharedReadWrite` in `pyspark/ml/classification.py`.
   
   This PR saves and loads them in that format, in both the Rust API and the 
Python binding, on the persistence base of the native Pipeline (#690, #698, 
#700).
   
   - **The format**:
     - the DefaultParamsWriter metadata of class 
`pyspark.ml.classification.OneVsRest`, with its params except `classifier`;
     - the classifier at `<path>/classifier`;
     - for the model, `numClasses` in the metadata and each class's model at 
`<path>/model_<i>`.
   - **Rust API** 
(`crates/spark-connect/src/ml/classification_api/one_vs_rest.rs`, `ml.rs`, 
`meta.rs`, `validators.rs`):
     - `OneVsRest::write().save(path)` and `OneVsRest::load(session, path)`, 
and the same for OneVsRestModel, through `MlWriter::meta` and `MetaSave`;
     - the classifier is loaded as its typed estimator, by its saved class;
     - `load_stage` loads both classes, so a Pipeline or a validator can hold 
them;
     - `nested_uids` walks into a OneVsRest's classifier and a OneVsRestModel's 
classifier and models, as PySpark's `MetaAlgorithmReadWrite.getAllNestedStages` 
does;
     - `OneVsRest::apply_param_map` forwards the classifier's params, as 
PySpark's `OneVsRest.copy` does.
   - **Python binding** 
(`crates/pyspark-rs/src/ml/classification_api/one_vs_rest.rs`, `ml.rs`):
     - `write`/`save`/`read`/`load` of the native OneVsRest and OneVsRestModel 
use the Python-format writer and reader of the base;
     - `copy(extra)` forwards the map into the classifier, as PySpark's does, 
so `fit(params)` and a validator's grid over the classifier's params work;
     - `python/pyspark/ml/connect/__init__.py` registers the two native classes 
as virtual subclasses of the vendored `pyspark.ml.classification.OneVsRest` and 
`OneVsRestModel`, so PySpark's validators and `MetaAlgorithmReadWrite` see the 
classifier.
   
   ### Why are the changes needed?
   
   Saving and loading a OneVsRest, and a validator or Pipeline over one, is 
part of the `pyspark.ml` API. It is the last gap of the native classification 
classes before the 4.3.0 release.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes. The native OneVsRest and OneVsRestModel can be saved and loaded, in the 
Rust API and in the Python binding, and official PySpark loads what they save 
and the reverse. `docs/compatibility.md` describes it.
   
   ### How was this patch tested?
   
   - Interop, live against a Spark 4.3.0 Connect server, both ways, for the 
Python binding and the Rust API:
     - what this client saves, official PySpark loads, and the reverse, with 
identical uids, classes, params, submodels and predictions;
     - a CrossValidator over OneVsRest(LogisticRegression) with a grid, both 
ways, with equal average metrics and predictions;
     - the metadata files equal official's except timestamps and uids.
   - New live cases in `_misc_api_cases.py`: persistence, a validator, and the 
classifier params of `copy`. Their golden is captured on official PySpark 
4.3.0. New Rust e2e tests in `e2e_classification_misc_api.rs`, and offline unit 
tests: the param map of the metadata, the typed classifier, the forwarding of 
`apply_param_map`, and the nested uids.
   - The crate's offline tests pass, and so do the offline Python suite of the 
coverage job and the live suites.
   - `cargo fmt --check`, `cargo +1.100.0 clippy --workspace --all-targets -- 
-D warnings` and ruff 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