Uh oh!
There was an error while loading. Please reload this page.
[SPARK-15509][ML][SparkR] R MLlib algorithms should support input columns "features" and "label" - #13584
[SPARK-15509][ML][SparkR] R MLlib algorithms should support input columns "features" and "label"#13584keypointt wants to merge 14 commits into
Conversation
SparkQA
commented
Jun 10, 2016
Test build #60261 has finished for PR 13584 at commit
|
keypointt
commented
Jun 17, 2016
hi @jkbradley do you mind have a look on this one? thanks a lot :) |
shivaram
commented
Jun 17, 2016
@jkbradley Is this important for 2.0 ? |
shivaram
commented
Jun 21, 2016
cc @mengxr |
shivaram
commented
Aug 24, 2016
@keypointt Is this PR still relevant ? |
keypointt
commented
Aug 24, 2016
I'm not sure, I guess this one is skipped and not important anymore? I can close it if it's not going to be merged |
shivaram
commented
Aug 24, 2016
junyangq
commented
Aug 25, 2016
@keypointt Can we keep searching (in random or sequential way) until an unused column name has been found? |
keypointt
commented
Aug 25, 2016
sure I'll try to scan through all the mllib algorithms |
junyangq
commented
Aug 25, 2016
@shivaram Does it sound reasonable to you? Just discussed this with @jkbradley. |
shivaram
commented
Aug 25, 2016
Yeah I was going to say that we need to handle cases where |
junyangq
commented
Aug 25, 2016
Sounds good. That's also what we meant. |
| test("avoid column name conflicting") { | ||
| val rFormula = new RFormula().setFormula("label ~ features") | ||
| val data = spark.read.format("libsvm").load("../data/mllib/sample_libsvm_data.txt") |
There was a problem hiding this comment.
Here I used "../data/", I'm not sure if there is a better way to do it, something like $current_directory/data/mllib/sample_libsvm_data.txt?
All I found is like this val data = spark.read.format("libsvm").load("data/mllib/sample_libsvm_data.txt")https://github.com/apache/spark/blob/master/examples/src/main/scala/org/apache/spark/examples/ml/NaiveBayesExample.scala#L36
SparkQA
commented
Aug 29, 2016
Test build #64578 has finished for PR 13584 at commit
|
| */ | ||
| def checkDataColumns(rFormula: RFormula, data: Dataset[_]): Unit = { | ||
| if (data.schema.fieldNames.contains(rFormula.getLabelCol)) { | ||
| logWarning("data containing 'label' column, so change its name to avoid conflict") |
There was a problem hiding this comment.
is it possible to include the featurecol name in logging?
…mn name has been found
SparkQA
commented
Sep 1, 2016
Test build #64764 has finished for PR 13584 at commit
|
SparkQA
commented
Sep 1, 2016
Test build #64765 has finished for PR 13584 at commit
|
junyangq
commented
Sep 1, 2016
LGTM |
| rFormula.setLabelCol(rFormula.getLabelCol + "_output") | ||
| val newLabelName = convertToUniqueName(rFormula.getLabelCol, data.schema.fieldNames) | ||
| logWarning( | ||
| s"data containing ${rFormula.getLabelCol} column, changing its name to $newLabelName") |
There was a problem hiding this comment.
this sounds a bit like we are renaming the existing label column?
perhaps just change to s"data containing ${rFormula.getLabelCol} column, using new name to $newLabelName instead"?
| rFormula.setFeaturesCol(rFormula.getFeaturesCol + "_output") | ||
| val newFeaturesName = convertToUniqueName(rFormula.getFeaturesCol, data.schema.fieldNames) | ||
| logWarning( | ||
| s"data containing ${rFormula.getFeaturesCol} column, changing its name to $newFeaturesName") |
SparkQA
commented
Sep 2, 2016
Test build #64811 has finished for PR 13584 at commit
|
SparkQA
commented
Sep 2, 2016
Test build #64813 has finished for PR 13584 at commit
|
felixcheung
commented
Sep 2, 2016
LGTM. @shivaram do you have any other comment? |
shivaram
commented
Sep 2, 2016
LGTM - @felixcheung Feel free to merge when its ready |
felixcheung
commented
Sep 2, 2016
Merged. I could't change the assignee in the JIRA, somehow - @shivaram could you please do that? |
…t input columns "features" and "label" ## What changes were proposed in this pull request? apache#13584 resolved the issue of features and label columns conflict with ```RFormula``` default ones when loading libsvm data, but it still left some issues should be resolved: 1, It’s not necessary to check and rename label column. Since we have considerations on the design of ```RFormula```, it can handle the case of label column already exists(with restriction of the existing label column should be numeric/boolean type). So it’s not necessary to change the column name to avoid conflict. If the label column is not numeric/boolean type, ```RFormula``` will throw exception. 2, We should rename features column name to new one if there is conflict, but appending a random value is enough since it was used internally only. We done similar work when implementing ```SQLTransformer```. 3, We should set correct new features column for the estimators. Take ```GLM``` as example: ```GLM``` estimator should set features column with the changed one(rFormula.getFeaturesCol) rather than the default “features”. Although it’s same when training model, but it involves problems when predicting. The following is the prediction result of GLM before this PR:  We should drop the internal used feature column name, otherwise, it will appear on the prediction DataFrame which will confused users. And this behavior is same as other scenarios which does not exist column name conflict. After this PR:  ## How was this patch tested? Existing unit tests. Author: Yanbo Liang <ybliang8@gmail.com> Closesapache#14993 from yanboliang/spark-15509.
…t input columns "features" and "label" ## What changes were proposed in this pull request? apache#13584 resolved the issue of features and label columns conflict with ```RFormula``` default ones when loading libsvm data, but it still left some issues should be resolved: 1, It’s not necessary to check and rename label column. Since we have considerations on the design of ```RFormula```, it can handle the case of label column already exists(with restriction of the existing label column should be numeric/boolean type). So it’s not necessary to change the column name to avoid conflict. If the label column is not numeric/boolean type, ```RFormula``` will throw exception. 2, We should rename features column name to new one if there is conflict, but appending a random value is enough since it was used internally only. We done similar work when implementing ```SQLTransformer```. 3, We should set correct new features column for the estimators. Take ```GLM``` as example: ```GLM``` estimator should set features column with the changed one(rFormula.getFeaturesCol) rather than the default “features”. Although it’s same when training model, but it involves problems when predicting. The following is the prediction result of GLM before this PR:  We should drop the internal used feature column name, otherwise, it will appear on the prediction DataFrame which will confused users. And this behavior is same as other scenarios which does not exist column name conflict. After this PR:  ## How was this patch tested? Existing unit tests. Author: Yanbo Liang <ybliang8@gmail.com> Closesapache#14993 from yanboliang/spark-15509.
https://issues.apache.org/jira/browse/SPARK-15509
What changes were proposed in this pull request?
Currently in SparkR, when you load a LibSVM dataset using the sqlContext and then pass it to an MLlib algorithm, the ML wrappers will fail since they will try to create a "features" column, which conflicts with the existing "features" column from the LibSVM loader. E.g., using the "mnist" dataset from LibSVM:
training <- loadDF(sqlContext, ".../mnist", "libsvm")model <- naiveBayes(label ~ features, training)This fails with:
The cause is, when using
loadDF()to generate dataframes, sometimes it’s with default column name“label”and“features”, and these two name will conflict with default column namessetDefault(labelCol, "label")andsetDefault(featuresCol, "features")ofSharedParams.scalaHow was this patch tested?
Test on my local machine.