public void makeTrainTest() throws Exception {
  int labels[]=new int[dataNum];
  int labelClassNum[]=new int[20];
  BufferedReader trUsers=new BufferedReader(new InputStreamReader(new FileInputStream(labelFile)));
  String line="";
  while ((line=trUsers.readLine()) != null) {
    String[] strs=line.split("\t");
    labels[Integer.valueOf(strs[0])]=Integer.valueOf(strs[1]);
    labelClassNum[labels[Integer.valueOf(strs[0])]]++;
  }
  trUsers.close();
  int countClassNum=0;
  for (int i=0; i < labelClassNum.length; i++) {
    if (labelClassNum[i] != 0)     countClassNum++;
  }
  int labelClass[]=new int[countClassNum];
  Random r_classifier=new Random(123l);
  for (int i=0; i < dataNum; i++) {
    double nextRandom=r_classifier.nextDouble();
    if (nextRandom <= limitRandom) {
      TestTrain[i]=1;
      labelClass[labels[i]]++;
    }
  }
  for (int i=0; i < labelClass.length; i++) {
    if (labelClass[i] == 0) {
      Random r_classifier2=new Random(123l);
      for (int j=0; j < dataNum; j++) {
        if (labels[j] == i) {
          double nextRandom2=r_classifier2.nextDouble();
          if (nextRandom2 <= limitRandom) {
            TestTrain[j]=1;
          }
        }
      }
    }
  }
}

public void makeTrainTest ( ) throws Exception { int labels [ ] = new int [ dataNum ] ; int labelClassNum [ ] = new int [ 20 ] ; BufferedReader trUsers = new BufferedReader ( new InputStreamReader ( new FileInputStream ( labelFile ) ) ) ; String line = "" ; while ( ( line = trUsers . readLine ( ) ) != null ) { String [ ] strs = line . split ( "\t" ) ; labels [ Integer . valueOf ( strs [ 0 ] ) ] = Integer . valueOf ( strs [ 1 ] ) ; labelClassNum [ labels [ Integer . valueOf ( strs [ 0 ] ) ] ] ++ ; } trUsers . close ( ) ; int countClassNum = 0 ; for ( int i = 0 ; i < labelClassNum . length ; i ++ ) { if ( labelClassNum [ i ] != 0 ) countClassNum ++ ; } int labelClass [ ] = new int [ countClassNum ] ; Random r_classifier = new Random ( 123l ) ; for ( int i = 0 ; i < dataNum ; i ++ ) { double nextRandom = r_classifier . nextDouble ( ) ; if ( nextRandom <= limitRandom ) { TestTrain [ i ] = 1 ; labelClass [ labels [ i ] ] ++ ; } } for ( int i = 0 ; i < labelClass . length ; i ++ ) { if ( labelClass [ i ] == 0 ) { Random r_classifier2 = new Random ( 123l ) ; for ( int j = 0 ; j < dataNum ; j ++ ) { if ( labels [ j ] == i ) { double nextRandom2 = r_classifier2 . nextDouble ( ) ; if ( nextRandom2 <= limitRandom ) { TestTrain [ j ] = 1 ; } } } } } }
make a map to differentiate train and test set for training svm in different percentage . 0 stands for user in test set and 1 stands for user in train set .
