一、介绍分类二、优化算法三、多分类问题逻辑回归分类MachineLearning分类邮件:垃圾邮件/不是垃圾邮件?在线交易:欺诈(是/否)?肿瘤:良性/恶性?0:“消极类”(e.g.,恶性肿瘤)1:“积极类”(e.g.,良性肿瘤)AndrewNg肿瘤尺寸阈值分类器在0.5处的输出If,predict“y=1”If,predict“y=0”肿瘤尺寸恶性肿瘤?(是)1(否)0AndrewNgS函数逻辑函数逻辑回归模型:使得10.50AndrewNgSupposepredict““ifpredict““ifz1Example:如果AndrewNgx1x2123123Predict““if逻辑回归决策边界AndrewNg非线性决策边界x1x2Predict““ifx1x21-1-11AndrewNg代价函数Linearregression:“非凸函数”“凸函数”AndrewNg逻辑回归代价函数Ify=1101Ify=0AndrewNgOutput逻辑回归代价函数为了拟合参数:当给定新的x时能预测AndrewNg梯度下降:Want:Repeat(simultaneouslyupdateall)AndrewNg梯度下降:Want:(simultaneouslyupdateall)RepeatAndrewNg逻辑回归优化算法MachineLearning代价函数希望给定通过编码实现计算(for)Repeat梯度下降算法:优化算法:梯度下降-Conjugategradient(共轭梯度法)BFGSL-BFGS优点:不用手动选择比梯度下降算法快缺点:复杂AndrewNgExample:function[jVal,gradient]=costFunction(theta)jVal=(theta(1)-5)^2+...(theta(2)-5)^2;gradient=zeros(2,1);gradient(1)=2*(theta(1)-5);gradient(2)=2*(theta(2)-5);options=optimset(‘GradObj’,‘on’,‘MaxIter’,‘100’);initialTheta=zeros(2,1);[optTheta,functionVal,exitFlag]...=fminunc(@costFunction,initialTheta,options);AndrewNgAndrewNggradient(1)=[];function[jVal,gradient]=costFunction(theta)theta=jVal=[];gradient(2)=[];gradient(n+1)=[];codetocomputecodetocomputecodetocomputecodetocomputeAndrewNg逻辑回归多分类问题MachineLearningMulticlassclassification邮件分类器:工作,朋友,家庭,Hobby药物诊断:没病,感冒,流感天气:晴天,多云,雨,雪AndrewNgx1x2x1x2二分类问题:多分类问题:AndrewNgx1x2一对多的思想:Class1:Class2:Class3:x1x2x1x2x1x2AndrewNg