Github user jkbradley commented on a diff in the pull request:
https://github.com/apache/spark/pull/5137#discussion_r27336036
--- Diff: python/pyspark/mllib/classification.py ---
@@ -112,11 +122,47 @@ class
LogisticRegressionModel(LinearBinaryClassificationModel):
... os.removedirs(path)
... except:
... pass
+ >>> multi_class_data = [
+ ... LabeledPoint(0.0, [0.0, 1.0, 0.0]),
+ ... LabeledPoint(1.0, [1.0, 0.0, 0.0]),
+ ... LabeledPoint(2.0, [0.0, 0.0, 1.0])
+ ... ]
+ >>> mcm =
LogisticRegressionWithLBFGS.train(data=sc.parallelize(multi_class_data),
numClasses=3)
+ >>> mcm.predict([0.0, 0.5, 0.0])
+ 0
+ >>> mcm.predict([0.8, 0.0, 0.0])
+ 1
+ >>> mcm.predict([0.0, 0.0, 0.3])
+ 2
"""
- def __init__(self, weights, intercept):
+ def __init__(self, weights, intercept, numFeatures, numClasses):
super(LogisticRegressionModel, self).__init__(weights, intercept)
+ self._numFeatures = int(numFeatures)
+ self._numClasses = int(numClasses)
self._threshold = 0.5
+ @property
+ def numFeatures(self):
+ return self._numFeatures
+
+ @property
+ def numClasses(self):
+ return self._numClasses
+
+ @property
+ def dataWithBiasSize(self):
+ return self.weights.size / (self.numClasses - 1)
+
+ @property
+ def weightsMatrix(self):
+ if self.numClasses == 2:
+ return None
+ else:
+ if not isinstance(self.weights, DenseVector):
--- End diff --
Please use _convert_to_vector as in LinearModel. That will check types and
support Python types beyond DenseVector.
---
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]