geterror.m

来自「Adaboost算法是一个著名的机器学习的算法」· M 代码 · 共 22 行

M
22
字号
%%% file: getError.m% This function calculates the error returned by the current run of the weak learner.%%function [errorTrain,errorTest]=getError(boost,train,train_label,test,test_label)    disp('run getError');    d=size(boost);    num=size(train);    prediction=zeros(num(1),1);    % geting the train error    for h=1:d(1)        prediction=prediction-log(boost(h,1))*(train(:,boost(h,2))>=boost(h,3));    end    temp=-sum(log(boost(:,1)))/2;    errorTrain=sum(abs((train_label>=5)-(prediction>=temp)))/num(1);    prediction=zeros(1000,1);    % geting the test error    for h=1:d(1)        prediction=prediction-log(boost(h,1))*(test(:,boost(h,2))>=boost(h,3));    end    errorTest=sum(abs((test_label>=5)-(prediction>=temp)))/1000;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?