-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21741][ML][PySpark] Python API for DataFrame-based multivariate summarizer #20695
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 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
488d45a
init pr
WeichenXu123 7d3cb1b
update doctest
WeichenXu123 001ff46
update doctest
WeichenXu123 b3e9ddd
update version
WeichenXu123 e64f795
address bago comment
WeichenXu123 21edbcd
merge master & resolve conflicts
WeichenXu123 f7cec51
Merge branch 'master' into py_summarizer
WeichenXu123 20968c1
address comments
WeichenXu123 b91dbeb
fix python style
WeichenXu123 9a4a0ca
address comments
WeichenXu123 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
address comments
- Loading branch information
commit 20968c1101d7c19bd81bf561e47e6b477fe0a19a
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 |
|---|---|---|
|
|
@@ -308,12 +308,12 @@ def normL2(col, weightCol=None): | |
| return Summarizer._get_single_metric(col, weightCol, "normL2") | ||
|
|
||
| @staticmethod | ||
| def _check_param(featureCol, weightCol): | ||
| def _check_param(featuresCol, weightCol): | ||
| if weightCol is None: | ||
| weightCol = lit(1.0) | ||
| if not isinstance(featureCol, Column) or not isinstance(weightCol, Column): | ||
| if not isinstance(featuresCol, Column) or not isinstance(weightCol, Column): | ||
| raise TypeError("featureCol and weightCol should be a Column") | ||
| return featureCol, weightCol | ||
| return featuresCol, weightCol | ||
|
|
||
| @staticmethod | ||
| def _get_single_metric(col, weightCol, metric): | ||
|
|
@@ -339,26 +339,28 @@ def metrics(*metrics): | |
| - normL2: the Euclidian norm for each coefficient. | ||
| - normL1: the L1 norm of each coefficient (sum of the absolute values). | ||
|
|
||
| :param metrics metrics that can be provided. | ||
| :return a Summarizer | ||
| :param metrics: | ||
| metrics that can be provided. | ||
| :return: | ||
| an object of :py:class:`pyspark.ml.stat.SummaryBuilder` | ||
|
|
||
| Note: Currently, the performance of this interface is about 2x~3x slower then using the RDD | ||
| interface. | ||
| """ | ||
| sc = SparkContext._active_spark_context | ||
| js = JavaWrapper._new_java_obj("org.apache.spark.ml.stat.Summarizer.metrics", | ||
| _to_seq(sc, metrics)) | ||
| return SummarizerBuilder(js) | ||
| return SummaryBuilder(js) | ||
|
|
||
|
|
||
| class SummarizerBuilder(object): | ||
| class SummaryBuilder(JavaWrapper): | ||
| """ | ||
| .. note:: Experimental | ||
|
|
||
| A builder object that provides summary statistics about a given column. | ||
|
|
||
| Users should not directly create such builders, but instead use one of the methods in | ||
| :py:class:`pyspark.ml.stat.Summary` | ||
| :py:class:`pyspark.ml.stat.Summarizer` | ||
|
|
||
| .. versionadded:: 2.4.0 | ||
|
|
||
|
|
@@ -367,13 +369,22 @@ def __init__(self, js): | |
| self._js = js | ||
|
|
||
| @since("2.4.0") | ||
| def summary(self, featureCol, weightCol=None): | ||
| def summary(self, featuresCol, weightCol=None): | ||
| """ | ||
| Returns an aggregate object that contains the summary of the column with the requested | ||
| metrics. | ||
|
Member
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. Let's copy the docs for arguments & return value from Scala |
||
|
|
||
| :param featuresCol: | ||
| a column that contains features Vector object. | ||
| :param weightCol | ||
| a column that contains weight value. Default weight is 1.0. | ||
| :return: | ||
| an aggregate column that contains the statistics. The exact content of this | ||
| structure is determined during the creation of the builder. | ||
|
|
||
| """ | ||
| featureCol, weightCol = Summarizer._check_param(featureCol, weightCol) | ||
| return Column(self._js.summary(featureCol._jc, weightCol._jc)) | ||
| featuresCol, weightCol = Summarizer._check_param(featuresCol, weightCol) | ||
| return Column(self._js.summary(featuresCol._jc, weightCol._jc)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
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 should call the super's init method, and it should store js in _java_obj (which is set in the JavaWrapper init).