HyukjinKwon opened a new pull request, #708:
URL: https://github.com/apache/spark-connect-rust/pull/708
### What changes were proposed in this pull request?
This completes the native tree classification classes of the Python binding
(`pyspark.ml.connect.classification`) to the `pyspark.ml` 4.3.0 API, on the
PyO3 base of #681. The classes are DecisionTree, RandomForest and GBT, with the
random forest summaries. The code is in
`crates/pyspark-rs/src/ml/classification_api/tree.rs` and the three estimators'
regions of `crates/pyspark-rs/src/ml.rs`.
- **The estimators**:
- `DecisionTreeClassifier`, `RandomForestClassifier` and `GBTClassifier`
are `native_pymethods!` classes, with PySpark's Params API, `copy`,
persistence, `fitMultiple`, every setter, and the supported-value class
attributes;
- each `fit` returns its typed model.
- **`DecisionTreeClassificationModel`**: `depth`, `numNodes`,
`featureImportances`, `toDebugString`, `numClasses`, `numFeatures`, `predict`,
`predictLeaf`, `predictRaw` and `predictProbability` of a vector, the model
setters, and save and load.
- **`RandomForestClassificationModel` and `GBTClassificationModel`**:
- the ensemble members: `trees`, `treeWeights`, `getNumTrees` (a property,
as in PySpark), `totalNumNodes`, `featureImportances`, `toDebugString` and
`predictLeaf`, plus the classification members;
- `trees` is cached, as PySpark's `functools.cached_property` is, and read
right after the fit and after a load, as PySpark's `_resetUid` does. The random
forest's trees are `DecisionTreeClassificationModel`s; the GBT's are
`DecisionTreeRegressionModel`s of #696;
- GBT has `evaluateEachIteration`.
- **The random forest summaries**:
- the training summary is made at the fit, binary or multiclass by the
`numClasses` that the fit reads, as PySpark's `_summaryCls` does. A fit
therefore sends the Fit, `numClasses`, then `trees`, as PySpark does;
- `evaluate` makes the same choice;
- the four classes have every member of PySpark's.
- **OneVsRest**: a OneVsRest of a tree classifier now gives typed tree
submodels in `OneVsRestModel.models`, as #706 does for the other classifiers.
The native fit helpers that only these estimators used are removed.
- **Tests**:
- `python/tests/_tree_api_cases.py` holds the cases of the Params API, the
models, summaries, evaluations, transforms and persistence.
`tests/golden/tree_api_cases.json` holds their results on official PySpark
4.3.0, from `scripts/capture_tree_api_cases_golden.py`.
- `test_tree_api_offline.py` and `test_tree_api_e2e.py` run the cases on
the native classes and compare with the golden. The ten classes are in `FULL`
of `test_ml_api_offline.py`.
- The OneVsRest cases of `_misc_api_cases.py` gain the three tree
classifiers.
- The offline mocks answer a random forest fit's `numClasses` and `trees`
(`_FETCHES_AFTER_FIT`).
- The DataFrame cases with floats round them to 9 digits, against the
platforms' last-bit drift.
### Why are the changes needed?
Before this PR, the native tree classifiers fit and transformed but returned
the common `MLModel`, without the tree members, summaries or persistence of
`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, in the Python binding. The native tree classifiers, their models and
the random forest summaries now have the API of `pyspark.ml`'s, and so does a
OneVsRest of a tree classifier. `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 goldens are captured on official, and two captures are
identical.
- The offline Python suite of the coverage job passes (5246 passed, 0
failed), and so do the live ML suites against a Spark 4.3.0 Connect server (390
passed, 0 failed).
- `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]