clear
clc
load feature.mat
[m,n]=size(feature);
feature=feature(:,[1 11 12 50  n]);

[m,n]=size(feature);

%  for i=1:n-1
%      maxs=max(feature(:,i));
%      mins=min(feature(:,i));
%      feature(:,i)=(feature(:,i)-mins)/(maxs-mins);
%  end

label_vector(1:m,1)=feature(1:m,n);
instance_matrix(1:m,1:n-1)=feature(1:m,1:n-1);


fid=fopen('data.txt','w');
for i=1:m
    fprintf(fid,'%f',label_vector(i));
    fprintf(fid,'  ');
    for j=1:n-1
        fprintf(fid,'%d',j);
        fprintf(fid,':');
        fprintf(fid,'%f',instance_matrix(i,j));
        fprintf(fid,'  ');
    end
    fprintf(fid,'\n');
end
fclose(fid);

[feature_label, feature_inst] = libsvmread('data.txt');
rate=0.8;

for i=1:1000
    %%
%     index=randperm(m);
%     train_number=ceil(m*rate);
%     train_index=index(1:train_number);
%     test_index=index(train_number+1:m);
    %test_index=train_index;
    %%
  [train_index,test_index]=data_seperate(rate);
    %%
    
    train_data=feature_inst(train_index,:);
    train_label=feature_label(train_index,:);
    
    test_data=feature_inst(test_index,:);
    test_label=feature_label(test_index,:);
    
 model=svmtrain(train_label, train_data, '-s 4 -t 2 ');
 
 [predict_label, accuracy, dec_values] = svmpredict(test_label, test_data, model);
 
 spearman(i)=corr(test_label,predict_label,'type','spearman');
 pearson(i)=corr(test_label,predict_label,'type','pearson');
 clc
end
medians=[median(spearman) median(pearson)]
means=[mean(spearman) mean(pearson)]
max_min=[max(spearman) min(spearman)]









