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

   ### What changes were proposed in this pull request?
   
   This completes the native LogisticRegression and LinearSVC classes of the 
Rust client (`spark_connect::ml`) to the `pyspark.ml` 4.3.0 API. It builds on 
the server-side objects of #667 and the shared traits and `ml_params!` of #680. 
The code is in 
`crates/spark-connect/src/ml/classification_api/{logistic,linear_svc}.rs`.
   
   - `LogisticRegressionModel` and `LinearSVCModel`:
     - `coefficients`, `intercept`, `numClasses` and `numFeatures`;
     - single-vector `predict` and `predictRaw`, plus `predictProbability` for 
LR;
     - for LR, also `coefficientMatrix` and `interceptVector`. `coefficients()` 
and `intercept()` raise the server's error on a multinomial model, as PySpark 
does;
     - `load`, and the model setters of the transform params.
   - Training summaries:
     - `summary()` returns the training summary of a fitted model, and 
`has_summary()` is client side, as in PySpark;
     - the LR summary is the binary one for at most two classes. As in PySpark, 
that choice is made at the fit, which sends `numClasses` right after the Fit;
     - `evaluate(&df)` returns the summary of a dataset, making the 
binary/multiclass choice again for LR;
     - the summaries implement the shared classification, binary and training 
summary traits, so they have the curve DataFrames (`roc`, `pr` and the 
by-threshold ones) and `objective_history` / `total_iterations`;
     - as in PySpark, the summary dataset is the training DataFrame.
   - Estimators: the typed `fit`, `fit_multiple` (one model per param map) and 
`load`.
   - Params:
     - the accessors of the four classes are generated with `ml_params!` from 
PySpark's param table, and replace the hand-written ones;
     - `features_col` / `set_features_col` are PySpark's names. 
`LogisticRegression::feature_col` and `set_feature_col`, the names that v4.2.0 
shipped, stay as deprecated aliases;
     - the bounds on the coefficients (`toMatrix`) are written by hand.
   - LR thresholds: `threshold()`, `thresholds()`, `set_threshold` and 
`set_thresholds` follow PySpark's `_LogisticRegressionParams`, as checked 
against the official client over Spark Connect:
     - the getters check that the two params agree to 1e-5, and `threshold()` 
requires exactly two thresholds;
     - the messages are PySpark's, with its `%g` formatting;
     - each setter leaves the other param set. Over Spark Connect, the `clear` 
of `pyspark.ml` does nothing, so a disagreement raises the getters' error.
   
   The Python binding is unchanged in this PR. The PyO3 classes come later, on 
the Params API base of #681.
   
   ### 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:
   
   - The typed models and their members, the summaries, `fit_multiple` and 
`load`.
   - The param accessors under PySpark's names.
   - `LogisticRegression::feature_col` and `set_feature_col` of v4.2.0 keep 
working as deprecated aliases of `features_col` and `set_features_col`.
   
   `docs/compatibility.md` describes both classes.
   
   ### How was this patch tested?
   
   - An offline golden test (`lr_svc_api_golden.rs`) replays the commands and 
results of official PySpark 4.3.0 (`tests/golden/classification_*.json`) 
through the shared replay server. It covers the models, the summaries and 
persistence, and checks each call's commands and values.
   - `lr_svc_params.rs` checks the defaults, the threshold cases (values and 
messages, as the official client gives them), the model setters on a loaded 
model, and the deprecated aliases.
   - A live test (`e2e_lr_svc_api.rs`) checks the golden values on the golden 
datasets, and `fit_multiple`.
   - 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]

Reply via email to