2
$\begingroup$

I have a time series, tab delimited dataset with the following format

Label4  0.064463    0.063448    0.070535    0.080498    0.055382    0.054336    0.055336
Label3  0.068560    0.091277    0.103625    0.092759    0.069522    0.070261    0.068328
Label2  0.058401    0.057793    0.062452    0.065339    0.044136    0.069419    0.049345
Label1  0.091222    0.093995    0.097264    0.108168    0.073451    0.071705    0.092312
...

I want to cluster the data by rows, such that a cluster is a group of rows that have similar numbers for column 1 - column 7.

I would like the output of FindCluster to return only the first column (Label). I do not want FindCluster to use the data in column 1 in the actual clustering calculation.

This is an incorrect implementation:

data=ImportString["Label4   0.064463    0.063448    0.070535    0.080498    0.055382    0.054336    0.055336
Label3  0.068560    0.091277    0.103625    0.092759    0.069522    0.070261    0.068328
Label2  0.058401    0.057793    0.062452    0.065339    0.044136    0.069419    0.049345
Label1  0.091222    0.093995    0.097264    0.108168    0.073451    0.071705    0.092312","TSV"];
clusters = FindClusters[{data[[All, Range[2, 8]]]} -> {data[[All, 1]]}]

My ideal output would be something like

{{Label1, Label2}, {Label3, Label4}}
$\endgroup$
2
$\begingroup$
data2 = ToExpression /@ {##2} -> #1 & @@ # & /@ (StringSplit @@@ data);
{{0.064463, 0.063448, 0.070535, 0.080498, 0.055382, 0.054336, 0.055336} -> "Label4", 
 {0.06856, 0.091277, 0.103625, 0.092759, 0.069522,  0.070261, 0.068328} -> "Label3", 
 {0.058401, 0.057793, 0.062452, 0.065339, 0.044136, 0.069419, 0.049345} -> "Label2", 
 {0.091222, 0.093995, 0.097264, 0.108168, 0.073451, 0.071705, 0.092312} -> "Label1"}
clusters = FindClusters[data2];
(* {{"Label4","Label2"},{"Label3","Label1"}} *)

for the data you provided:

data = ImportString[
   "Label4   0.064463    0.063448    0.070535    0.080498    0.055382   0.054336    0.055336
   Label3  0.068560    0.091277    0.103625    0.092759    0.069522    0.070261    0.068328
   Label2  0.058401    0.057793    0.062452    0.065339    0.044136    0.069419    0.049345
   Label1  0.091222    0.093995    0.097264    0.108168    0.073451   0.071705    0.092312", 
   "TSV"];
|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thanks this is exactly what I wanted. $\endgroup$ – Justin Gardin Oct 16 '14 at 18:18
  • $\begingroup$ @JustinGardin, my pleasure. Welcome to Mathematica.SE. Please consider visiting the tour page on the basic rules of the site, and editing help page for editing help. $\endgroup$ – kglr Oct 16 '14 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.