HyukjinKwon opened a new pull request, #680:
URL: https://github.com/apache/spark-connect-rust/pull/680
### What changes were proposed in this pull request?
The native ML layer of the Rust client is being completed to the
`pyspark.ml` 4.3.0 surface. This PR adds the shared pieces that the
classification, regression, clustering and feature areas build on, over the
server-side objects of #667.
**Model and summary traits** (`ml/classification_api`, `ml/tree_api.rs`).
Each member has a default method: a fetch of the object, as PySpark's
`_call_java` of it.
- `ClassificationModel: PredictionModel` (`num_classes`, `predict_raw`) and
`ProbabilisticClassificationModel` (`predict_probability`), as
`_JavaClassificationModel` and `_JavaProbabilisticClassificationModel`.
- `MlSummary` (the target of a summary) and `TrainingSummary`
(`objective_history`, `total_iterations`), which the regression summaries use
too.
- `ClassificationSummary` and `BinaryClassificationSummary`, with every
member of `_ClassificationSummary` and `_BinaryClassificationSummary`.
DataFrame members such as `roc` and `pr` are attribute relations of the summary.
- `DecisionTreeModel` and `TreeEnsembleModel { type Tree }`, the members of
`_DecisionTreeModel` and `_TreeEnsembleModel` that the classification and
regression trees share. An ensemble names its tree model type, which it builds
of each id of the `trees` result.
- One empty file per classification family, for the family PRs.
**Param accessors.**
- `ml_params!` generates the typed builder setters and the getters of a
class's params, and a `PARAM_NAMES` constant per class. It moves from the
feature module (`feature_params!` stays as an alias) to `ml.rs`, so every area
can use it, and gains getter-only rows for model params that have no setter in
`pyspark.ml`.
- `scripts/gen_rust_params_table.py <Class>...` prints a class's rows from
`tests/golden/ml_api.json` (#669). The converters map to Rust types, and a
param with a default gets a getter returning `T`, else `Option<T>`. A setter
row appears only where `pyspark.ml` has the `setX` member. `outputCol` defaults
to the uid plus `__output`. `seed` defaults to the value the server uses when
no seed is sent: Java's `String.hashCode` of the JVM class name, as `HasSeed`
does, through a `java_string_hash` const fn. Rows are wrapped to 100 columns.
- `tests/ml_params_table.rs` checks each converted class's `PARAM_NAMES`
against PySpark's params in the golden. Every golden class must be either
converted or excluded with a reason ("pending: <area>" or "no Rust type: ..."),
in a table per area under `tests/ml_params_table/`, so each area's PR edits
only its own table. 34 feature classes are converted today, and the area PRs
convert the rest.
### Why are the changes needed?
The area PRs (classification, regression and clustering, feature) need one
set of traits and one generated param surface, so that the Rust API matches
`pyspark.ml` member for member, and a gate that proves no param is missing.
### Does this PR introduce _any_ user-facing change?
Yes, new public traits in `spark_connect::ml`. The feature stages also get a
`PARAM_NAMES` constant. Their accessors are unchanged.
### How was this patch tested?
- The completeness test passes against the golden of #669. Its failure modes
were checked by hand: a class in neither table, a class listed twice, a class
whose params differ, and a duplicate `ml_params!` block.
- A unit test of `java_string_hash` against Java's values.
- The Rust lib tests (692), the feature golden and e2e suites, the
`--no-run` builds and the drop-in build pass.
- `cargo fmt`, the stub audit, clippy 1.100.0 with `-D warnings` and ruff
pass.
- The area branches built on it pass their offline golden and live tests
against Spark 4.3.0.
### 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]