倾不完的羁绊 倾不完的羁绊
关注数: 4 粉丝数: 58 发帖数: 2,830 关注贴吧数: 30
救救孩子吧,如何给出一串代码进行线性拟合啊 给出这一串代码,怎么拟合成一条曲线啊 ,里面应该要的数据也看不懂,好难受啊 data = importdata('final_test.txt'); plot3(data(:,3),data(:,4),data(:,5),'x') idx=kmeans(data(:,3:5),6); plot(data(idx==1,2),data(idx==1,14),'.') [coef,score,latent,t2] = princomp(data); n=6; newdata=data*coef(:,1:n); data_tmp = data; data_tmp(:, 1:5) = NaN; cols_tmp = zeros(1, n); for i = 1 : n datai = data_tmp; newdatai = repmat(newdata(:, i), 1, size(datai, 2)); disi = sum((newdatai-datai).^2, 1); [~, indi] = min(disi); cols_tmp(i) = indi; data_tmp(:, indi) = NaN; end M = data(:, 1:5); disp(cols_tmp); 14 18 22 7 13 23 8 21 6 15 M = [M data(:, cols_tmp)]; X=data(idx==1,2); Y1=data(idx==1,14); >> Y2=data(idx==1,18); >> Y3=data(idx==1,7); >> Y4=data(idx==1,13); >> Y5=data(idx==1,8); Y=[Y1 Y2 Y3 Y4 Y5]; Cftool EXCEL data = importdata('final_test.txt'); [num] = xlsread('example'); plot3(data(:,3),data(:,4),data(:,5),'.') ; X=0; while(length(X)~=8293) try idx=kmeans(data(:,3:5),6); X=data(idx==1,2); catch end end for i=1:5 Y = num(:,5+i); figure(i) X_del = X(1:20:end); Y_del = Y(1:20:end); Y_del = 1-(Y_del); plot(X_del,Y_del,'o'); hold on; out = polyfit(X_del,Y_del,2) R= min(min(corrcoef(X_del, Y_del))) xx=1:0.5:300; for ii=1:length(xx) yy=out(1)*xx.^2+out(2)*xx+out(3); end plot(xx,yy,'r','linewidth',2); hold on; end 预测 data = importdata('test.txt'); [num] = xlsread('example11'); plot3(data(:,3),data(:,4),data(:,5),'.') ; X=0; while(length(X)~=4437) try idx=kmeans(data(:,3:5),6); X=data(idx==1,2); catch end end for i=1:5 Y = num(:,5+i); figure(i) X_del = X(1:20:end); Y_del = Y(1:20:end); Y_del = 1-(Y_del); plot(X_del,Y_del,'o'); hold on; out = polyfit(X_del,Y_del,2) R= min(min(corrcoef(X_del, Y_del))) xx=1:0.5:200; for ii=1:length(xx) yy=out(1)*xx.^2+out(2)*xx+out(3); end plot(xx,yy,'r','linewidth',2); hold on; axis([0 200 0 1]) End 计算预测得分 A=xlsread('51.xlsx','A1:A2298'); B=xlsread('51.xlsx','B1:B2298'); S=0; for i=1:2298 if A(i)-B(i)>0 Sk(i)=2.72^((A(i)-B(i))/10)-1; else Sk(i)=2.72^((B(i)-A(i))/13)-1; S=S+Sk(i); disp(S); end end
1 下一页