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

   ### What changes were proposed in this pull request?
   
   This completes the native tree classification classes of the Rust client 
(`spark_connect::ml`) to the `pyspark.ml` 4.3.0 API: DecisionTree, RandomForest 
and GBT. It builds on the server-side objects of #667, the shared 
classification and tree traits and `ml_params!` of #680, and the regression 
tree model of #683. The code is in 
`crates/spark-connect/src/ml/classification_api/tree.rs`.
   
   - The tree members, from the shared `DecisionTreeModel` / 
`TreeEnsembleModel` traits:
     - `depth`, `num_nodes`, `to_debug_string`, `feature_importances` and 
`predict_leaf`;
     - for the ensembles, also `trees`, `tree_weights`, `get_num_trees` and 
`total_num_nodes`.
   - The classification and prediction members:
     - `num_classes`, `num_features`;
     - single-vector `predict`, `predict_raw` and `predict_probability`.
   - The supported-value lists of PySpark's client side: impurities, feature 
subset strategies, and loss types for GBT.
   - `RandomForestClassificationModel::trees` returns decision tree 
classification models. `GBTClassificationModel::trees` returns regression tree 
models (`DecisionTreeRegressionModel`), as in PySpark. Each tree is its own 
server-side object.
   - `GBTClassificationModel::evaluate_each_iteration(&df)`.
   - RandomForest training summary:
     - `summary()` returns the binary or the multiclass training summary, 
chosen by `numClasses`, and `has_summary()` is client side;
     - `evaluate(&df)` returns the summary of a dataset;
     - as in PySpark, the summary dataset is the training DataFrame;
     - the four random forest summary classes implement the shared 
classification, binary and training summary traits.
   - Each estimator's `fit` returns its typed model, and every estimator and 
model has `load`.
   - Params:
     - the setters and getters of all six 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. None of these 
classes shipped in v4.2.0;
     - `seed()` returns the server's default (the Java hash of the JVM class 
name) when it is unset.
     - The completeness test lists the six classes as converted.
   
   Unlike PySpark, the Rust fit does not fetch `numClasses` and the trees up 
front. `summary()` and `trees()` fetch them when asked. The Python binding is 
unchanged in this PR. Its PyO3 classes come on the Params API base of #681.
   
   ### Why are the changes needed?
   
   The native classes could fit and transform, but they had no tree inspection, 
feature importances, 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, all relative to the unreleased master:
   
   - The typed models and their members, the random forest summaries, and 
`load`.
   - The param accessors under PySpark's names.
   
   `docs/compatibility.md` describes the three classifiers.
   
   ### How was this patch tested?
   
   - Offline golden tests (`classification_api/tree/golden_tests.rs`) check 
each accessor's request against the commands of official PySpark 4.3.0 
(`tests/golden/classification_*.json`), and decode each recorded result into 
its value.
   - A live test (`e2e_tree_classification_api.rs`) fits on the golden datasets 
in one partition. It compares the decision tree, the random forest (trees, 
importances, weights, node counts, predictions and both summaries) and the GBT 
values with the golden within 1e-9 relative. It also checks GBT's 
`evaluateEachIteration` and a save and load.
   - The existing decision tree, random forest and GBT tests pass with the 
typed models.
   - The crate's offline tests pass, and so do the live tests against a Spark 
4.3.0 Connect server.
   - The offline Python suite of the coverage job passes with the drop-in built 
from this branch.
   - `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