{"action":"created","issue":{"url":"https://api.github.com/repos/dataPipelineAU/LearningDataMiningWithPython/issues/5","repository_url":"https://api.github.com/repos/dataPipelineAU/LearningDataMiningWithPython","labels_url":"https://api.github.com/repos/dataPipelineAU/LearningDataMiningWithPython/issues/5/labels{/name}","comments_url":"https://api.github.com/repos/dataPipelineAU/LearningDataMiningWithPython/issues/5/comments","events_url":"https://api.github.com/repos/dataPipelineAU/LearningDataMiningWithPython/issues/5/events","html_url":"https://github.com/dataPipelineAU/LearningDataMiningWithPython/issues/5","id":180568834,"number":5,"title":"in ch5 ValueError","user":{"login":"liaoran","id":6219520,"avatar_url":"https://avatars.githubusercontent.com/u/6219520?v=3","gravatar_id":"","url":"https://api.github.com/users/liaoran","html_url":"https://github.com/liaoran","followers_url":"https://api.github.com/users/liaoran/followers","following_url":"https://api.github.com/users/liaoran/following{/other_user}","gists_url":"https://api.github.com/users/liaoran/gists{/gist_id}","starred_url":"https://api.github.com/users/liaoran/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liaoran/subscriptions","organizations_url":"https://api.github.com/users/liaoran/orgs","repos_url":"https://api.github.com/users/liaoran/repos","events_url":"https://api.github.com/users/liaoran/events{/privacy}","received_events_url":"https://api.github.com/users/liaoran/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":8,"created_at":"2016-10-03T06:04:24Z","updated_at":"2016-10-09T09:25:39Z","closed_at":"2016-10-09T09:03:42Z","body":"Code:\r\n```\r\nimport os\r\nimport pandas as pd\r\nimport numpy as np\r\ndata_folder = os.path.join(os.path.expanduser(\"~\"),\"data\",\"Ads\")\r\ndata_filename = os.path.join(data_folder,\"ad.data\")\r\ndef convert_number(x):\r\n    try:\r\n        return float(x)\r\n    except ValueError:\r\n        return np.nan\r\nfrom collections import defaultdict\r\nconverters = defaultdict(convert_number)\r\nconverters[1558] = lambda x:1 if x.strip() == \"ad.\" else 0\r\nads = pd.read_csv(data_filename,header=None,converters=converters)\r\nx = ads.drop(1558,axis=1).values\r\ny = ads[1558]\r\nfrom sklearn.decomposition import PCA\r\npca = PCA(n_components=5)\r\nxd = pca.fit_transform(x)\r\nnp.set_printoptions(precision=3,suppress=True)\r\npca.explained_variance_ratio_\r\n```\r\nError:\r\n```\r\n---------------------------------------------------------------------------\r\nValueError                                Traceback (most recent call last)\r\n<ipython-input-17-0c33a13666bd> in <module>()\r\n      1 from sklearn.decomposition import PCA\r\n      2 pca = PCA(n_components=5)\r\n----> 3 xd = pca.fit_transform(x)\r\n      4 import numpy as np\r\n      5 np.set_printoptions(precision=3,suppress=True)\r\n\r\n/home/kongnian/anaconda3/lib/python3.5/site-packages/sklearn/decomposition/pca.py in fit_transform(self, X, y)\r\n    239 \r\n    240         \"\"\"\r\n--> 241         U, S, V = self._fit(X)\r\n    242         U = U[:, :self.n_components_]\r\n    243 \r\n\r\n/home/kongnian/anaconda3/lib/python3.5/site-packages/sklearn/decomposition/pca.py in _fit(self, X)\r\n    266             requested.\r\n    267         \"\"\"\r\n--> 268         X = check_array(X)\r\n    269         n_samples, n_features = X.shape\r\n    270         X = as_float_array(X, copy=self.copy)\r\n\r\n/home/kongnian/anaconda3/lib/python3.5/site-packages/sklearn/utils/validation.py in check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)\r\n    371                                       force_all_finite)\r\n    372     else:\r\n--> 373         array = np.array(array, dtype=dtype, order=order, copy=copy)\r\n    374 \r\n    375         if ensure_2d:\r\n\r\nValueError: could not convert string to float: '?'\r\n```\r\nOS Information:\r\nLinux ubuntu 4.4.0-41-generic #61-Ubuntu SMP Tue Sep 27 17:27:48 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux"},"comment":{"url":"https://api.github.com/repos/dataPipelineAU/LearningDataMiningWithPython/issues/comments/252475250","html_url":"https://github.com/dataPipelineAU/LearningDataMiningWithPython/issues/5#issuecomment-252475250","issue_url":"https://api.github.com/repos/dataPipelineAU/LearningDataMiningWithPython/issues/5","id":252475250,"user":{"login":"robertlayton","id":800543,"avatar_url":"https://avatars.githubusercontent.com/u/800543?v=3","gravatar_id":"","url":"https://api.github.com/users/robertlayton","html_url":"https://github.com/robertlayton","followers_url":"https://api.github.com/users/robertlayton/followers","following_url":"https://api.github.com/users/robertlayton/following{/other_user}","gists_url":"https://api.github.com/users/robertlayton/gists{/gist_id}","starred_url":"https://api.github.com/users/robertlayton/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/robertlayton/subscriptions","organizations_url":"https://api.github.com/users/robertlayton/orgs","repos_url":"https://api.github.com/users/robertlayton/repos","events_url":"https://api.github.com/users/robertlayton/events{/privacy}","received_events_url":"https://api.github.com/users/robertlayton/received_events","type":"User","site_admin":false},"created_at":"2016-10-09T09:25:39Z","updated_at":"2016-10-09T09:25:39Z","body":"Was it my fix? I updated the formatting to add the line in. Apologies for not picking that up earlier\r\n"}}
{"actor":{"display_login":"robertlayton"}}