-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-9312] [ML] Added max confidence factor to OneVsRestModel #7652
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
8 commits
Select commit
Hold shift + click to select a range
f4e2089
Added predictive probability to OneVsRestModel and LogisticRegression…
badriub 8bfd54c
SPARK-9312: Adding confidence factor to OneVsRest Model
badriub c4a3c29
SPARK-9312: Undoing changes for the LogisticRegression related to
badriub d758972
Correcting indentation
badriub 095774f
Implementing review comments
badriub e3e858f
Merge branch 'master' of https://github.com/badriub/spark.git
badriub a18dab6
Import order corrected
badriub 3950a5b
Missed fixing a doc earlier
badriub 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,18 +24,19 @@ import scala.language.existentials | |
| import org.apache.spark.annotation.Experimental | ||
| import org.apache.spark.ml._ | ||
| import org.apache.spark.ml.attribute._ | ||
| import org.apache.spark.ml.param.shared.HasRawPredictionCol | ||
| import org.apache.spark.ml.param.{Param, ParamMap} | ||
| import org.apache.spark.ml.util.{Identifiable, MetadataUtils} | ||
| import org.apache.spark.mllib.linalg.Vector | ||
| import org.apache.spark.sql.{DataFrame, Row} | ||
| import org.apache.spark.sql.functions._ | ||
| import org.apache.spark.sql.types._ | ||
| import org.apache.spark.sql.{DataFrame, Row} | ||
| import org.apache.spark.storage.StorageLevel | ||
|
|
||
| /** | ||
| * Params for [[OneVsRest]]. | ||
| */ | ||
| private[ml] trait OneVsRestParams extends PredictorParams { | ||
| private[ml] trait OneVsRestParams extends ClassifierParams { | ||
|
|
||
| // scalastyle:off structural.type | ||
| type ClassifierType = Classifier[F, E, M] forSome { | ||
|
|
@@ -127,10 +128,16 @@ final class OneVsRestModel private[ml] ( | |
| predictions.maxBy(_._2)._1.toDouble | ||
| } | ||
|
|
||
| // output label and label metadata as prediction | ||
| // output the highest confidence as rawPredictionCol | ||
| val probabilityUDF = udf { (predictions: Map[Int, Double]) => | ||
| predictions.maxBy(_._2)._2.toDouble | ||
| } | ||
|
|
||
| // output label, confidence factor and label metadata as prediction | ||
| aggregatedDataset | ||
| .withColumn($(predictionCol), labelUDF(col(accColName)).as($(predictionCol), labelMetadata)) | ||
| .drop(accColName) | ||
| .withColumn($(rawPredictionCol), probabilityUDF(col(accColName)).as($(rawPredictionCol), | ||
| labelMetadata)).drop(accColName) | ||
| } | ||
|
Author
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. Adding the max confidence factor as output column. |
||
|
|
||
| override def copy(extra: ParamMap): OneVsRestModel = { | ||
|
|
@@ -220,4 +227,5 @@ final class OneVsRest(override val uid: String) | |
| } | ||
| copied | ||
| } | ||
|
|
||
| } | ||
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
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.
This is outputting a Double, but it should return a Vector with one value for each class label. Actually, the output value should be the accCol converted to a Vector.
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.
Sorry for the delayed response. I've made some small changes as per your recommendations. WRT this point, I'm not sure I follow. As far as I understand, I need to return the highest confidence factor(which will be Double) corresponding to the model used with OVR.