0

I have a dataset like below: In this dataset first column represents the id of a person, the last column is label of this person and rest of the columns are features of the person.

101 166 633.0999756 557.5   71.80000305 60.40000153 2.799999952 1   1   -1
101 133 636.2000122 504.3999939 71  56.5    2.799999952 1   2   -1
105 465 663.5   493.7000122 82.80000305 66.40000153 3.299999952 10  3   -1
105 133 635.5999756 495.6000061 89  72  3.599999905 9   6   -1
105 266 633.9000244 582.2000122 93.59999847 81  3.700000048 2   2   -1
105 299 618.4000244 552.4000244 80.19999695 66.59999847 3.200000048 3   64  -1
105 99  615.5999756 575.7000122 80  67  3.200000048 0   0   -1
120 399 617.7000122 583.5   95.80000305 82.40000153 3.799999952 8   10  1
120 266 633.9000244 582.2000122 93.59999847 81  3.700000048 2   2   1
120 299 618.4000244 552.4000244 80.19999695 66.59999847 3.200000048 3   64  1
120 99  615.5999756 575.7000122 80  67  3.200000048 0   0   1

My aim is to classify these people, and I want to use leave one out person method as a split method. So I need to choose one person and his all data as a test data and the rest of the data for training. But when try to choose the test data I implemented list assignment operation but it gave an error. This is my code:

`import numpy as np

 datasets=["raw_fixationData.txt"]
 file_name_array=[101,105,120]

for data in datasets:
    data = np.genfromtxt(data,delimiter="\t")
    data=data[1:,:]
    num_line=len(data[:,1])-1
    num_feat=len(data[1,:])-2
    label=num_feat+1
    X = data[0:num_line+1,1:label]
    y = data[0:num_line+1,label]  

   test_prtcpnt=[]; test_prtcpnt_label=[];  train_prtcpnt=[];  train_prtcpnt_label=[];

   for i in range(len(file_name_array)):

       m=0; # test index
       n=0 #train index
       for j in range(num_line):
           if X[j,0]==file_name_array[i]:
               test_prtcpnt[m,0:10]=X[j,0:10];
               test_prtcpnt_label[m]=y[j];
               m=m+1;  
           else:
               train_prtcpnt[n,0:10]=X[j,0:10];
               train_prtcpnt_label[n]=y[j];
               n=n+1;  ` 

This code give me this error test_prtcpnt[m,0:10]=X[j,0:10]; TypeError: list indices must be integers or slices, not tuple

How could I solve this problem?

Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555
user951487
  • 845
  • 7
  • 19
  • 30
  • I guess you need to use [`np.array`](https://docs.scipy.org/doc/numpy/user/basics.creation.html) instead of lists. – Peter Wood Feb 21 '17 at 16:05

1 Answers1

1

I think that you are misusing Python's slice notation. Please refer to the following stack overflow post on slicing:

Explain Python's slice notation

In this case, the Python interpreter seems to be interpreting test_prtcpnt[m,0:10] as a tuple. Is it possible that you meant to say the following:

test_prtcpnt[0:10]=X[0:10]
Community
  • 1
  • 1
digitalnomd
  • 1,380
  • 12
  • 21