?? model_selection.m
字號:
function Model_Selection(train_p,train_t,test_p,test_t,M)
numperclu=[];
% [cents,clu,numperclu]=Kmeans_batch_Clusting(train_p,M); % 用=Kmeans_batch_Clusting算法聚類,cents表示選取類的中心,
% % ...clu表示樣例所屬的類序號,numperclu每類包含訓練點個數;
[clu,cents]=kmeans(train_p,M,'replicates',100,'maxiter',10000,'EmptyAction','singleton');
Centers_num=size(cents,1); % 聚類后所得類的個數;
for i=1:Centers_num
numperclu(i)=size(clu(clu==i),1);
end
[R,width]=My_Width(train_p,cents,clu,numperclu,Centers_num);% 求每個中心的寬度,返回寬度矩陣R.(d×d×K),with為寬度向量
H=My_Guass(train_p,cents,Centers_num,R);% 構造Guass函數矩陣H
H1=pinv(H); % 求高斯矩陣H的偽逆H1;
W=H1*(train_t) % 解權重矩陣W;
[TrainErrorMSE,TrainErrorRate]=Train_Error(train_p,train_t,H,W); % 求訓練MSE和訓練分類錯誤率
[TestErrorMSE,TestErrorRate]=Test_Error(test_p,test_t,cents,W,R); % 求測試MSE及測試分類錯誤率
% 顯示部分
TrainCorrectRate=1-TrainErrorRate
TestCorrectRate=1-TestErrorRate
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -