aboutsummaryrefslogtreecommitdiff
path: root/python/pyspark/ml/regression.py
diff options
context:
space:
mode:
authorYanbo Liang <ybliang8@gmail.com>2015-09-11 08:50:35 -0700
committerXiangrui Meng <meng@databricks.com>2015-09-11 08:50:35 -0700
commitb656e6134fc5cd27e1fe6b6ab30fd7633cab0b14 (patch)
tree10d2d556a148adab585979cc387109588c6fda43 /python/pyspark/ml/regression.py
parentc268ca4ddde2f5213b2e3985dcaaac5900aea71c (diff)
downloadspark-b656e6134fc5cd27e1fe6b6ab30fd7633cab0b14.tar.gz
spark-b656e6134fc5cd27e1fe6b6ab30fd7633cab0b14.tar.bz2
spark-b656e6134fc5cd27e1fe6b6ab30fd7633cab0b14.zip
[SPARK-10026] [ML] [PySpark] Implement some common Params for regression in PySpark
LinearRegression and LogisticRegression lack of some Params for Python, and some Params are not shared classes which lead we need to write them for each class. These kinds of Params are list here: ```scala HasElasticNetParam HasFitIntercept HasStandardization HasThresholds ``` Here we implement them in shared params at Python side and make LinearRegression/LogisticRegression parameters peer with Scala one. Author: Yanbo Liang <ybliang8@gmail.com> Closes #8508 from yanboliang/spark-10026.
Diffstat (limited to 'python/pyspark/ml/regression.py')
-rw-r--r--python/pyspark/ml/regression.py42
1 files changed, 11 insertions, 31 deletions
diff --git a/python/pyspark/ml/regression.py b/python/pyspark/ml/regression.py
index 44f60a7695..a9503608b7 100644
--- a/python/pyspark/ml/regression.py
+++ b/python/pyspark/ml/regression.py
@@ -28,7 +28,8 @@ __all__ = ['DecisionTreeRegressor', 'DecisionTreeRegressionModel', 'GBTRegressor
@inherit_doc
class LinearRegression(JavaEstimator, HasFeaturesCol, HasLabelCol, HasPredictionCol, HasMaxIter,
- HasRegParam, HasTol):
+ HasRegParam, HasTol, HasElasticNetParam, HasFitIntercept,
+ HasStandardization):
"""
Linear regression.
@@ -63,38 +64,30 @@ class LinearRegression(JavaEstimator, HasFeaturesCol, HasLabelCol, HasPrediction
TypeError: Method setParams forces keyword arguments.
"""
- # a placeholder to make it appear in the generated doc
- elasticNetParam = \
- Param(Params._dummy(), "elasticNetParam",
- "the ElasticNet mixing parameter, in range [0, 1]. For alpha = 0, " +
- "the penalty is an L2 penalty. For alpha = 1, it is an L1 penalty.")
-
@keyword_only
def __init__(self, featuresCol="features", labelCol="label", predictionCol="prediction",
- maxIter=100, regParam=0.0, elasticNetParam=0.0, tol=1e-6):
+ maxIter=100, regParam=0.0, elasticNetParam=0.0, tol=1e-6, fitIntercept=True,
+ standardization=True):
"""
__init__(self, featuresCol="features", labelCol="label", predictionCol="prediction", \
- maxIter=100, regParam=0.0, elasticNetParam=0.0, tol=1e-6)
+ maxIter=100, regParam=0.0, elasticNetParam=0.0, tol=1e-6, fitIntercept=True, \
+ standardization=True)
"""
super(LinearRegression, self).__init__()
self._java_obj = self._new_java_obj(
"org.apache.spark.ml.regression.LinearRegression", self.uid)
- #: param for the ElasticNet mixing parameter, in range [0, 1]. For alpha = 0, the penalty
- # is an L2 penalty. For alpha = 1, it is an L1 penalty.
- self.elasticNetParam = \
- Param(self, "elasticNetParam",
- "the ElasticNet mixing parameter, in range [0, 1]. For alpha = 0, the penalty " +
- "is an L2 penalty. For alpha = 1, it is an L1 penalty.")
- self._setDefault(maxIter=100, regParam=0.0, elasticNetParam=0.0, tol=1e-6)
+ self._setDefault(maxIter=100, regParam=0.0, tol=1e-6)
kwargs = self.__init__._input_kwargs
self.setParams(**kwargs)
@keyword_only
def setParams(self, featuresCol="features", labelCol="label", predictionCol="prediction",
- maxIter=100, regParam=0.0, elasticNetParam=0.0, tol=1e-6):
+ maxIter=100, regParam=0.0, elasticNetParam=0.0, tol=1e-6, fitIntercept=True,
+ standardization=True):
"""
setParams(self, featuresCol="features", labelCol="label", predictionCol="prediction", \
- maxIter=100, regParam=0.0, elasticNetParam=0.0, tol=1e-6)
+ maxIter=100, regParam=0.0, elasticNetParam=0.0, tol=1e-6, fitIntercept=True, \
+ standardization=True)
Sets params for linear regression.
"""
kwargs = self.setParams._input_kwargs
@@ -103,19 +96,6 @@ class LinearRegression(JavaEstimator, HasFeaturesCol, HasLabelCol, HasPrediction
def _create_model(self, java_model):
return LinearRegressionModel(java_model)
- def setElasticNetParam(self, value):
- """
- Sets the value of :py:attr:`elasticNetParam`.
- """
- self._paramMap[self.elasticNetParam] = value
- return self
-
- def getElasticNetParam(self):
- """
- Gets the value of elasticNetParam or its default value.
- """
- return self.getOrDefault(self.elasticNetParam)
-
class LinearRegressionModel(JavaModel):
"""