This is an automated email from the ASF dual-hosted git repository.

zhengruifeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new 2dd10b29f507 [SPARK-61456][ML][PYTHON] Support configurable 
intermediate storage levels in regression estimators
2dd10b29f507 is described below

commit 2dd10b29f5079e9f01aa54e1c447257d73181775
Author: Ruifeng Zheng <[email protected]>
AuthorDate: Fri Nov 13 08:28:11 2026 +0800

    [SPARK-61456][ML][PYTHON] Support configurable intermediate storage levels 
in regression estimators
    
    ### What changes were proposed in this pull request?
    
    Add the existing `intermediateStorageLevel` parameter to 
`LinearRegression`, `AFTSurvivalRegression`, `FMRegressor`, and 
`IsotonicRegression` in Scala and PySpark. Use the configured level for their 
internally cached training data. PySpark accepts the parameter through 
constructors, `setParams`, and setters.
    
    ### Why are the changes needed?
    
    These regressors hard-code the storage level of intermediate RDDs, which 
users cannot configure by caching their input DataFrame. The parameter allows 
choices such as `DISK_ONLY` to reduce memory pressure.
    
    ### Does this PR introduce _any_ user-facing change?
    
    Yes. The four regressors expose `intermediateStorageLevel`, defaulting to 
`MEMORY_AND_DISK`. For `LinearRegression`, it applies to training blocks used 
by the iterative solver. The existing shared validator rejects `NONE` and 
invalid storage levels.
    
    ### How was this patch tested?
    
    - Extended the existing Scala suites with simple default-value and 
setter/getter checks. All 75 executed Scala tests passed; two existing tests 
were ignored.
    - Extended existing PySpark tests to cover constructor keywords, 
`setParams`, setters, and model parameter propagation.
    - All nine focused classic PySpark, Spark Connect, and Java/Python 
parameter-parity checks passed.
    - A Scala smoke check confirmed `DISK_ONLY` cached RDDs for all four 
regressors, including `LinearRegression` with its iterative solver.
    - Scala source/test style checks, MLlib MiMa, and Python lint and 
formatting passed.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Codex (GPT-6)
    
    Closes #60338 from zhengruifeng/regressor-intermediate-storage.
    
    Authored-by: Ruifeng Zheng <[email protected]>
    Signed-off-by: Ruifeng Zheng <[email protected]>
    
    
    skip-checks: true
---
 .../ml/regression/AFTSurvivalRegression.scala      | 11 ++-
 .../apache/spark/ml/regression/FMRegressor.scala   | 14 +++-
 .../spark/ml/regression/IsotonicRegression.scala   | 14 +++-
 .../spark/ml/regression/LinearRegression.scala     | 17 ++++-
 .../ml/regression/AFTSurvivalRegressionSuite.scala |  6 +-
 .../spark/ml/regression/FMRegressorSuite.scala     |  6 +-
 .../ml/regression/IsotonicRegressionSuite.scala    |  3 +
 .../ml/regression/LinearRegressionSuite.scala      |  6 +-
 python/pyspark/ml/regression.py                    | 80 +++++++++++++++++++---
 python/pyspark/ml/tests/test_regression.py         | 36 +++++++++-
 10 files changed, 166 insertions(+), 27 deletions(-)

diff --git 
a/mllib/src/main/scala/org/apache/spark/ml/regression/AFTSurvivalRegression.scala
 
b/mllib/src/main/scala/org/apache/spark/ml/regression/AFTSurvivalRegression.scala
index 0e6846e6085d..d823743b1fee 100644
--- 
a/mllib/src/main/scala/org/apache/spark/ml/regression/AFTSurvivalRegression.scala
+++ 
b/mllib/src/main/scala/org/apache/spark/ml/regression/AFTSurvivalRegression.scala
@@ -50,7 +50,7 @@ import org.apache.spark.storage.StorageLevel
  */
 private[regression] trait AFTSurvivalRegressionParams extends PredictorParams
   with HasMaxIter with HasTol with HasFitIntercept with HasAggregationDepth
-  with HasMaxBlockSizeInMB with Logging {
+  with HasMaxBlockSizeInMB with HasIntermediateStorageLevel with Logging {
 
   /**
    * Param for censor column name.
@@ -199,12 +199,17 @@ class AFTSurvivalRegression @Since("1.6.0") 
(@Since("1.6.0") override val uid: S
   @Since("3.1.0")
   def setMaxBlockSizeInMB(value: Double): this.type = set(maxBlockSizeInMB, 
value)
 
+  /** @group expertSetParam */
+  @Since("4.4.0")
+  def setIntermediateStorageLevel(value: String): this.type = 
set(intermediateStorageLevel, value)
+
   override protected def train(
       dataset: Dataset[_]): AFTSurvivalRegressionModel = instrumented { instr 
=>
     instr.logPipelineStage(this)
     instr.logDataset(dataset)
     instr.logParams(this, labelCol, featuresCol, censorCol, predictionCol, 
quantilesCol,
-      fitIntercept, maxIter, tol, aggregationDepth, maxBlockSizeInMB)
+      fitIntercept, maxIter, tol, aggregationDepth, maxBlockSizeInMB,
+      intermediateStorageLevel)
     instr.logNamedValue("quantileProbabilities.size", 
$(quantileProbabilities).length)
 
     if (dataset.storageLevel != StorageLevel.NONE) {
@@ -304,7 +309,7 @@ class AFTSurvivalRegression @Since("1.6.0") 
(@Since("1.6.0") override val uid: S
 
     val maxMemUsage = (actualBlockSizeInMB * 1024L * 1024L).ceil.toLong
     val blocks = InstanceBlock.blokifyWithMaxMemUsage(scaled, maxMemUsage)
-      .persist(StorageLevel.MEMORY_AND_DISK)
+      .persist(StorageLevel.fromString($(intermediateStorageLevel)))
       .setName(s"training blocks (blockSizeInMB=$actualBlockSizeInMB)")
 
     val getAggregatorFunc = new AFTBlockAggregator(bcScaledMean, 
$(fitIntercept))(_)
diff --git 
a/mllib/src/main/scala/org/apache/spark/ml/regression/FMRegressor.scala 
b/mllib/src/main/scala/org/apache/spark/ml/regression/FMRegressor.scala
index d2fcb9280c63..c83fabadc681 100644
--- a/mllib/src/main/scala/org/apache/spark/ml/regression/FMRegressor.scala
+++ b/mllib/src/main/scala/org/apache/spark/ml/regression/FMRegressor.scala
@@ -269,7 +269,8 @@ private[ml] object FactorizationMachines {
 /**
  * Params for FMRegressor
  */
-private[regression] trait FMRegressorParams extends 
FactorizationMachinesParams {
+private[regression] trait FMRegressorParams extends FactorizationMachinesParams
+  with HasIntermediateStorageLevel {
 }
 
 // scalastyle:off line.size.limit
@@ -408,6 +409,10 @@ class FMRegressor @Since("3.0.0") (
   @Since("3.0.0")
   def setSeed(value: Long): this.type = set(seed, value)
 
+  /** @group expertSetParam */
+  @Since("4.4.0")
+  def setIntermediateStorageLevel(value: String): this.type = 
set(intermediateStorageLevel, value)
+
   override protected def train(
       dataset: Dataset[_]
     ): FMRegressionModel = instrumented { instr =>
@@ -415,7 +420,8 @@ class FMRegressor @Since("3.0.0") (
     instr.logPipelineStage(this)
     instr.logDataset(dataset)
     instr.logParams(this, factorSize, fitIntercept, fitLinear, regParam,
-      miniBatchFraction, initStd, maxIter, stepSize, tol, solver)
+      miniBatchFraction, initStd, maxIter, stepSize, tol, solver,
+      intermediateStorageLevel)
 
     val numFeatures = getNumFeatures(dataset, $(featuresCol))
     instr.logNumFeatures(numFeatures)
@@ -428,7 +434,9 @@ class FMRegressor @Since("3.0.0") (
     ).rdd.map { case Row(l: Double, v: Vector) => (l, OldVectors.fromML(v))
     }.setName("training instances")
 
-    if (handlePersistence) data.persist(StorageLevel.MEMORY_AND_DISK)
+    if (handlePersistence) {
+      data.persist(StorageLevel.fromString($(intermediateStorageLevel)))
+    }
 
     val (coefficients, _) = trainImpl(data, numFeatures, SquaredError)
 
diff --git 
a/mllib/src/main/scala/org/apache/spark/ml/regression/IsotonicRegression.scala 
b/mllib/src/main/scala/org/apache/spark/ml/regression/IsotonicRegression.scala
index 72fe7706d610..b66287fe0d4d 100644
--- 
a/mllib/src/main/scala/org/apache/spark/ml/regression/IsotonicRegression.scala
+++ 
b/mllib/src/main/scala/org/apache/spark/ml/regression/IsotonicRegression.scala
@@ -45,7 +45,8 @@ import org.apache.spark.util.SizeEstimator
  * Params for isotonic regression.
  */
 private[regression] trait IsotonicRegressionBase extends Params with 
HasFeaturesCol
-  with HasLabelCol with HasPredictionCol with HasWeightCol with Logging {
+  with HasLabelCol with HasPredictionCol with HasWeightCol
+  with HasIntermediateStorageLevel with Logging {
 
   /**
    * Param for whether the output sequence should be isotonic/increasing 
(true) or
@@ -165,6 +166,10 @@ class IsotonicRegression @Since("1.5.0") (@Since("1.5.0") 
override val uid: Stri
   @Since("1.5.0")
   def setFeatureIndex(value: Int): this.type = set(featureIndex, value)
 
+  /** @group expertSetParam */
+  @Since("4.4.0")
+  def setIntermediateStorageLevel(value: String): this.type = 
set(intermediateStorageLevel, value)
+
   @Since("1.5.0")
   override def copy(extra: ParamMap): IsotonicRegression = defaultCopy(extra)
 
@@ -174,11 +179,14 @@ class IsotonicRegression @Since("1.5.0") (@Since("1.5.0") 
override val uid: Stri
     // Extract columns from data.  If dataset is persisted, do not persist 
oldDataset.
     val instances = extractWeightedLabeledPoints(dataset)
     val handlePersistence = dataset.storageLevel == StorageLevel.NONE
-    if (handlePersistence) instances.persist(StorageLevel.MEMORY_AND_DISK)
+    if (handlePersistence) {
+      instances.persist(StorageLevel.fromString($(intermediateStorageLevel)))
+    }
 
     instr.logPipelineStage(this)
     instr.logDataset(dataset)
-    instr.logParams(this, labelCol, featuresCol, weightCol, predictionCol, 
featureIndex, isotonic)
+    instr.logParams(this, labelCol, featuresCol, weightCol, predictionCol, 
featureIndex,
+      isotonic, intermediateStorageLevel)
     instr.logNumFeatures(1)
 
     val isotonicRegression = new 
MLlibIsotonicRegression().setIsotonic($(isotonic))
diff --git 
a/mllib/src/main/scala/org/apache/spark/ml/regression/LinearRegression.scala 
b/mllib/src/main/scala/org/apache/spark/ml/regression/LinearRegression.scala
index 89e29a7fb26d..49281db67082 100644
--- a/mllib/src/main/scala/org/apache/spark/ml/regression/LinearRegression.scala
+++ b/mllib/src/main/scala/org/apache/spark/ml/regression/LinearRegression.scala
@@ -58,7 +58,8 @@ import org.apache.spark.util.VersionUtils.majorMinorVersion
 private[regression] trait LinearRegressionParams extends PredictorParams
     with HasRegParam with HasElasticNetParam with HasMaxIter with HasTol
     with HasFitIntercept with HasStandardization with HasWeightCol with 
HasSolver
-    with HasAggregationDepth with HasLoss with HasMaxBlockSizeInMB {
+    with HasAggregationDepth with HasLoss with HasMaxBlockSizeInMB
+    with HasIntermediateStorageLevel {
 
   import LinearRegression._
 
@@ -326,13 +327,23 @@ class LinearRegression @Since("1.3.0") (@Since("1.3.0") 
override val uid: String
   @Since("3.1.0")
   def setMaxBlockSizeInMB(value: Double): this.type = set(maxBlockSizeInMB, 
value)
 
+  /**
+   * Sets the storage level for intermediate training data on the iterative 
training path.
+   * Has no effect on normal-equation training, including when [[solver]] is 
"auto" and selects
+   * that path, or when training returns early for a constant label.
+   *
+   * @group expertSetParam
+   */
+  @Since("4.4.0")
+  def setIntermediateStorageLevel(value: String): this.type = 
set(intermediateStorageLevel, value)
+
   override protected def train(
       dataset: Dataset[_]): LinearRegressionModel = instrumented { instr =>
     instr.logPipelineStage(this)
     instr.logDataset(dataset)
     instr.logParams(this, labelCol, featuresCol, weightCol, predictionCol, 
solver, tol,
       elasticNetParam, fitIntercept, maxIter, regParam, standardization, 
aggregationDepth, loss,
-      epsilon, maxBlockSizeInMB)
+      epsilon, maxBlockSizeInMB, intermediateStorageLevel)
 
     if (dataset.storageLevel != StorageLevel.NONE) {
       instr.logWarning("Input instances will be standardized, blockified to 
blocks, and " +
@@ -549,7 +560,7 @@ class LinearRegression @Since("1.3.0") (@Since("1.3.0") 
override val uid: String
 
     val maxMemUsage = (actualBlockSizeInMB * 1024L * 1024L).ceil.toLong
     val blocks = InstanceBlock.blokifyWithMaxMemUsage(standardized, 
maxMemUsage)
-      .persist(StorageLevel.MEMORY_AND_DISK)
+      .persist(StorageLevel.fromString($(intermediateStorageLevel)))
       .setName(s"$uid: training blocks (blockSizeInMB=$actualBlockSizeInMB)")
 
     if ($(fitIntercept) && $(loss) == Huber) {
diff --git 
a/mllib/src/test/scala/org/apache/spark/ml/regression/AFTSurvivalRegressionSuite.scala
 
b/mllib/src/test/scala/org/apache/spark/ml/regression/AFTSurvivalRegressionSuite.scala
index d9b454e0d10a..956aab70630e 100644
--- 
a/mllib/src/test/scala/org/apache/spark/ml/regression/AFTSurvivalRegressionSuite.scala
+++ 
b/mllib/src/test/scala/org/apache/spark/ml/regression/AFTSurvivalRegressionSuite.scala
@@ -62,7 +62,11 @@ class AFTSurvivalRegressionSuite extends MLTest with 
DefaultReadWriteTest {
   }
 
   test("params") {
-    ParamsSuite.checkParams(new AFTSurvivalRegression)
+    val regressor = new AFTSurvivalRegression
+    ParamsSuite.checkParams(regressor)
+    assert(regressor.getIntermediateStorageLevel === "MEMORY_AND_DISK")
+    regressor.setIntermediateStorageLevel("DISK_ONLY")
+    assert(regressor.getIntermediateStorageLevel === "DISK_ONLY")
     val model = new AFTSurvivalRegressionModel("aftSurvReg", 
Vectors.dense(0.0), 0.0, 0.0)
     ParamsSuite.checkParams(model)
   }
diff --git 
a/mllib/src/test/scala/org/apache/spark/ml/regression/FMRegressorSuite.scala 
b/mllib/src/test/scala/org/apache/spark/ml/regression/FMRegressorSuite.scala
index f2134977c476..dc5b4e2edbdb 100644
--- a/mllib/src/test/scala/org/apache/spark/ml/regression/FMRegressorSuite.scala
+++ b/mllib/src/test/scala/org/apache/spark/ml/regression/FMRegressorSuite.scala
@@ -44,7 +44,11 @@ class FMRegressorSuite extends MLTest with 
DefaultReadWriteTest {
   }
 
   test("params") {
-    ParamsSuite.checkParams(new FMRegressor)
+    val regressor = new FMRegressor
+    ParamsSuite.checkParams(regressor)
+    assert(regressor.getIntermediateStorageLevel === "MEMORY_AND_DISK")
+    regressor.setIntermediateStorageLevel("DISK_ONLY")
+    assert(regressor.getIntermediateStorageLevel === "DISK_ONLY")
     val model = new FMRegressionModel("fmr_test", 0.0, Vectors.dense(0.0),
       new DenseMatrix(1, 8, new Array[Double](8)))
     ParamsSuite.checkParams(model)
diff --git 
a/mllib/src/test/scala/org/apache/spark/ml/regression/IsotonicRegressionSuite.scala
 
b/mllib/src/test/scala/org/apache/spark/ml/regression/IsotonicRegressionSuite.scala
index ae779a51e599..772be3c0155d 100644
--- 
a/mllib/src/test/scala/org/apache/spark/ml/regression/IsotonicRegressionSuite.scala
+++ 
b/mllib/src/test/scala/org/apache/spark/ml/regression/IsotonicRegressionSuite.scala
@@ -82,6 +82,9 @@ class IsotonicRegressionSuite extends MLTest with 
DefaultReadWriteTest {
     val dataset = generateIsotonicInput(Seq(1, 2, 3))
     val ir = new IsotonicRegression
     ParamsSuite.checkParams(ir)
+    assert(ir.getIntermediateStorageLevel === "MEMORY_AND_DISK")
+    ir.setIntermediateStorageLevel("DISK_ONLY")
+    assert(ir.getIntermediateStorageLevel === "DISK_ONLY")
     val model = ir.fit(dataset)
     ParamsSuite.checkParams(model)
   }
diff --git 
a/mllib/src/test/scala/org/apache/spark/ml/regression/LinearRegressionSuite.scala
 
b/mllib/src/test/scala/org/apache/spark/ml/regression/LinearRegressionSuite.scala
index 644a06d51129..90b62aed27d0 100644
--- 
a/mllib/src/test/scala/org/apache/spark/ml/regression/LinearRegressionSuite.scala
+++ 
b/mllib/src/test/scala/org/apache/spark/ml/regression/LinearRegressionSuite.scala
@@ -150,7 +150,11 @@ class LinearRegressionSuite extends MLTest with 
DefaultReadWriteTest with PMMLRe
   }
 
   test("params") {
-    ParamsSuite.checkParams(new LinearRegression)
+    val regressor = new LinearRegression
+    ParamsSuite.checkParams(regressor)
+    assert(regressor.getIntermediateStorageLevel === "MEMORY_AND_DISK")
+    regressor.setIntermediateStorageLevel("DISK_ONLY")
+    assert(regressor.getIntermediateStorageLevel === "DISK_ONLY")
     val model = new LinearRegressionModel("linearReg", Vectors.dense(0.0), 0.0)
     ParamsSuite.checkParams(model)
   }
diff --git a/python/pyspark/ml/regression.py b/python/pyspark/ml/regression.py
index 82a36fbfd202..0913cae393dc 100644
--- a/python/pyspark/ml/regression.py
+++ b/python/pyspark/ml/regression.py
@@ -29,6 +29,7 @@ from pyspark.ml.param.shared import (
     HasElasticNetParam,
     HasFeaturesCol,
     HasFitIntercept,
+    HasIntermediateStorageLevel,
     HasLabelCol,
     HasLoss,
     HasMaxBlockSizeInMB,
@@ -158,6 +159,7 @@ class _LinearRegressionParams(
     HasAggregationDepth,
     HasLoss,
     HasMaxBlockSizeInMB,
+    HasIntermediateStorageLevel,
 ):
     """
     Params for :py:class:`LinearRegression` and 
:py:class:`LinearRegressionModel`.
@@ -316,12 +318,14 @@ class LinearRegression(
         loss: str = "squaredError",
         epsilon: float = 1.35,
         maxBlockSizeInMB: float = 0.0,
+        intermediateStorageLevel: str = "MEMORY_AND_DISK",
     ):
         """
         __init__(self, \\*, featuresCol="features", labelCol="label", 
predictionCol="prediction", \
                  maxIter=100, regParam=0.0, elasticNetParam=0.0, tol=1e-6, 
fitIntercept=True, \
                  standardization=True, solver="auto", weightCol=None, 
aggregationDepth=2, \
-                 loss="squaredError", epsilon=1.35, maxBlockSizeInMB=0.0)
+                 loss="squaredError", epsilon=1.35, maxBlockSizeInMB=0.0, \
+                 intermediateStorageLevel="MEMORY_AND_DISK")
         """
         super().__init__()
         self._java_obj = self._new_java_obj(
@@ -350,12 +354,14 @@ class LinearRegression(
         loss: str = "squaredError",
         epsilon: float = 1.35,
         maxBlockSizeInMB: float = 0.0,
+        intermediateStorageLevel: str = "MEMORY_AND_DISK",
     ) -> "LinearRegression":
         """
         setParams(self, \\*, featuresCol="features", labelCol="label", 
predictionCol="prediction", \
                   maxIter=100, regParam=0.0, elasticNetParam=0.0, tol=1e-6, 
fitIntercept=True, \
                   standardization=True, solver="auto", weightCol=None, 
aggregationDepth=2, \
-                  loss="squaredError", epsilon=1.35, maxBlockSizeInMB=0.0)
+                  loss="squaredError", epsilon=1.35, maxBlockSizeInMB=0.0, \
+                  intermediateStorageLevel="MEMORY_AND_DISK")
         Sets params for linear regression.
         """
         kwargs = self._input_kwargs
@@ -438,6 +444,17 @@ class LinearRegression(
         """
         return self._set(maxBlockSizeInMB=value)
 
+    @since("4.4.0")
+    def setIntermediateStorageLevel(self, value: str) -> "LinearRegression":
+        """
+        Sets the value of :py:attr:`intermediateStorageLevel`.
+
+        Only affects the iterative training path. Has no effect on 
normal-equation
+        training, including when :py:attr:`solver` is "auto" and selects that 
path,
+        or when training returns early for a constant label.
+        """
+        return self._set(intermediateStorageLevel=value)
+
 
 class LinearRegressionModel(
     _JavaRegressionModel,
@@ -771,7 +788,9 @@ class 
LinearRegressionTrainingSummary(LinearRegressionSummary):
         return self._call_java("totalIterations")
 
 
-class _IsotonicRegressionParams(HasFeaturesCol, HasLabelCol, HasPredictionCol, 
HasWeightCol):
+class _IsotonicRegressionParams(
+    HasFeaturesCol, HasLabelCol, HasPredictionCol, HasWeightCol, 
HasIntermediateStorageLevel
+):
     """
     Params for :py:class:`IsotonicRegression` and 
:py:class:`IsotonicRegressionModel`.
 
@@ -866,10 +885,12 @@ class IsotonicRegression(
         weightCol: Optional[str] = None,
         isotonic: bool = True,
         featureIndex: int = 0,
+        intermediateStorageLevel: str = "MEMORY_AND_DISK",
     ):
         """
         __init__(self, \\*, featuresCol="features", labelCol="label", 
predictionCol="prediction", \
-                 weightCol=None, isotonic=True, featureIndex=0):
+                 weightCol=None, isotonic=True, featureIndex=0, \
+                 intermediateStorageLevel="MEMORY_AND_DISK"):
         """
         super().__init__()
         self._java_obj = self._new_java_obj(
@@ -888,10 +909,12 @@ class IsotonicRegression(
         weightCol: Optional[str] = None,
         isotonic: bool = True,
         featureIndex: int = 0,
+        intermediateStorageLevel: str = "MEMORY_AND_DISK",
     ) -> "IsotonicRegression":
         """
         setParams(self, \\*, featuresCol="features", labelCol="label", 
predictionCol="prediction", \
-                 weightCol=None, isotonic=True, featureIndex=0):
+                 weightCol=None, isotonic=True, featureIndex=0, \
+                 intermediateStorageLevel="MEMORY_AND_DISK"):
         Set the params for IsotonicRegression.
         """
         kwargs = self._input_kwargs
@@ -912,6 +935,13 @@ class IsotonicRegression(
         """
         return self._set(featureIndex=value)
 
+    @since("4.4.0")
+    def setIntermediateStorageLevel(self, value: str) -> "IsotonicRegression":
+        """
+        Sets the value of :py:attr:`intermediateStorageLevel`.
+        """
+        return self._set(intermediateStorageLevel=value)
+
     @since("1.6.0")
     def setFeaturesCol(self, value: str) -> "IsotonicRegression":
         """
@@ -2057,7 +2087,13 @@ class GBTRegressionModel(
 
 
 class _AFTSurvivalRegressionParams(
-    _PredictorParams, HasMaxIter, HasTol, HasFitIntercept, 
HasAggregationDepth, HasMaxBlockSizeInMB
+    _PredictorParams,
+    HasMaxIter,
+    HasTol,
+    HasFitIntercept,
+    HasAggregationDepth,
+    HasMaxBlockSizeInMB,
+    HasIntermediateStorageLevel,
 ):
     """
     Params for :py:class:`AFTSurvivalRegression` and 
:py:class:`AFTSurvivalRegressionModel`.
@@ -2215,12 +2251,14 @@ class AFTSurvivalRegression(
         quantilesCol: Optional[str] = None,
         aggregationDepth: int = 2,
         maxBlockSizeInMB: float = 0.0,
+        intermediateStorageLevel: str = "MEMORY_AND_DISK",
     ):
         """
         __init__(self, \\*, featuresCol="features", labelCol="label", 
predictionCol="prediction", \
                  fitIntercept=True, maxIter=100, tol=1E-6, censorCol="censor", 
\
                  quantileProbabilities=[0.01, 0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 
0.95, 0.99], \
-                 quantilesCol=None, aggregationDepth=2, maxBlockSizeInMB=0.0)
+                 quantilesCol=None, aggregationDepth=2, maxBlockSizeInMB=0.0, \
+                 intermediateStorageLevel="MEMORY_AND_DISK")
         """
         super().__init__()
         self._java_obj = self._new_java_obj(
@@ -2255,12 +2293,14 @@ class AFTSurvivalRegression(
         quantilesCol: Optional[str] = None,
         aggregationDepth: int = 2,
         maxBlockSizeInMB: float = 0.0,
+        intermediateStorageLevel: str = "MEMORY_AND_DISK",
     ) -> "AFTSurvivalRegression":
         """
         setParams(self, \\*, featuresCol="features", labelCol="label", 
predictionCol="prediction", \
                   fitIntercept=True, maxIter=100, tol=1E-6, 
censorCol="censor", \
                   quantileProbabilities=[0.01, 0.05, 0.1, 0.25, 0.5, 0.75, 
0.9, 0.95, 0.99], \
-                  quantilesCol=None, aggregationDepth=2, maxBlockSizeInMB=0.0):
+                  quantilesCol=None, aggregationDepth=2, maxBlockSizeInMB=0.0, 
\
+                  intermediateStorageLevel="MEMORY_AND_DISK"):
         """
         kwargs = self._input_kwargs
         return self._set(**kwargs)
@@ -2324,6 +2364,13 @@ class AFTSurvivalRegression(
         """
         return self._set(maxBlockSizeInMB=value)
 
+    @since("4.4.0")
+    def setIntermediateStorageLevel(self, value: str) -> 
"AFTSurvivalRegression":
+        """
+        Sets the value of :py:attr:`intermediateStorageLevel`.
+        """
+        return self._set(intermediateStorageLevel=value)
+
 
 class AFTSurvivalRegressionModel(
     _JavaRegressionModel[Vector],
@@ -3101,6 +3148,7 @@ class _FactorizationMachinesParams(
 class FMRegressor(
     _JavaRegressor["FMRegressionModel"],
     _FactorizationMachinesParams,
+    HasIntermediateStorageLevel,
     JavaMLWritable,
     JavaMLReadable["FMRegressor"],
 ):
@@ -3183,12 +3231,14 @@ class FMRegressor(
         tol: float = 1e-6,
         solver: str = "adamW",
         seed: Optional[int] = None,
+        intermediateStorageLevel: str = "MEMORY_AND_DISK",
     ):
         """
         __init__(self, \\*, featuresCol="features", labelCol="label", 
predictionCol="prediction", \
                  factorSize=8, fitIntercept=True, fitLinear=True, 
regParam=0.0, \
                  miniBatchFraction=1.0, initStd=0.01, maxIter=100, 
stepSize=1.0, \
-                 tol=1e-6, solver="adamW", seed=None)
+                 tol=1e-6, solver="adamW", seed=None, \
+                 intermediateStorageLevel="MEMORY_AND_DISK")
         """
         super().__init__()
         self._java_obj = 
self._new_java_obj("org.apache.spark.ml.regression.FMRegressor", self.uid)
@@ -3214,12 +3264,14 @@ class FMRegressor(
         tol: float = 1e-6,
         solver: str = "adamW",
         seed: Optional[int] = None,
+        intermediateStorageLevel: str = "MEMORY_AND_DISK",
     ) -> "FMRegressor":
         """
         setParams(self, \\*, featuresCol="features", labelCol="label", 
predictionCol="prediction", \
                   factorSize=8, fitIntercept=True, fitLinear=True, 
regParam=0.0, \
                   miniBatchFraction=1.0, initStd=0.01, maxIter=100, 
stepSize=1.0, \
-                  tol=1e-6, solver="adamW", seed=None)
+                  tol=1e-6, solver="adamW", seed=None, \
+                  intermediateStorageLevel="MEMORY_AND_DISK")
         Sets Params for FMRegressor.
         """
         kwargs = self._input_kwargs
@@ -3291,6 +3343,13 @@ class FMRegressor(
         """
         return self._set(seed=value)
 
+    @since("4.4.0")
+    def setIntermediateStorageLevel(self, value: str) -> "FMRegressor":
+        """
+        Sets the value of :py:attr:`intermediateStorageLevel`.
+        """
+        return self._set(intermediateStorageLevel=value)
+
     @since("3.0.0")
     def setFitIntercept(self, value: bool) -> "FMRegressor":
         """
@@ -3309,6 +3368,7 @@ class FMRegressor(
 class FMRegressionModel(
     _JavaRegressionModel,
     _FactorizationMachinesParams,
+    HasIntermediateStorageLevel,
     JavaMLWritable,
     JavaMLReadable["FMRegressionModel"],
 ):
diff --git a/python/pyspark/ml/tests/test_regression.py 
b/python/pyspark/ml/tests/test_regression.py
index 7024bd45cd5f..854e2ee3bbc7 100644
--- a/python/pyspark/ml/tests/test_regression.py
+++ b/python/pyspark/ml/tests/test_regression.py
@@ -53,11 +53,18 @@ class RegressionTestsMixin:
             ["label", "features", "censor"],
         )
 
-        aft = AFTSurvivalRegression()
+        
self.assertEqual(AFTSurvivalRegression().getIntermediateStorageLevel(), 
"MEMORY_AND_DISK")
+        aft = AFTSurvivalRegression(intermediateStorageLevel="DISK_ONLY")
+        self.assertEqual(aft.getIntermediateStorageLevel(), "DISK_ONLY")
+        aft.setParams(intermediateStorageLevel="MEMORY_ONLY")
+        self.assertEqual(aft.getIntermediateStorageLevel(), "MEMORY_ONLY")
+        aft.setIntermediateStorageLevel("DISK_ONLY")
+        self.assertEqual(aft.getIntermediateStorageLevel(), "DISK_ONLY")
         aft.setMaxIter(1)
         self.assertEqual(aft.getMaxIter(), 1)
 
         model = aft.fit(df)
+        self.assertEqual(model.getIntermediateStorageLevel(), "DISK_ONLY")
         self.assertEqual(aft.uid, model.uid)
         self.assertEqual(model.numFeatures, 1)
         self.assertTrue(np.allclose(model.intercept, 0.0, atol=1e-4), 
model.intercept)
@@ -110,14 +117,22 @@ class RegressionTestsMixin:
             [(1.0, Vectors.dense(1.0)), (0.0, Vectors.sparse(1, [], []))], 
["label", "features"]
         )
 
+        self.assertEqual(IsotonicRegression().getIntermediateStorageLevel(), 
"MEMORY_AND_DISK")
         ir = IsotonicRegression(
             isotonic=True,
             featureIndex=0,
+            intermediateStorageLevel="DISK_ONLY",
         )
+        self.assertEqual(ir.getIntermediateStorageLevel(), "DISK_ONLY")
+        ir.setParams(intermediateStorageLevel="MEMORY_ONLY")
+        self.assertEqual(ir.getIntermediateStorageLevel(), "MEMORY_ONLY")
+        ir.setIntermediateStorageLevel("DISK_ONLY")
+        self.assertEqual(ir.getIntermediateStorageLevel(), "DISK_ONLY")
         self.assertTrue(ir.getIsotonic())
         self.assertEqual(ir.getFeatureIndex(), 0)
 
         model = ir.fit(df)
+        self.assertEqual(model.getIntermediateStorageLevel(), "DISK_ONLY")
         self.assertEqual(model.numFeatures, 1)
         self.assertTrue(
             np.allclose(model.boundaries.toArray(), [0.0, 1.0], atol=1e-4), 
model.boundaries
@@ -160,18 +175,26 @@ class RegressionTestsMixin:
             .sortWithinPartitions("weight")
         )
 
+        self.assertEqual(LinearRegression().getIntermediateStorageLevel(), 
"MEMORY_AND_DISK")
         lr = LinearRegression(
             regParam=0.0,
             maxIter=2,
             solver="normal",
             weightCol="weight",
+            intermediateStorageLevel="DISK_ONLY",
         )
+        self.assertEqual(lr.getIntermediateStorageLevel(), "DISK_ONLY")
+        lr.setParams(intermediateStorageLevel="MEMORY_ONLY")
+        self.assertEqual(lr.getIntermediateStorageLevel(), "MEMORY_ONLY")
+        lr.setIntermediateStorageLevel("DISK_ONLY")
+        self.assertEqual(lr.getIntermediateStorageLevel(), "DISK_ONLY")
         self.assertEqual(lr.getRegParam(), 0)
         self.assertEqual(lr.getMaxIter(), 2)
         self.assertEqual(lr.getSolver(), "normal")
         self.assertEqual(lr.getWeightCol(), "weight")
 
         model = lr.fit(df)
+        self.assertEqual(model.getIntermediateStorageLevel(), "DISK_ONLY")
         self.assertEqual(lr.uid, model.uid)
         self.assertEqual(model.numFeatures, 2)
         self.assertTrue(np.allclose(model.scale, 1.0, atol=1e-4))
@@ -393,13 +416,22 @@ class RegressionTestsMixin:
             .select("label", "features")
         )
 
-        fm = FMRegressor(factorSize=2, maxIter=1, regParam=1.0, seed=1)
+        self.assertEqual(FMRegressor().getIntermediateStorageLevel(), 
"MEMORY_AND_DISK")
+        fm = FMRegressor(
+            factorSize=2, maxIter=1, regParam=1.0, seed=1, 
intermediateStorageLevel="DISK_ONLY"
+        )
+        self.assertEqual(fm.getIntermediateStorageLevel(), "DISK_ONLY")
+        fm.setParams(intermediateStorageLevel="MEMORY_ONLY")
+        self.assertEqual(fm.getIntermediateStorageLevel(), "MEMORY_ONLY")
+        fm.setIntermediateStorageLevel("DISK_ONLY")
+        self.assertEqual(fm.getIntermediateStorageLevel(), "DISK_ONLY")
         self.assertEqual(fm.getFactorSize(), 2)
         self.assertEqual(fm.getMaxIter(), 1)
         self.assertEqual(fm.getRegParam(), 1.0)
         self.assertEqual(fm.getSeed(), 1)
 
         model = fm.fit(df)
+        self.assertEqual(model.getIntermediateStorageLevel(), "DISK_ONLY")
         self.assertEqual(fm.uid, model.uid)
         self.assertEqual(model.numFeatures, 2)
         self.assertTrue(


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to