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

   ### What changes were proposed in this pull request?
   
   Part of the native ML parity work. This PR adds the typed regression models 
to the Rust `spark_connect::ml` API, built on the server-side objects of #667 
(SPARK-61688) and the shared traits and `ml_params!` of #680 (SPARK-61691). 
Each regression estimator now fits its typed model, which has the members of 
PySpark 4.3.0's model class. Each member is a fetch of the model's server-side 
object, the way PySpark's `_call_java` reads it.
   
   - **Typed fit**:
     - `LinearRegression::fit(&mut self, df)` returns a 
`LinearRegressionModel`, and so on for the other 7 estimators.
     - The `Estimator` trait's `fit` boxes the model, and `Box<dyn 
Model>::downcast_ref` reaches the concrete type.
   - **Models**:
     - `LinearRegressionModel` and `GeneralizedLinearRegressionModel`: 
`coefficients`, `intercept` (and `scale` of a linear regression), 
`evaluate(&dataset)`, and `has_summary()`/`summary()`.
     - The training summary is set up client-side at the fit, as PySpark's 
`try_remote_fit` sets it up, with the training dataset as its summary dataset. 
Both classes override `_summary_dataset` to return the training dataset. A 
loaded model has no training summary.
     - `AFTSurvivalRegressionModel`: `coefficients`, `intercept`, `scale`, 
`predict_quantiles`.
     - `IsotonicRegressionModel`: `boundaries`, `predictions`, `num_features`, 
and `predict` of a single feature value.
     - `FMRegressionModel`: `intercept`, `linear`, `factors`.
     - Every model except the isotonic one implements `PredictionModel` 
(`num_features`, `predict`).
   - **Summaries**:
     - `LinearRegressionSummaryApi` is implemented by `LinearRegressionSummary` 
and by `LinearRegressionTrainingSummary`, which also implements 
`TrainingSummary`.
     - `GeneralizedLinearRegressionSummaryApi` is implemented by both GLR 
summaries. The training one also has `solver`, `num_iterations`, the 
coefficient statistics and `describe()`.
     - DataFrame members are attribute relations of the summary: `predictions`, 
`residuals`, and GLR's `residuals(residuals_type)`.
     - The summary of `evaluate` is its own server-side object, which the 
client does not release, as in PySpark.
   - **Trees**:
     - `DecisionTreeRegressionModel` implements `DecisionTreeModel`.
     - `RandomForestRegressionModel` and `GBTRegressionModel` implement 
`TreeEnsembleModel`, whose trees are `DecisionTreeRegressionModel`s of their 
own server-side objects.
     - `GBTRegressionModel::evaluate_each_iteration(&dataset, loss)`.
     - `DecisionTreeRegressionModel::from_ml_ref` builds a tree of an ensemble. 
The classification GBT trees are this class too.
   - **Persistence**: `load(&session, path)` for every estimator and model, 
alongside the `write()` of #667.
   - **Params**: the hand-written setters and getters of the 16 classes are 
replaced by the generated `ml_params!` rows of `tests/golden/ml_api.json`, and 
the classes are converted in `tests/ml_params_table/regression.rs`.
     - A model has a getter for each of its params, and only the setters that 
PySpark's model has.
     - A getter returns PySpark's default when the param is unset, and `None` 
for a param that has no default. An unset seed returns Spark's default, the 
`String.hashCode` of the JVM class name.
     - The `featuresCol` accessors are now `features_col` and 
`set_features_col`, after the param name.
     - `GBTRegressor` keeps `set_validation_tol`. `validationTol` is a 
constructor param of PySpark, which has no `setValidationTol`.
   - **Docs**: `docs/compatibility.md` has a new section, "Native regression 
models (Rust API)".
   
   ### Why are the changes needed?
   
   So that the native Rust ML API has the members of pyspark.ml's regression 
models: inspection, summaries, single-vector prediction and persistence.
   
   ### Does this PR introduce _any_ user-facing change?
   
   Yes, in the native Rust ML API, which is unreleased: none of these classes 
shipped in the 4.2.0 crate.
   - The inherent `fit` of the 8 regression estimators returns the typed model. 
`Estimator::fit(&mut estimator, &df)` still returns the `Box<dyn Model>`.
   - The members, summaries and `load` above are new.
   - The accessors of `featuresCol` are renamed, and an unset seed returns 
Spark's default.
   
   ### How was this patch tested?
   
   - New live tests in `e2e_ml_regression_api.rs` (4 tests), against a Spark 
4.3.0 Connect server:
     - every member, summary and evaluation of the linear and generalized 
linear models;
     - AFT, isotonic and FM;
     - the tree members, trees and `evaluateEachIteration`;
     - save and load of the models and estimators.
   - The existing live and golden suites of the 8 families pass. They are 
updated for the typed fit and for the renamed accessors and seed defaults.
   - `tests/ml_params_table.rs` passes with the 16 classes converted. The 
crate's unit tests passed 694. Clippy (`-D warnings`) and fmt are clean.
   - The members' value types (Int, Long, Double, arrays, vector, matrix) were 
checked against the official `pyspark-client` 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]

Reply via email to