{"action":"created","comment":{"url":"https://api.github.com/repos/databricks/spark-sklearn/pulls/comments/68615235","id":68615235,"diff_hunk":"@@ -0,0 +1,237 @@\n+\n+from itertools import chain, repeat, cycle\n+import numpy as np\n+import pandas as pd\n+from sklearn.decomposition import PCA\n+from sklearn.linear_model import LinearRegression\n+from sklearn.linear_model import LogisticRegression\n+import unittest\n+\n+from pyspark.sql.types import *\n+from pyspark.ml.linalg import Vectors\n+import sklearn.base\n+\n+from spark_sklearn import KeyedEstimator, KeyedModel, SparkSklearnEstimator\n+from spark_sklearn.test_utils import fixtureReuseSparkSession, assertPandasAlmostEqual\n+\n+def _sortByComponentWeight(pca):\n+    zipped = zip(pca.components_, pca.explained_variance_ratio_)\n+    ordered = sorted(zipped, key=lambda x: x[1])\n+    return tuple(np.array(unzipped) for unzipped in zip(*ordered))\n+\n+def _assertPandasAlmostEqual(actual, expected, sortby):\n+    def convert_estimators(x): # note convertion makes estimators invariant to training order.\n+        if isinstance(x, SparkSklearnEstimator): x = x.estimator\n+        if isinstance(x, LinearRegression) or isinstance(x, LogisticRegression):\n+            return x.coef_, x.intercept_\n+        if isinstance(x, PCA):\n+            return _sortByComponentWeight(x)\n+        return x\n+    assertPandasAlmostEqual(actual, expected, convert=convert_estimators, sortby=sortby)\n+\n+@fixtureReuseSparkSession\n+class KeyedModelTests(unittest.TestCase):\n+\n+    class _CustomTransformer(sklearn.base.BaseEstimator):\n+        def fit(X, y=None):\n+            pass","path":"python/spark_sklearn/tests/test_keyed_models.py","position":37,"original_position":37,"commit_id":"914ee33ffe15332ab2243a9bdd9be61d31a12d23","original_commit_id":"914ee33ffe15332ab2243a9bdd9be61d31a12d23","user":{"login":"vlad17","id":5834964,"avatar_url":"https://avatars.githubusercontent.com/u/5834964?v=3","gravatar_id":"","url":"https://api.github.com/users/vlad17","html_url":"https://github.com/vlad17","followers_url":"https://api.github.com/users/vlad17/followers","following_url":"https://api.github.com/users/vlad17/following{/other_user}","gists_url":"https://api.github.com/users/vlad17/gists{/gist_id}","starred_url":"https://api.github.com/users/vlad17/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vlad17/subscriptions","organizations_url":"https://api.github.com/users/vlad17/orgs","repos_url":"https://api.github.com/users/vlad17/repos","events_url":"https://api.github.com/users/vlad17/events{/privacy}","received_events_url":"https://api.github.com/users/vlad17/received_events","type":"User","site_admin":false},"body":"The paper's in the works.","created_at":"2016-06-27T17:03:42Z","updated_at":"2016-06-27T17:03:42Z","html_url":"https://github.com/databricks/spark-sklearn/pull/26#discussion_r68615235","pull_request_url":"https://api.github.com/repos/databricks/spark-sklearn/pulls/26","_links":{"self":{"href":"https://api.github.com/repos/databricks/spark-sklearn/pulls/comments/68615235"},"html":{"href":"https://github.com/databricks/spark-sklearn/pull/26#discussion_r68615235"},"pull_request":{"href":"https://api.github.com/repos/databricks/spark-sklearn/pulls/26"}}},"pull_request":{"url":"https://api.github.com/repos/databricks/spark-sklearn/pulls/26","id":75186308,"html_url":"https://github.com/databricks/spark-sklearn/pull/26","diff_url":"https://github.com/databricks/spark-sklearn/pull/26.diff","patch_url":"https://github.com/databricks/spark-sklearn/pull/26.patch","issue_url":"https://api.github.com/repos/databricks/spark-sklearn/issues/26","number":26,"state":"open","locked":false,"title":"High level api","user":{"login":"vlad17","id":5834964,"avatar_url":"https://avatars.githubusercontent.com/u/5834964?v=3","gravatar_id":"","url":"https://api.github.com/users/vlad17","html_url":"https://github.com/vlad17","followers_url":"https://api.github.com/users/vlad17/followers","following_url":"https://api.github.com/users/vlad17/following{/other_user}","gists_url":"https://api.github.com/users/vlad17/gists{/gist_id}","starred_url":"https://api.github.com/users/vlad17/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vlad17/subscriptions","organizations_url":"https://api.github.com/users/vlad17/orgs","repos_url":"https://api.github.com/users/vlad17/repos","events_url":"https://api.github.com/users/vlad17/events{/privacy}","received_events_url":"https://api.github.com/users/vlad17/received_events","type":"User","site_admin":false},"body":"This commit adds the high-level KeyedModels API, which enables users to train scikit-learn estimators on grouped data.\r\n\r\nTesting done via unit tests (note some edge case functionality is not offered / tests are skipped until associated spark JIRAs are resolved).\r\n\r\nSome additional refactoring in test_gapply was done to extract common pandas dataframe functionality.","created_at":"2016-06-24T23:23:44Z","updated_at":"2016-06-27T17:03:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3ad569f1d8410834bfff59d022ad668a94a281c7","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/databricks/spark-sklearn/pulls/26/commits","review_comments_url":"https://api.github.com/repos/databricks/spark-sklearn/pulls/26/comments","review_comment_url":"https://api.github.com/repos/databricks/spark-sklearn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/databricks/spark-sklearn/issues/26/comments","statuses_url":"https://api.github.com/repos/databricks/spark-sklearn/statuses/914ee33ffe15332ab2243a9bdd9be61d31a12d23","head":{"label":"vlad17:high-level-api","ref":"high-level-api","sha":"914ee33ffe15332ab2243a9bdd9be61d31a12d23","user":{"login":"vlad17","id":5834964,"avatar_url":"https://avatars.githubusercontent.com/u/5834964?v=3","gravatar_id":"","url":"https://api.github.com/users/vlad17","html_url":"https://github.com/vlad17","followers_url":"https://api.github.com/users/vlad17/followers","following_url":"https://api.github.com/users/vlad17/following{/other_user}","gists_url":"https://api.github.com/users/vlad17/gists{/gist_id}","starred_url":"https://api.github.com/users/vlad17/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vlad17/subscriptions","organizations_url":"https://api.github.com/users/vlad17/orgs","repos_url":"https://api.github.com/users/vlad17/repos","events_url":"https://api.github.com/users/vlad17/events{/privacy}","received_events_url":"https://api.github.com/users/vlad17/received_events","type":"User","site_admin":false},"repo":{"id":61221264,"name":"spark-sklearn","full_name":"vlad17/spark-sklearn","owner":{"login":"vlad17","id":5834964,"avatar_url":"https://avatars.githubusercontent.com/u/5834964?v=3","gravatar_id":"","url":"https://api.github.com/users/vlad17","html_url":"https://github.com/vlad17","followers_url":"https://api.github.com/users/vlad17/followers","following_url":"https://api.github.com/users/vlad17/following{/other_user}","gists_url":"https://api.github.com/users/vlad17/gists{/gist_id}","starred_url":"https://api.github.com/users/vlad17/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vlad17/subscriptions","organizations_url":"https://api.github.com/users/vlad17/orgs","repos_url":"https://api.github.com/users/vlad17/repos","events_url":"https://api.github.com/users/vlad17/events{/privacy}","received_events_url":"https://api.github.com/users/vlad17/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/vlad17/spark-sklearn","description":"Scikit-learn integration package for Spark","fork":true,"url":"https://api.github.com/repos/vlad17/spark-sklearn","forks_url":"https://api.github.com/repos/vlad17/spark-sklearn/forks","keys_url":"https://api.github.com/repos/vlad17/spark-sklearn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/vlad17/spark-sklearn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/vlad17/spark-sklearn/teams","hooks_url":"https://api.github.com/repos/vlad17/spark-sklearn/hooks","issue_events_url":"https://api.github.com/repos/vlad17/spark-sklearn/issues/events{/number}","events_url":"https://api.github.com/repos/vlad17/spark-sklearn/events","assignees_url":"https://api.github.com/repos/vlad17/spark-sklearn/assignees{/user}","branches_url":"https://api.github.com/repos/vlad17/spark-sklearn/branches{/branch}","tags_url":"https://api.github.com/repos/vlad17/spark-sklearn/tags","blobs_url":"https://api.github.com/repos/vlad17/spark-sklearn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/vlad17/spark-sklearn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/vlad17/spark-sklearn/git/refs{/sha}","trees_url":"https://api.github.com/repos/vlad17/spark-sklearn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/vlad17/spark-sklearn/statuses/{sha}","languages_url":"https://api.github.com/repos/vlad17/spark-sklearn/languages","stargazers_url":"https://api.github.com/repos/vlad17/spark-sklearn/stargazers","contributors_url":"https://api.github.com/repos/vlad17/spark-sklearn/contributors","subscribers_url":"https://api.github.com/repos/vlad17/spark-sklearn/subscribers","subscription_url":"https://api.github.com/repos/vlad17/spark-sklearn/subscription","commits_url":"https://api.github.com/repos/vlad17/spark-sklearn/commits{/sha}","git_commits_url":"https://api.github.com/repos/vlad17/spark-sklearn/git/commits{/sha}","comments_url":"https://api.github.com/repos/vlad17/spark-sklearn/comments{/number}","issue_comment_url":"https://api.github.com/repos/vlad17/spark-sklearn/issues/comments{/number}","contents_url":"https://api.github.com/repos/vlad17/spark-sklearn/contents/{+path}","compare_url":"https://api.github.com/repos/vlad17/spark-sklearn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/vlad17/spark-sklearn/merges","archive_url":"https://api.github.com/repos/vlad17/spark-sklearn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/vlad17/spark-sklearn/downloads","issues_url":"https://api.github.com/repos/vlad17/spark-sklearn/issues{/number}","pulls_url":"https://api.github.com/repos/vlad17/spark-sklearn/pulls{/number}","milestones_url":"https://api.github.com/repos/vlad17/spark-sklearn/milestones{/number}","notifications_url":"https://api.github.com/repos/vlad17/spark-sklearn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/vlad17/spark-sklearn/labels{/name}","releases_url":"https://api.github.com/repos/vlad17/spark-sklearn/releases{/id}","deployments_url":"https://api.github.com/repos/vlad17/spark-sklearn/deployments","created_at":"2016-06-15T16:00:20Z","updated_at":"2016-06-27T16:06:28Z","pushed_at":"2016-06-27T16:06:27Z","git_url":"git://github.com/vlad17/spark-sklearn.git","ssh_url":"git@github.com:vlad17/spark-sklearn.git","clone_url":"https://github.com/vlad17/spark-sklearn.git","svn_url":"https://github.com/vlad17/spark-sklearn","homepage":"","size":431,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"databricks:master","ref":"master","sha":"922aee935743c4ab1f170d16e37cb968323ebf9d","user":{"login":"databricks","id":4998052,"avatar_url":"https://avatars.githubusercontent.com/u/4998052?v=3","gravatar_id":"","url":"https://api.github.com/users/databricks","html_url":"https://github.com/databricks","followers_url":"https://api.github.com/users/databricks/followers","following_url":"https://api.github.com/users/databricks/following{/other_user}","gists_url":"https://api.github.com/users/databricks/gists{/gist_id}","starred_url":"https://api.github.com/users/databricks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/databricks/subscriptions","organizations_url":"https://api.github.com/users/databricks/orgs","repos_url":"https://api.github.com/users/databricks/repos","events_url":"https://api.github.com/users/databricks/events{/privacy}","received_events_url":"https://api.github.com/users/databricks/received_events","type":"Organization","site_admin":false},"repo":{"id":41820544,"name":"spark-sklearn","full_name":"databricks/spark-sklearn","owner":{"login":"databricks","id":4998052,"avatar_url":"https://avatars.githubusercontent.com/u/4998052?v=3","gravatar_id":"","url":"https://api.github.com/users/databricks","html_url":"https://github.com/databricks","followers_url":"https://api.github.com/users/databricks/followers","following_url":"https://api.github.com/users/databricks/following{/other_user}","gists_url":"https://api.github.com/users/databricks/gists{/gist_id}","starred_url":"https://api.github.com/users/databricks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/databricks/subscriptions","organizations_url":"https://api.github.com/users/databricks/orgs","repos_url":"https://api.github.com/users/databricks/repos","events_url":"https://api.github.com/users/databricks/events{/privacy}","received_events_url":"https://api.github.com/users/databricks/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/databricks/spark-sklearn","description":"Scikit-learn integration package for Spark","fork":false,"url":"https://api.github.com/repos/databricks/spark-sklearn","forks_url":"https://api.github.com/repos/databricks/spark-sklearn/forks","keys_url":"https://api.github.com/repos/databricks/spark-sklearn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/databricks/spark-sklearn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/databricks/spark-sklearn/teams","hooks_url":"https://api.github.com/repos/databricks/spark-sklearn/hooks","issue_events_url":"https://api.github.com/repos/databricks/spark-sklearn/issues/events{/number}","events_url":"https://api.github.com/repos/databricks/spark-sklearn/events","assignees_url":"https://api.github.com/repos/databricks/spark-sklearn/assignees{/user}","branches_url":"https://api.github.com/repos/databricks/spark-sklearn/branches{/branch}","tags_url":"https://api.github.com/repos/databricks/spark-sklearn/tags","blobs_url":"https://api.github.com/repos/databricks/spark-sklearn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/databricks/spark-sklearn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/databricks/spark-sklearn/git/refs{/sha}","trees_url":"https://api.github.com/repos/databricks/spark-sklearn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/databricks/spark-sklearn/statuses/{sha}","languages_url":"https://api.github.com/repos/databricks/spark-sklearn/languages","stargazers_url":"https://api.github.com/repos/databricks/spark-sklearn/stargazers","contributors_url":"https://api.github.com/repos/databricks/spark-sklearn/contributors","subscribers_url":"https://api.github.com/repos/databricks/spark-sklearn/subscribers","subscription_url":"https://api.github.com/repos/databricks/spark-sklearn/subscription","commits_url":"https://api.github.com/repos/databricks/spark-sklearn/commits{/sha}","git_commits_url":"https://api.github.com/repos/databricks/spark-sklearn/git/commits{/sha}","comments_url":"https://api.github.com/repos/databricks/spark-sklearn/comments{/number}","issue_comment_url":"https://api.github.com/repos/databricks/spark-sklearn/issues/comments{/number}","contents_url":"https://api.github.com/repos/databricks/spark-sklearn/contents/{+path}","compare_url":"https://api.github.com/repos/databricks/spark-sklearn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/databricks/spark-sklearn/merges","archive_url":"https://api.github.com/repos/databricks/spark-sklearn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/databricks/spark-sklearn/downloads","issues_url":"https://api.github.com/repos/databricks/spark-sklearn/issues{/number}","pulls_url":"https://api.github.com/repos/databricks/spark-sklearn/pulls{/number}","milestones_url":"https://api.github.com/repos/databricks/spark-sklearn/milestones{/number}","notifications_url":"https://api.github.com/repos/databricks/spark-sklearn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/databricks/spark-sklearn/labels{/name}","releases_url":"https://api.github.com/repos/databricks/spark-sklearn/releases{/id}","deployments_url":"https://api.github.com/repos/databricks/spark-sklearn/deployments","created_at":"2015-09-02T18:44:51Z","updated_at":"2016-06-27T07:39:55Z","pushed_at":"2016-06-25T01:33:25Z","git_url":"git://github.com/databricks/spark-sklearn.git","ssh_url":"git@github.com:databricks/spark-sklearn.git","clone_url":"https://github.com/databricks/spark-sklearn.git","svn_url":"https://github.com/databricks/spark-sklearn","homepage":"","size":262,"stargazers_count":173,"watchers_count":173,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":35,"mirror_url":null,"open_issues_count":4,"forks":35,"open_issues":4,"watchers":173,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/databricks/spark-sklearn/pulls/26"},"html":{"href":"https://github.com/databricks/spark-sklearn/pull/26"},"issue":{"href":"https://api.github.com/repos/databricks/spark-sklearn/issues/26"},"comments":{"href":"https://api.github.com/repos/databricks/spark-sklearn/issues/26/comments"},"review_comments":{"href":"https://api.github.com/repos/databricks/spark-sklearn/pulls/26/comments"},"review_comment":{"href":"https://api.github.com/repos/databricks/spark-sklearn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/databricks/spark-sklearn/pulls/26/commits"},"statuses":{"href":"https://api.github.com/repos/databricks/spark-sklearn/statuses/914ee33ffe15332ab2243a9bdd9be61d31a12d23"}}}}
{"actor":{"display_login":"vlad17"}}