Github user yanboliang commented on a diff in the pull request:
https://github.com/apache/spark/pull/11468#discussion_r58976307
--- Diff: python/pyspark/ml/regression.py ---
@@ -934,6 +935,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, JavaMLWritable,
JavaMLReadable):
+ """
+ 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([
+ ... (1.0, Vectors.dense(1.0, 0.0)),
+ ... (1.0, Vectors.dense(1.0, 2.0)),], ["label", "features"])
+ >>> glr = GeneralizedLinearRegression(family="gaussian",
link="identity")
+ >>> model = glr.fit(df)
+ >>> abs(model.transform(df).head().prediction - 1.0) < 0.001
+ True
+ >>> model.coefficients
+ DenseVector([0.0, 0.0])
+ >>> abs(model.intercept - 1.0) < 0.001
+ True
+ >>> glr_path = temp_path + "/glr"
+ >>> glr.save(glr_path)
+ >>> glr2 = GeneralizedLinearRegression.load(glr_path)
+ >>> glr.getFamily() == glr2.getFamily()
+ True
+ >>> model_path = temp_path + "/glr_model"
+ >>> model.save(model_path)
+ >>> model2 = GeneralizedLinearRegressionModel.load(model_path)
+ >>> abs(model.intercept - model2.intercept) < 0.001
+ True
--- End diff --
Should be ```model.intercept == model2.intercept```, because they are the
same value just after save/load.
May be we should also check ```model.coefficients[0] ==
model2.coefficients[0]```, but the coefficients of your test case are all
zeros, I think it's better to modify the test data which can produce non zero
coefficients.
---
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]