{"action":"created","issue":{"url":"https://api.github.com/repos/Amber-MD/cpptraj/issues/189","labels_url":"https://api.github.com/repos/Amber-MD/cpptraj/issues/189/labels{/name}","comments_url":"https://api.github.com/repos/Amber-MD/cpptraj/issues/189/comments","events_url":"https://api.github.com/repos/Amber-MD/cpptraj/issues/189/events","html_url":"https://github.com/Amber-MD/cpptraj/issues/189","id":118481875,"number":189,"title":"Dataset for clustering: discussion","user":{"login":"hainm","id":4451957,"avatar_url":"https://avatars.githubusercontent.com/u/4451957?v=3","gravatar_id":"","url":"https://api.github.com/users/hainm","html_url":"https://github.com/hainm","followers_url":"https://api.github.com/users/hainm/followers","following_url":"https://api.github.com/users/hainm/following{/other_user}","gists_url":"https://api.github.com/users/hainm/gists{/gist_id}","starred_url":"https://api.github.com/users/hainm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hainm/subscriptions","organizations_url":"https://api.github.com/users/hainm/orgs","repos_url":"https://api.github.com/users/hainm/repos","events_url":"https://api.github.com/users/hainm/events{/privacy}","received_events_url":"https://api.github.com/users/hainm/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-11-23T21:57:41Z","updated_at":"2015-11-23T22:08:29Z","closed_at":null,"body":"from this PR: #183 \r\n\r\nDan's comment:\r\n\r\n> I'm delaying on this a little bit because I'm wondering if all clustering data shouldn't be stored in either one specialized DataSet or in multiple DataSets with different aspects. Former would allow cluster output to be used with the DataFile framework more easily, latter would be easier to implement in the short run but maybe harder to maintain. Maybe this should be a separate issue? Not sure...\r\n\r\nHai:\r\n\r\nI am ok with delaying (and I don't need this feature now). My original aim for this PR is to make cpptraj a bit similar to sklearn. Just give very dummy example here.\r\n\r\n```python\r\nIn [3]: from sklearn.cluster import k_means\r\n\r\nIn [4]: k_means(xyz, n_clusters=10)\r\nOut[4]: \r\n(array([[ 15.48531055,  28.5936985 ,  16.56096268, ...,  34.20779419,\r\n           9.24066639,  16.65553093],\r\n        [ 15.07740974,  29.1335144 ,  17.32461929, ...,  33.20933914,\r\n           7.98652649,  15.00128174],\r\n        [ 14.73693371,  28.61953735,  16.14261436, ...,  32.55017853,\r\n           9.01970196,  17.33253098],\r\n        ..., \r\n        [ 15.06157207,  28.82535172,  17.34188652, ...,  34.29132462,\r\n           8.27471733,  16.50368881],\r\n        [ 15.55458927,  28.54844856,  17.18908691, ...,  -0.17751557,\r\n           8.35964298,  18.69264793],\r\n        [ 14.77806568,  29.08259392,  16.52130318, ...,  33.91731262,\r\n           9.42454243,  16.95419884]]),\r\n array([8, 3, 7, 1, 6, 0, 5, 4, 9, 2], dtype=int32),\r\n 1.3271346688270569e-08)\r\n```\r\n\r\n```python\r\nReturns\r\n-------\r\ncentroid : float ndarray with shape (k, n_features)\r\n    Centroids found at the last iteration of k-means.\r\n\r\nlabel : integer ndarray with shape (n_samples,)\r\n    label[i] is the code or index of the centroid the\r\n    i'th observation is closest to.\r\n\r\ninertia : float\r\n    The final value of the inertia criterion (sum of squared distances to\r\n    the closest centroid for all observations in the training set).\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/Amber-MD/cpptraj/issues/comments/159081876","html_url":"https://github.com/Amber-MD/cpptraj/issues/189#issuecomment-159081876","issue_url":"https://api.github.com/repos/Amber-MD/cpptraj/issues/189","id":159081876,"user":{"login":"hainm","id":4451957,"avatar_url":"https://avatars.githubusercontent.com/u/4451957?v=3","gravatar_id":"","url":"https://api.github.com/users/hainm","html_url":"https://github.com/hainm","followers_url":"https://api.github.com/users/hainm/followers","following_url":"https://api.github.com/users/hainm/following{/other_user}","gists_url":"https://api.github.com/users/hainm/gists{/gist_id}","starred_url":"https://api.github.com/users/hainm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/hainm/subscriptions","organizations_url":"https://api.github.com/users/hainm/orgs","repos_url":"https://api.github.com/users/hainm/repos","events_url":"https://api.github.com/users/hainm/events{/privacy}","received_events_url":"https://api.github.com/users/hainm/received_events","type":"User","site_admin":false},"created_at":"2015-11-23T22:08:29Z","updated_at":"2015-11-23T22:08:29Z","body":">  Like the actual frame numbers in each cluster, the cluster silhouette data, pseufo-F, DBI, etc.\r\n\r\nPer \" the cluster silhouette data, pseufo-F, DBI, etc.\", I have never used them. So I am not sure about how I can use. May be we just dump them to a single String dataset? If anyone want to use, he/she can parse the string.\r\n\r\nPer 'actual frame numbers in each cluster`, Python has excellent class, called Counter :D\r\n\r\n```python\r\nIn [16]: data = kmeans(traj, n_clusters=20)\r\n\r\nIn [17]: data\r\nOut[17]: array([16, 18, 17, ...,  0,  0,  0], dtype=int32)\r\n\r\nIn [18]: Counter(data)\r\nOut[18]: \r\nCounter({0: 20,\r\n         1: 17,\r\n         2: 12,\r\n         3: 12,\r\n         4: 6,\r\n         5: 4,\r\n         6: 4,\r\n         7: 3,\r\n         8: 3,\r\n         9: 3,\r\n         10: 3,\r\n         11: 2,\r\n         12: 2,\r\n         13: 2,\r\n         14: 2,\r\n         15: 2,\r\n         16: 1,\r\n         17: 1,\r\n         18: 1,\r\n         19: 1})\r\n```\r\n\r\n\r\n"}}