-
Notifications
You must be signed in to change notification settings - Fork 29k
[Spark-21854] Added LogisticRegressionTrainingSummary for MultinomialLogisticRegression in Python API #19185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
50cfafe
added probabilityCol to LogisticRegressionSummary
60579d5
modified LogisticRegressionSummary and LogisticRegressionModel in cla…
1a73e6c
test on multiclass summary
53ac68e
fixed numClasses
a4755d7
0911 added more test and simplified summary logic
jmwdpk eb8f6b4
added more scala unit tests for binary summary, and additional tests …
jmwdpk 6529fa6
removed extra summary test
jmwdpk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1451,7 +1451,7 @@ def test_glr_summary(self): | |
| sameSummary = model.evaluate(df) | ||
| self.assertAlmostEqual(sameSummary.deviance, s.deviance) | ||
|
|
||
| def test_logistic_regression_summary(self): | ||
| def test_binary_logistic_regression_summary(self): | ||
| df = self.spark.createDataFrame([(1.0, 2.0, Vectors.dense(1.0)), | ||
| (0.0, 2.0, Vectors.sparse(1, [], []))], | ||
| ["label", "weight", "features"]) | ||
|
|
@@ -1464,20 +1464,73 @@ def test_logistic_regression_summary(self): | |
| self.assertEqual(s.probabilityCol, "probability") | ||
| self.assertEqual(s.labelCol, "label") | ||
| self.assertEqual(s.featuresCol, "features") | ||
| self.assertEqual(s.predictionCol, "prediction") | ||
| objHist = s.objectiveHistory | ||
| self.assertTrue(isinstance(objHist, list) and isinstance(objHist[0], float)) | ||
| self.assertGreater(s.totalIterations, 0) | ||
| self.assertTrue(isinstance(s.labels, list)) | ||
| self.assertTrue(isinstance(s.truePositiveRateByLabel, list)) | ||
| self.assertTrue(isinstance(s.falsePositiveRateByLabel, list)) | ||
| self.assertTrue(isinstance(s.precisionByLabel, list)) | ||
| self.assertTrue(isinstance(s.recallByLabel, list)) | ||
| self.assertTrue(isinstance(s.fMeasureByLabel(), list)) | ||
| self.assertTrue(isinstance(s.fMeasureByLabel(1.0), list)) | ||
| self.assertTrue(isinstance(s.roc, DataFrame)) | ||
| self.assertAlmostEqual(s.areaUnderROC, 1.0, 2) | ||
| self.assertTrue(isinstance(s.pr, DataFrame)) | ||
| self.assertTrue(isinstance(s.fMeasureByThreshold, DataFrame)) | ||
| self.assertTrue(isinstance(s.precisionByThreshold, DataFrame)) | ||
| self.assertTrue(isinstance(s.recallByThreshold, DataFrame)) | ||
| self.assertAlmostEqual(s.accuracy, 1.0, 2) | ||
| self.assertAlmostEqual(s.weightedTruePositiveRate, 1.0, 2) | ||
| self.assertAlmostEqual(s.weightedFalsePositiveRate, 0.0, 2) | ||
| self.assertAlmostEqual(s.weightedRecall, 1.0, 2) | ||
| self.assertAlmostEqual(s.weightedPrecision, 1.0, 2) | ||
| self.assertAlmostEqual(s.weightedFMeasure(), 1.0, 2) | ||
| self.assertAlmostEqual(s.weightedFMeasure(1.0), 1.0, 2) | ||
| # test evaluation (with training dataset) produces a summary with same values | ||
| # one check is enough to verify a summary is returned, Scala version runs full test | ||
| sameSummary = model.evaluate(df) | ||
| self.assertAlmostEqual(sameSummary.areaUnderROC, s.areaUnderROC) | ||
|
|
||
| def test_multiclass_logistic_regression_summary(self): | ||
| df = self.spark.createDataFrame([(1.0, 2.0, Vectors.dense(1.0)), | ||
| (0.0, 2.0, Vectors.sparse(1, [], [])), | ||
| (2.0, 2.0, Vectors.dense(2.0)), | ||
| (2.0, 2.0, Vectors.dense(1.9))], | ||
| ["label", "weight", "features"]) | ||
| lr = LogisticRegression(maxIter=5, regParam=0.01, weightCol="weight", fitIntercept=False) | ||
| model = lr.fit(df) | ||
| self.assertTrue(model.hasSummary) | ||
| s = model.summary | ||
| # test that api is callable and returns expected types | ||
| self.assertTrue(isinstance(s.predictions, DataFrame)) | ||
| self.assertEqual(s.probabilityCol, "probability") | ||
| self.assertEqual(s.labelCol, "label") | ||
| self.assertEqual(s.featuresCol, "features") | ||
| self.assertEqual(s.predictionCol, "prediction") | ||
| objHist = s.objectiveHistory | ||
| self.assertTrue(isinstance(objHist, list) and isinstance(objHist[0], float)) | ||
| self.assertGreater(s.totalIterations, 0) | ||
| self.assertTrue(isinstance(s.labels, list)) | ||
| self.assertTrue(isinstance(s.truePositiveRateByLabel, list)) | ||
| self.assertTrue(isinstance(s.falsePositiveRateByLabel, list)) | ||
| self.assertTrue(isinstance(s.precisionByLabel, list)) | ||
| self.assertTrue(isinstance(s.recallByLabel, list)) | ||
| self.assertTrue(isinstance(s.fMeasureByLabel(), list)) | ||
| self.assertTrue(isinstance(s.fMeasureByLabel(1.0), list)) | ||
| self.assertAlmostEqual(s.accuracy, 0.75, 2) | ||
| self.assertAlmostEqual(s.weightedTruePositiveRate, 0.75, 2) | ||
| self.assertAlmostEqual(s.weightedFalsePositiveRate, 0.25, 2) | ||
| self.assertAlmostEqual(s.weightedRecall, 0.75, 2) | ||
| self.assertAlmostEqual(s.weightedPrecision, 0.583, 2) | ||
| self.assertAlmostEqual(s.weightedFMeasure(), 0.65, 2) | ||
| self.assertAlmostEqual(s.weightedFMeasure(1.0), 0.65, 2) | ||
| # test evaluation (with training dataset) produces a summary with same values | ||
| # one check is enough to verify a summary is returned, Scala version runs full test | ||
| sameSummary = model.evaluate(df) | ||
| self.assertAlmostEqual(sameSummary.accuracy, s.accuracy) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Like mentioned in annotation, one check is enough to verify a summary is returned, let's remove others to simplify the test. Thanks. |
||
|
|
||
| def test_gaussian_mixture_summary(self): | ||
| data = [(Vectors.dense(1.0),), (Vectors.dense(5.0),), (Vectors.dense(10.0),), | ||
| (Vectors.sparse(1, [], []),)] | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe add
beta=1.0to the methods that take beta as a parameter.