Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 6893A200C3C for ; Mon, 3 Apr 2017 20:37:49 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6737D160B8D; Mon, 3 Apr 2017 18:37:49 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id B096B160B8F for ; Mon, 3 Apr 2017 20:37:48 +0200 (CEST) Received: (qmail 86554 invoked by uid 500); 3 Apr 2017 18:37:48 -0000 Mailing-List: contact reviews-help@spark.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list reviews@spark.apache.org Received: (qmail 86536 invoked by uid 99); 3 Apr 2017 18:37:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 03 Apr 2017 18:37:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 71272DFBC6; Mon, 3 Apr 2017 18:37:47 +0000 (UTC) From: MLnick To: reviews@spark.apache.org Reply-To: reviews@spark.apache.org References: In-Reply-To: Subject: [GitHub] spark pull request #17494: [SPARK-20076][ML][PySpark] Add Python interface f... Content-Type: text/plain Message-Id: <20170403183747.71272DFBC6@git1-us-west.apache.org> Date: Mon, 3 Apr 2017 18:37:47 +0000 (UTC) archived-at: Mon, 03 Apr 2017 18:37:49 -0000 Github user MLnick commented on a diff in the pull request: https://github.com/apache/spark/pull/17494#discussion_r109492883 --- Diff: python/pyspark/ml/stat.py --- @@ -71,6 +71,62 @@ def test(dataset, featuresCol, labelCol): return _java2py(sc, javaTestObj.test(*args)) +class Correlation(object): + """ + .. note:: Experimental + + Compute the correlation matrix for the input dataset of Vectors using the specified method. + Methods currently supported: `pearson` (default), `spearman`. + + :param dataset: + A dataset or a dataframe. + :param column: + The name of the column of vectors for which the correlation coefficient needs + to be computed. This must be a column of the dataset, and it must contain + Vector objects. + :param method: + String specifying the method to use for computing correlation. + Supported: `pearson` (default), `spearman`. + :return: + A dataframe that contains the correlation matrix of the column of vectors. This + dataframe contains a single row and a single column of name + '$METHODNAME($COLUMN)'. + + >>> from pyspark.ml.linalg import Vectors + >>> from pyspark.ml.stat import Correlation + >>> dataset = [[Vectors.dense([1, 0, 0, -2])], + ... [Vectors.dense([4, 5, 0, 3])], + ... [Vectors.dense([6, 7, 0, 8])], + ... [Vectors.dense([9, 0, 0, 1])]] + >>> dataset = spark.createDataFrame(dataset, ["features"]) + >>> pearsonCorr = Correlation.corr(dataset, 'features', 'pearson').collect()[0][0] + >>> print(str(pearsonCorr).replace('nan', 'NaN')) + DenseMatrix([[ 1. , 0.05564149, NaN, 0.40047142], + [ 0.05564149, 1. , NaN, 0.91359586], + [ NaN, NaN, 1. , NaN], + [ 0.40047142, 0.91359586, NaN, 1. ]]) + >>> spearmanCorr = Correlation.corr(dataset, 'features', method="spearman").collect()[0][0] --- End diff -- Super minor nit - but let's use single `'` everywhere here rather than have a mix of single & double. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. --- --------------------------------------------------------------------- To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org For additional commands, e-mail: reviews-help@spark.apache.org