📄 da_lsgo.m
字号:
%
% da_lsgo.m
%
% Runs the least squares regression routines
%
%
% If there is more than one output variable defined then
% only use the FIRST one.
%
if sum(output_var) > 1
[D L]=size(output_var);
for i = 1 : L
if output_var(i) == 1
y=data(:,i);
break;
end
end
else
y=data(:,output_var);
end
x=pcincl(data,include_var,output_var);
% y=data(:,output_var);
mx=mean(x);
sdx=std(x);
my=mean(y);
sdy=std(y);
%
% Split the data correctly
%
%
% Check radio button 4 for the percentage partition
%
if get(pcr_rad4,'Value') == 1
[tx ty vx vy]=psplit(x,y,get(pcr_rad4sl,'Value'));
end
%
% Check radio button 5 for the random partition
%
if get(pcr_rad5,'Value') == 1
disp('Bollocks')
[tx ty vx vy]=rsplit(x,y,get(pcr_rad5sl,'Value'));
end
%
% Check radio button 6 for the block splitting
%
if get(pcr_rad6,'Value') == 1
[tx ty vx vy]=bsplit(x,y,ceil(get(pcr_rad6sl,'Value')));
end
%
% Check radio button 7 for alternate split
%
if get(pcr_rad7,'Value') == 1
[tx ty vx vy]=asplit(x,y);
end
%
% Bog standard regression with no polynomials
% and no best combination regression.
%
if get(pcr_rad1,'Value') == 0
if get(pcr_rad3,'Value') == 0
%
% Calculate the regression coefficients
% based on the training set
%
a=inv(tx'*tx)*tx'*ty;
impact=a;
regv=a;
py=vx*a;
[D L]=size(vy);
e=((sse(vy,py).^0.5)/D)/mean(vy);
c=corrcoef(vy,py);
c=c(2,1);
end
end
%
% Include polynomial terms.
% NO best combination regression
% get the number of terms to include from sl1
%
if get(pcr_rad1,'Value') == 1
if get(pcr_rad3,'Value') == 0
degree=ceil(get(sl1,'Value'));
tx=pol(tx,degree);
vx=pol(vx,degree);
a=inv(tx'*tx)*tx'*ty;
impact=a;
regv=a;
py=vx*a;
[D L]=size(vy);
e=((sse(vy,py).^0.5)/D)/mean(vy);
c=corrcoef(vy,py);
c=c(2,1);
end
end
%
% Now check radio button 3 to regress best combination of variables
%
if get(pcr_rad3,'Value') == 1
[D L]=size(tx);
%
% Only carry out this option if there are 10 varibles or less
%
if L < 11
e_min=1e100;
axes(ax1);
ovt=zeros(1,L);
for i = 1:2^L
%
% Build a binary include vector
%
inc=binary(i,L);
tx1=pcincl(tx,inc,ovt);
vx1=pcincl(vx,inc,ovt);
%
% Perform regression
%
a=inv(tx1'*tx1)*tx1'*ty;
py=vx1*a;
e=sse(py,vy);
if e < e_min
e_min=e;
ba=a;
include=inc;
plot([py vy]);
drawnow;
bpy=py;
end
end
end
[D L]=size(vy);
e=((sse(vy,py).^0.5)/D)/mean(vy);
c=corrcoef(vy,py);
c=c(2,1);
%
% Calculate the impact vector
%
[D L]=size(vx);
impact=zeros(L,1);
count=1;
for i = 1 : L
if include(i) == 1
impact(i)=ba(count);
count=count+1;
end
end
end
%
% Print results in the little blue box
%
text1=uicontrol(w1,...
'Style','text',...
'Position',[275 385 130 15],...
'BackGroundColor',[0 0 1],...
'ForeGroundColor',[1 1 1],...
'String',['Error = ' num2str(e)]);
text2=uicontrol(w1,...
'Style','text',...
'Position',[410 385 130 15],...
'BackGroundColor',[0 0 1],...
'ForeGroundColor',[1 1 1],...
'String',['Correlation = ' num2str(c)]);
%
% More detail button
%
pca_but2=uicontrol(w1,...
'Style','push',...
'Position',[380 10 100 20],...
'String','More detail',...
'CallBack','da_lsdet;');
%
% Save model button
%
pca_but3=uicontrol(w1,...
'style','push',...
'position',[500 10 100 20],...
'string','Save model',...
'callback',[...
'[D L]=size(tx);',...
'out=svlin2('''',include_var,zeros(L,1),zeros(L,1),zeros(L,1),zeros(L,1),impact,ones(L,1),zeros(L,1))']);
clear x y;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -