Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/11468#discussion_r54834037
--- Diff: python/pyspark/ml/regression.py ---
@@ -857,6 +858,146 @@ def predict(self, features):
return self._call_java("predict", features)
+@inherit_doc
+class GeneralizedLinearRegression(JavaEstimator, HasLabelCol,
HasFeaturesCol, HasPredictionCol,
+ HasFitIntercept, HasMaxIter, HasTol,
HasRegParam, HasWeightCol,
+ HasSolver):
+ """
+ Generalized Linear Regression.
+
+ Fit a Generalized Linear Model specified by giving a symbolic
description of the linear
+ predictor (link function) and a description of the error distribution
(family). It supports
+ "gaussian", "binomial", "poisson" and "gamma" as family. Valid link
functions for each family
+ is listed below. The first link function of each family is the default
one.
+ - "gaussian" -> "identity", "log", "inverse"
+ - "binomial" -> "logit", "probit", "cloglog"
+ - "poisson" -> "log", "identity", "sqrt"
+ - "gamma" -> "inverse", "identity", "log"
+
+ .. seealso:: `GLM
<https://en.wikipedia.org/wiki/Generalized_linear_model>`_
+
+ >>> from pyspark.mllib.linalg import Vectors
+ >>> df = sqlContext.createDataFrame([
+ ... (17.05224, Vectors.dense(3.55954, 11.19528)),
+ ... (13.46161, Vectors.dense(2.34561, 9.65407)),
+ ... (17.13384, Vectors.dense(3.37980, 12.03069)),
+ ... (13.84938, Vectors.dense(2.51969, 9.64902)),], ["label",
"features"])
+ >>> glr = GeneralizedLinearRegression()
+ >>> model = glr.setFamily("gaussian").setLink("identity").fit(df)
+ >>> model.transform(df).show()
+ +--------+------------------+------------------+
+ | label| features| prediction|
+ +--------+------------------+------------------+
+ |17.05224|[3.55954,11.19528]|17.052776698886376|
+ |13.46161| [2.34561,9.65407]|13.463078911930246|
+ |17.13384| [3.3798,12.03069]| 17.13348844246882|
+ |13.84938| [2.51969,9.64902]|13.847725946714558|
+ +--------+------------------+------------------+
+ ...
+ >>> model.coefficients
+ DenseVector([2.2263, 0.5756])
+ >>> model.intercept
+ 2.6841196897757795
+
+ .. versionadded:: 2.0.0
+ """
+
+ family = Param(Params._dummy(), "family", "The name of family which is
a description of " +
+ "the error distribution to be used in the model.
Supported options: " +
+ "gaussian(default), binomial, poisson and gamma.")
+ link = Param(Params._dummy(), "link", "The name of link function which
provides the " +
+ "relationship between the linear predictor and the mean
of the distribution " +
+ "function. Supported options: identity, log, inverse,
logit, probit, cloglog " +
+ "and sqrt.")
+
+ @keyword_only
+ def __init__(self, labelCol="label", featuresCol="features",
predictionCol="prediction",
+ fitIntercept=True, maxIter=25, tol=1e-6, regParam=0.0,
weightCol=None,
+ solver="irls"):
+ """
+ __init__(self, labelCol="label", featuresCol="features",
predictionCol="prediction", \
+ fitIntercept=True, maxIter=25, tol=1e-6, regParam=0.0,
weightCol=None, \
+ solver="irls")
+ """
+ super(GeneralizedLinearRegression, self).__init__()
+ self._java_obj = self._new_java_obj(
+ "org.apache.spark.ml.regression.GeneralizedLinearRegression",
self.uid)
+ self._setDefault(family="gaussian", link="identity")
--- End diff --
We did not set default value for ```link``` at Scala side because it was
decided by ```family```. For example, if users set ```family="binomial"``` and
did not set link, the ```link``` will be set as ```logit``` when training and
prediction.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]