?? cv_of_logistic.m
字號:
%交叉驗證 CV_of_Logistic.m
X=X_Log;
Y=Y_Log;
%從cell中取出 為了簡潔,實際程序中不用
% x1_train=X{1};
% x1_test=X{2};
% x2_train=X{3};
% x2_test=X{4};
% x3_train=X{5};
% x3_test=X{6};
% x4_train=X{7};
% x4_test=X{8};
% x5_train=X{9};
% x5_test=X{10};
%
% y1_train=Y{1};
% y1_test=Y{2};
% y2_train=Y{3};
% y2_test=Y{4};
% y3_train=Y{5};
% y3_test=Y{6};
% y4_train=Y{7};
% y4_test=Y{8};
% y5_train=Y{9};
% y5_test=Y{10};
%設定step(由實踐證明step選2即可)
step=2;
CV_Logistic=0;
clear Er;
clear s;
for i=1:2:10 %i分別取1,3,5,7,9
[beta,rate_Logistic((i+1)/2,1)] = Logistic_solve(X{i},Y{i},step); %rate_Logistic((i+1)/2,1)訓練集的正確率
%在訓練集1上得到 beta
%在測試集1上驗證
[y] = Logistic_class(X{i+1},beta);
%計算L(y,f^)=abs(y-y')/2誤分點 ????
Er = abs(Y{i+1}-y);
L_Logistic((i+1)/2) = sum(Er); %錯判的個數
s = size(X{i+1}); %測試集的大小
rate_Logistic((i+1)/2,2) = (1-L_Logistic((i+1)/2)/s(1))*100; %測試集的正確率
CV_Logistic = CV_Logistic + L_Logistic((i+1)/2);
clear Er;
clear s;
end
CV_Logistic = CV_Logistic/sall(1); %預測誤差的交叉驗證估計
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -