HyukjinKwon opened a new pull request, #695:
URL: https://github.com/apache/spark-connect-rust/pull/695
### What changes were proposed in this pull request?
The native ML classes of the Python binding (`pyspark.ml.connect`) are being
completed to the full `pyspark.ml` 4.3.0 API on the PyO3 base of #681. This PR
does LogisticRegression, and adds one file per classification family:
- **The classification families' files**:
`crates/pyspark-rs/src/ml/classification_api/` gets one file per family
(logistic, tree, naive_bayes, mlp, fm, one_vs_rest). `classification_api.rs`
declares them and registers each. The other families fill theirs in their own
PRs.
- **`LogisticRegression`**:
- its PyO3 class is now a `native_pymethods!` class, with PySpark's Params
API, `copy`, persistence and `fitMultiple`;
- it has every setter of PySpark's class;
- its `fit` returns the typed `LogisticRegressionModel`.
- **`LogisticRegressionModel`**:
- `coefficients`, `coefficientMatrix`, `intercept` and `interceptVector`;
- `numClasses`, `numFeatures`;
- `predict`, `predictRaw` and `predictProbability` of a vector;
- `evaluate`, `summary` (a property), `hasSummary`, the model setters,
`transform`, `copy`, and save and load.
- **The four summaries**: `LogisticRegressionSummary`,
`LogisticRegressionTrainingSummary`, `BinaryLogisticRegressionSummary` and
`BinaryLogisticRegressionTrainingSummary`, with every member of PySpark's.
- As PySpark's `_summaryCls` does, the fit reads `numClasses` right after
the Fit to choose the binary (two classes or fewer) or the multinomial training
summary. `evaluate` makes the same choice after its evaluate request.
- **Thresholds**: `getThreshold`, `getThresholds`, `setThreshold` and
`setThresholds`, on the estimator and the model, follow PySpark's
`_LogisticRegressionParams`, checked against the official client over Spark
Connect:
- the values and errors are PySpark's, including its `%g` messages;
- over Spark Connect, `clear` does nothing, so neither setter clears the
other param.
- **Tests**:
- `python/tests/_logistic_api_cases.py` holds the cases of the Params API,
the thresholds, the binary and multinomial models, their summaries,
evaluations, transforms and persistence. `tests/golden/logistic_api_cases.json`
holds their results on official PySpark 4.3.0, from
`scripts/capture_logistic_api_cases_golden.py`.
- `test_logistic_api_offline.py` and `test_logistic_api_e2e.py` run the
cases on the native classes and compare with the golden.
- The six classes are in `FULL` of `test_ml_api_offline.py`, which checks
their members, kinds and parameters.
- The mock Connect server of the offline tests gets a queue of responses,
one per execution, so a test can answer a fit's Fit and then its `numClasses`.
This PR is stacked on #691, whose commit it includes until #691 merges: the
shared `model_cases` of the tests takes the DataFrame of the fit there.
### Why are the changes needed?
Before this PR, the native `LogisticRegression` returned the common
`MLModel`, without the model's members, summaries or persistence. This is part
of completing the native ML classes before the 4.3.0 release.
### Does this PR introduce _any_ user-facing change?
Yes, in the Python binding:
`pyspark.ml.connect.classification.LogisticRegression` and its model and
summaries now have the API of `pyspark.ml`'s. `docs/compatibility.md` describes
them.
### How was this patch tested?
- The new cases pass on the native classes and on official PySpark 4.3.0,
offline and live. The golden is captured on official, and two captures are
identical.
- The offline Python suite of the coverage job passes, and so do the live ML
suites against a Spark 4.3.0 Connect server.
- `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]