Skip to content

[SPARK-18385][ML] Make the transformer's natively in ml framework to avoid extra conversion - #15831

Closed
techaddict wants to merge 5 commits into
apache:masterfrom
techaddict:ml-transformer
Closed

[SPARK-18385][ML] Make the transformer's natively in ml framework to avoid extra conversion#15831
techaddict wants to merge 5 commits into
apache:masterfrom
techaddict:ml-transformer

Conversation

@techaddict

@techaddicttechaddict commented Nov 9, 2016

Copy link
Copy Markdown
Contributor

What changes were proposed in this pull request?

Follow Up of SPARK-14615
Transformer's added in ml framework to avoid extra conversion for:
ChiSqSelector
IDF
StandardScaler
PCA

How was this patch tested?

Existing Tests

@techaddict

Copy link
Copy Markdown
ContributorAuthor

cc: @dbtsai@mengxr

@SparkQA

Copy link
Copy Markdown

Test build #68410 has finished for PR 15831 at commit a9483ef.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@SparkQA

Copy link
Copy Markdown

Test build #68411 has finished for PR 15831 at commit 89e6858.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@sethah

sethah commented Nov 17, 2016

Copy link
Copy Markdown
Contributor

I see this patch was created as a result of the PR that separated the ml/mllib linalg packages, to avoid some inefficiencies in conversion. However, it also is a partial step toward feature parity. Typically, we would port full algorithms all at once, instead of just porting the transformer functionality as is done here, but I understand that this is not just about parity. I would suggest one of the following:

  1. Port over full feature functionality. This increases the scope and therefore the algos should probably separated out individually into PRs.
  2. Keep the scope the same, but avoid copying code.

For an example of option 2, for ChiSqSelector, we can implement new static methods in the mllib.ChiSqSelectorModel:

private[spark] defcompressDense(
selectedFeatures: Array[Int],
values: Array[Double]):Array[Double] = {
selectedFeatures.map(i => values(i))
}
private[spark] defcompressSparse(
compressedSize: Int,
selectedFeatures: Array[Int],
indices: Array[Int],
values: Array[Double]): (Array[Int], Array[Double]) = {
...
}

then in the actual model classes we can just do something like:

privatedefcompress(features: Vector):Vector= {
features match {
caseSparseVector(_, indices, values) =>valnewSize= selectedFeatures.length
val (newIndices, newValues) =ChiSqSelectorModel.compressSparse(newSize, selectedFeatures, indices, values)
Vectors.sparse(newSize, newIndices, newValues)
caseDenseVector(values) =>Vectors.dense(ChiSqSelectorModel.compressDense(selectedFeatures, values))
}
}

This approach would allow us to avoid copying a lot of code until we do full feature ports. What are others opinions? I lean towards the second option since it keeps the scope reasonable.

cc @dbtsai@yanboliang

case DenseVector(values) =>
val values = features.toArray
Vectors.dense(selectedFeatures.map(i => values(i)))
case other =>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw there is no reason to have this case since Vector is a sealed trait

@techaddict

Copy link
Copy Markdown
ContributorAuthor

@sethah I agree, 2nd approach is much more reasonable.

@yanboliang

Copy link
Copy Markdown
Contributor

@techaddict@sethah I'm more prefer option 1, since we would like to remove spark.mllib package in a future release(may be 3.0) and we wouldn't like to make any change to it except bug fix. Could you make this improvement separately for relevant algorithms? Thanks.

@techaddict

Copy link
Copy Markdown
ContributorAuthor

@sethah@yanboliang I've started with migrating IDF, can you review the WIP and if i'm going in the right direction https://github.com/techaddict/spark/pull/2/files
there is some code duplication were we can make mllib code actually depend on the ml one

@MLnick

MLnick commented Dec 1, 2016

Copy link
Copy Markdown
Contributor

I'm also generally supportive of (1) - porting the code to ml and having the mllib code wrap the ml version - this is the approach for other models that have been done. Of course only once allmllib code has been ported over fully can we ultimately deprecate mllib.

I guess we can start doing this for some transformers like these - but ideally we should focus on porting stuff that's still missing in ml first.

I'd prefer that we create a top-level JIRA to track all the components that need to be done, and link everything appropriately. We also need to decide on priority - we may realistically be working on it over a 1-1.5 year time frame (of course hopefully it will take a lot shorter).

@techaddict

Copy link
Copy Markdown
ContributorAuthor

@MLnick I will create a umbrella jira and start adding jira's for things I'm aware of of and you can start prioritising 👍 sounds like a plan ?

@zhengruifeng

Copy link
Copy Markdown
Contributor

the same TODO also appear in HashingTF, what about include it in this PR?

@sethah

Copy link
Copy Markdown
Contributor

I think we decided to go a different direction than what is proposed here? Actually, I still think there's merit in fixing the problem without having to do full feature ports. Either way, I'm not sure anyone is still taking on this task, so @zhengruifeng or @techaddict it would be great if you wanted to either revive this PR/help review, or start working on the larger umbrella JIRA and sub tasks...

@techaddict

Copy link
Copy Markdown
ContributorAuthor

@sethah I will revive this pr thanks 👍

@zhengruifeng

Copy link
Copy Markdown
Contributor

@techaddict@sethah I have some time to work on the porting, but I dont find the umbrella JIRA

@HyukjinKwon

Copy link
Copy Markdown
Member

Hi @@techaddict, how is this PR going?

@techaddict

Copy link
Copy Markdown
ContributorAuthor

@HyukjinKwon was busy, will restart this week.

@SparkQA

Copy link
Copy Markdown

Test build #77448 has finished for PR 15831 at commit 89e6858.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@HyukjinKwonHyukjinKwon mentioned this pull request Jun 7, 2017
@asfgitasfgit closed this in b771fedJun 8, 2017
zifeif2 pushed a commit to zifeif2/spark that referenced this pull request Nov 22, 2025
# What changes were proposed in this pull request?
This PR proposes to close stale PRs, mostly the same instances with apache#18017Closesapache#11459Closesapache#13833Closesapache#13720Closesapache#12506Closesapache#12456Closesapache#12252Closesapache#17689Closesapache#17791Closesapache#18163Closesapache#17640Closesapache#17926Closesapache#18163Closesapache#12506Closesapache#18044Closesapache#14036Closesapache#15831Closesapache#14461Closesapache#17638Closesapache#18222
Added:
Closesapache#18045Closesapache#18061Closesapache#18010Closesapache#18041Closesapache#18124Closesapache#18130Closesapache#12217
Added:
Closesapache#16291Closesapache#17480Closesapache#14995
Added:
Closesapache#12835Closesapache#17141
## How was this patch tested?
N/A
Author: hyukjinkwon <gurwls223@gmail.com>
Closesapache#18223 from HyukjinKwon/close-stale-prs.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@techaddict@SparkQA@sethah@yanboliang@MLnick@zhengruifeng@HyukjinKwon