{"id":2842,"date":"2020-02-02T15:58:06","date_gmt":"2020-02-02T07:58:06","guid":{"rendered":"http:\/\/www.sniper97.cn\/?p=2842"},"modified":"2020-02-02T15:58:06","modified_gmt":"2020-02-02T07:58:06","slug":"%e3%80%90%e5%90%b4%e6%81%a9%e8%be%be%e6%b7%b1%e5%ba%a6%e5%ad%a6%e4%b9%a0%e3%80%91%e6%b5%85%e5%b1%82%e7%a5%9e%e7%bb%8f%e7%bd%91%e7%bb%9c","status":"publish","type":"post","link":"http:\/\/www.sniper97.cn\/index.php\/note\/deep-learning\/2842\/","title":{"rendered":"\u3010\u5434\u6069\u8fbe\u6df1\u5ea6\u5b66\u4e60\u3011\u6d45\u5c42\u795e\u7ecf\u7f51\u7edc"},"content":{"rendered":"\n<p>\u5434\u6069\u8fbe\u6df1\u5ea6\u5b66\u4e60\u7b2c\u4e00\u8bfe\u7b2c\u4e09\u5468\uff0c\u6d45\u5c42\u795e\u7ecf\u7f51\u7edc<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"295\" height=\"221\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-12.png\" alt=\"\" class=\"wp-image-2855\"\/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">1.\u4ec0\u4e48\u662f\u795e\u7ecf\u7f51\u7edc<\/h2>\n\n\n<p>\u795e\u7ecf\u7f51\u7edc\u5176\u5b9e\u5c31\u662f\u591a\u4e2a\u903b\u8f91\u56de\u5f52\u5355\u5143\u7684\u5806\u53e0\u3002<\/p>\n\n\n<p>\u6bd4\u5982\u4e0b\u56fe\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"513\" height=\"340\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247.png\" alt=\"\" class=\"wp-image-2843\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247.png 513w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-300x199.png 300w\" sizes=\"(max-width: 513px) 100vw, 513px\" \/><\/figure><\/div>\n\n\n<p>\u8fd9\u5f20\u56fe\u7247\u5b9e\u9645\u4e0a\u5c31\u662f4\u4e2a\u903b\u8f91\u56de\u5f52\u5355\u5143\u7684\u5806\u53e0\uff0c\u5bf9\u4e8e\u30102\u3011\u5c42\uff0c\u662f\u7531\u30101\u3011\u5c42\u7684\u6570\u636e\u4f5c\u903b\u8f91\u56de\u5f52\u5f97\u5230\u30102\u3011\u5c42\u6570\u636e\uff0c\u800c\u30101\u3011\u5c42\u6570\u636e\u53c8\u662f\u5206\u522b\u7531\u8f93\u5165\u5c42x\u505a\u4e86\u4e09\u6b21\u903b\u8f91\u56de\u5f52\u5f97\u5230\u7684\u8f93\u51fa\u3002<\/p>\n\n\n<p>\u5bf9\u4e8e\u8fd9\u4e9b\u5c42\u7684\u53eb\u6cd5\uff0c\u6211\u4eec\u8fd8\u6709\u5176\u4ed6\u53eb\u6cd5\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"564\" height=\"393\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-1.png\" alt=\"\" class=\"wp-image-2844\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-1.png 564w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-1-300x209.png 300w\" sizes=\"(max-width: 564px) 100vw, 564px\" \/><\/figure><\/div>\n\n\n<p>\u5206\u522b\u4e3a\u8f93\u5165\u5c42\uff0c\u9690\u85cf\u5c42\uff08\u53ef\u4ee5\u5927\u4e8e\u4e00\u5c42\uff09\u548c\u8f93\u51fa\u5c42\u7ec4\u6210\uff0c\u5176\u4e2d\u7684\u7ed3\u70b9\u8868\u793a\u4e5f\u5728\u56fe\u4e2d\u6709\u6807\u8bc6\u3002<\/p>\n\n\n<h2 class=\"wp-block-heading\">2.\u795e\u7ecf\u5143\u91cc\u6709\u4ec0\u4e48\uff1f<\/h2>\n\n\n<p>\u65e2\u7136\u672c\u8d28\u4e0a\u548c\u903b\u8f91\u56de\u5f52\u5dee\u4e0d\u591a\uff0c\u90a3\u4e48\u795e\u7ecf\u5143\u7684\u5b9e\u9645\u8fd0\u7b97\u4e5f\u548c\u903b\u8f91\u56de\u5f52\u5927\u540c\u5c0f\u5f02\u3002<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"924\" height=\"433\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-2.png\" alt=\"\" class=\"wp-image-2845\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-2.png 924w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-2-300x141.png 300w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-2-768x360.png 768w\" sizes=\"(max-width: 924px) 100vw, 924px\" \/><\/figure><\/div>\n\n\n<p>\u5b9e\u9645\u4e0a\u5c31\u662fz = wx + b\u548c\u4e00\u4e2a\u6fc0\u6d3b\u8fc7\u7a0b\uff0c\u548c\u4e0a\u4e00\u5468\u8bb2\u7684\u57fa\u4e8e\u903b\u8f91\u56de\u5f52\u7684\u795e\u7ecf\u7f51\u7edc\u662f\u4e00\u6837\u7684\uff0c\u548c\u57fa\u7840\u903b\u8f91\u56de\u5f52\u4e5f\u5c31\u591a\u4e86\u4e00\u4e2a\u504f\u7f6eb\u3002<\/p>\n\n\n<p>\u56e0\u6b64\u5bf9\u4e8e\u6574\u4e2a\u795e\u7ecf\u7f51\u7edc\uff0c\u6211\u4eec\u53ef\u4ee5\u83b7\u5f97\u5982\u4e0b\u5f0f\u5b50\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"938\" height=\"265\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-3.png\" alt=\"\" class=\"wp-image-2846\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-3.png 938w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-3-300x85.png 300w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-3-768x217.png 768w\" sizes=\"(max-width: 938px) 100vw, 938px\" \/><\/figure><\/div>\n\n\n<p>\u4e3a\u4e86\u8ba1\u7b97\u65b9\u4fbf\uff0c\u6211\u4eec\u5411\u91cf\u5316\u8868\u793a\u8fd9\u4e9b\u8ba1\u7b97\u8fc7\u7a0b\uff08\u8fd9\u91cc\u662f\u4e00\u6b21\u8ba1\u7b97\u4e09\u4e2a\u6837\u672c\u7684\u60c5\u51b5\uff09<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1014\" height=\"412\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-4.png\" alt=\"\" class=\"wp-image-2847\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-4.png 1014w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-4-300x122.png 300w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-4-768x312.png 768w\" sizes=\"(max-width: 1014px) 100vw, 1014px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">3.\u6fc0\u6d3b\u51fd\u6570<\/h2>\n\n\n<p>\u6211\u4eec\u6709\u4e09\uff08\u56db\uff09\u79cd\u6fc0\u6d3b\u51fd\u6570\uff0c\u5206\u522b\u4e3a\uff1a<\/p>\n\n\n<p>sigmoid\u6fc0\u6d3b\u51fd\u6570<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"362\" height=\"252\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-5.png\" alt=\"\" class=\"wp-image-2848\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-5.png 362w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-5-300x209.png 300w\" sizes=\"(max-width: 362px) 100vw, 362px\" \/><\/figure><\/div>\n\n\n<p>tanh\u6fc0\u6d3b\u51fd\u6570<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"408\" height=\"266\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-6.png\" alt=\"\" class=\"wp-image-2849\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-6.png 408w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-6-300x196.png 300w\" sizes=\"(max-width: 408px) 100vw, 408px\" \/><figcaption><br \/><\/figcaption><\/figure><\/div>\n\n\n<p>ReLU\u6fc0\u6d3b\u51fd\u6570<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"329\" height=\"237\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-7.png\" alt=\"\" class=\"wp-image-2850\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-7.png 329w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-7-300x216.png 300w\" sizes=\"(max-width: 329px) 100vw, 329px\" \/><\/figure><\/div>\n\n\n<p>\u548cReLU\u7684\u53d8\u79cd\uff0c\u5e26\u6cc4\u6f0f\u7684ReLU\u6fc0\u6d3b\u51fd\u6570\uff08\u6ce8\u610f\u5230\u5728x\u8d1f\u534a\u8f74\u4e0d\u518d\u662f\u4e00\u6761\u6c34\u5e73\u76f4\u7ebf\uff0c\u800c\u662f\u53c8\u4e00\u4e2a\u5fae\u5c0f\u659c\u7387\u7684\u66f2\u7ebf\uff09<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"404\" height=\"221\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-8.png\" alt=\"\" class=\"wp-image-2851\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-8.png 404w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-8-300x164.png 300w\" sizes=\"(max-width: 404px) 100vw, 404px\" \/><\/figure><\/div>\n\n\n<p>\u5bf9\u4e8e\u8fd9\u4e48\u591a\u79cd\u6fc0\u6d3b\u51fd\u6570\uff0c\u600e\u4e48\u4f7f\u7528\u548c\u533a\u5206\u5462\uff1f<\/p>\n\n\n<p>\u5bf9\u4e8esigmoid\u6fc0\u6d3b\u51fd\u6570\uff0c\u662f\u4e00\u4e2a\u5f88\u53e4\u8001\u7684\u6fc0\u6d3b\u51fd\u6570\uff0c\u5b83\u548c\u5176\u4ed6\u6fc0\u6d3b\u51fd\u6570\u4e00\u6837\uff0c\u90fd\u5c06\u5f88\u5927\u8303\u56f4\u7684x\u503c\u6620\u5c04\u5230\u4e00\u4e2a\u5f88\u5c0f\u7684\u8303\u56f4\u4e4b\u5185\u3002<\/p>\n\n\n<p>\u5bf9\u4e8etanh\u6fc0\u6d3b\u51fd\u6570\uff0c\u5b83\u7684\u8868\u73b0\u5f80\u5f80\u4f18\u4e8esigmoid\u6fc0\u6d3b\u51fd\u6570\uff0c\u56e0\u6b64\u591a\u4f7f\u7528tanh\u3002\u4f46\u662f\u4e5f\u4e0d\u662f\u7edd\u5bf9\u7684\uff0c\u6709\u4e00\u4e2a\u7279\u4f8b\u5c31\u662f\u4e8c\u5206\u7c7b\u95ee\u9898\uff0c\u56e0\u4e3a\u6211\u4eec\u6700\u540e\u7684\u8f93\u51fa\u6982\u7387\u57280~1\u4e4b\u95f4\u4f1a\u66f4\u52a0\u5408\u7406\uff0c\u56e0\u6b64\u8f93\u51fa\u5c42\u7684\u6fc0\u6d3b\u51fd\u6570\u5f80\u5f80\u4f7f\u7528\u7684\u662fsigmoid\u6fc0\u6d3b\u51fd\u6570\u3002\u5373\u4f7f\u8fd9\u6837\uff0c\u5728\u8fd9\u4e4b\u524d\u7684\u9690\u85cf\u5c42\uff0c\u4f9d\u7136\u63a8\u8350\u4f7f\u7528tanh\u6fc0\u6d3b\u51fd\u6570\u6216\u8005ReLU\u6fc0\u6d3b\u51fd\u6570\u3002<\/p>\n\n\n<p>\u4f46\u662fsigmoid\u6fc0\u6d3b\u51fd\u6570\u548ctanh\u6fc0\u6d3b\u51fd\u6570\u90fd\u6709\u4e00\u4e2a\u95ee\u9898\uff0c\u5c31\u662f\u5f53x\u8db3\u591f\u5927\u6216\u8005\u8db3\u591f\u5c0f\u7684\u65f6\u5019\uff0c\u6fc0\u6d3b\u51fd\u6570\u7684\u659c\u7387\u8d8b\u8fd1\u4e8e0\uff0c\u8fd9\u6837\u4f1a\u5bfc\u81f4\u6574\u4f53\u7684\u5b66\u4e60\u901f\u7387\u4e0b\u964d\uff0c\u51cf\u6162\u5b66\u4e60\u7684\u901f\u5ea6\uff0c\u56e0\u6b64\u6211\u4eec\u5f15\u5165\u4e86\u53e6\u4e00\u4e2a\u6fc0\u6d3b\u51fd\u6570\u3002<\/p>\n\n\n<p>ReLU\u6fc0\u6d3b\u51fd\u6570\uff08a = max(0,z)\uff09,\u53ea\u8981z\u4e3a\u590d\u8ff0\uff0c\u659c\u7387\u4e3a0\uff0cz\u4e3a\u6b63\u6570\u659c\u7387\u4e3a1\u3002\u5bf9\u4e8e\u8fd9\u4e2a\u6fc0\u6d3b\u51fd\u6570\uff0c\u53ea\u6709\u51e0\u53e5\u8bdd\u6765\u63cf\u8ff0\uff0c\u597d\u7528\uff0c\u7528\u5c31\u5b8c\u4e8b\u4e86\uff0c\u4e0d\u77e5\u9053\u7528\u5565\u5c31\u7528\u5b83\uff0c\u6307\u5b9a\u6ca1\u9519\u3002<\/p>\n\n\n<p>\u8fd8\u6709\u4e00\u4e2a\u5c31\u662f\u5e26\u6cc4\u6f0f\u7684ReLU\u51fd\u6570\uff0c\u8fd9\u4e2a\u51fd\u6570\u5728x\u8d1f\u534a\u8f74\u6709\u4e00\u4e2a\u659c\u7387\u5f88\u5c0f\u7684\u53d6\u6d88\uff0c\u901a\u5e38\u53d60.01\uff0c\u8fd9\u53ea\u662f\u4e2a\u7ecf\u9a8c\u503c\uff0c\u5728\u4e00\u4e9b\u60c5\u51b5\u4e0b\u9700\u8981\u8bd5\u9a8c\u5176\u4ed6\u503c\u3002\u4f46\u662f\u5f80\u5f80\u4f7f\u7528ReLU\u6fc0\u6d3b\u51fd\u6570\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n\n\n<p>\u56e0\u6b64\u6211\u4eec\u603b\u7ed3\u4e00\u4e0b\u5c31\u662fReLU\u7528\u5c31\u5b8c\u4e8b\u4e86\uff0csigmoid\u9664\u4e86\u4e8c\u5206\u7c7b\u7684\u8f93\u51fa\u5c42\u6700\u597d\u4e0d\u7528\u3002<\/p>\n\n\n<h2 class=\"wp-block-heading\">4.\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u975e\u7ebf\u6027\u7684\u6fc0\u6d3b\u51fd\u6570\uff1f<\/h2>\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\u4e0a\u9762\u8bf4\u7684\u51e0\u4e2a\u6fc0\u6d3b\u51fd\u6570\u90fd\u662f\u975e\uff08\u5168\u5c40\uff09\u7ebf\u6027\u7684\uff0c\u90a3\u4e48\u4e3a\u4ec0\u4e48\u8981\u4f7f\u7528\u975e\u7ebf\u6027\u7684\u6fc0\u6d3b\u51fd\u6570\u5462\uff1f<\/p>\n\n\n<p>\u4e8b\u5b9e\u8bc1\u660e\uff0c\u5982\u679c\u8981\u8ba9\u4f60\u7684\u795e\u7ecf\u7f51\u7edc\u6709\u4e00\u4e2a\u6bd4\u8f83\u597d\u7684\u8f93\u51fa\uff0c\u5fc5\u987b\u4f7f\u7528\u975e\u7ebf\u6027\u7684\u6fc0\u6d3b\u51fd\u6570\u3002<\/p>\n\n\n<p> \u56e0\u4e3a\u5982\u679c\u4f7f\u7528\u7ebf\u6027\u7684\u6fc0\u6d3b\u51fd\u6570\uff0c\u6700\u540e\u6211\u4eec \u53ef\u4ee5\u5316\u7b80\u53d1\u73b0\uff0c\u6574\u4e2a\u795e\u7ecf\u7f51\u7edc\u5b9e\u9645\u4e0a\u8fd8\u662f\u5728\u505a\u7ebf\u6027\u5728\u7ec4\u5408\uff0c\u5b9e\u9645\u4e0a\u8fd8\u662f\u7ebf\u6027\u62df\u5408\uff0c\u5c31\u4ece\u795e\u7ecf\u7f51\u7edc\u9000\u5316\u5230\u4e86\u903b\u8f91\u56de\u5f52\u3002<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"478\" height=\"392\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-9.png\" alt=\"\" class=\"wp-image-2852\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-9.png 478w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-9-300x246.png 300w\" sizes=\"(max-width: 478px) 100vw, 478px\" \/><\/figure><\/div>\n\n\n<p> \u4e5f\u5c31\u662f\u8bf4\uff0c\u4e0d\u7ba1\u591a\u5c11\u5c42\u7684\u795e\u7ecf\u7f51\u7edc\uff0c\u5982\u679c\u4f7f\u7528\u7ebf\u6027\u6fc0\u6d3b\u51fd\u6570\uff0c\u90a3\u4e48\u548c\u6700\u7b80\u5355\u7684\u903b\u8f91\u56de\u5f52\u7684\u7ed3\u679c\u662f\u4e00\u6837\u7684\u3002 <\/p>\n\n\n<h2 class=\"wp-block-heading\">5.\u968f\u673a\u521d\u59cb\u5316<\/h2>\n\n\n<p>\u5bf9\u4e8e\u53c2\u6570w\u7684\u9009\u62e9\uff0c\u5982\u679c\u6211\u4eec\u5168\u90e8\u521d\u59cb\u5316\u4e3a0<\/p>\n\n\n<p> <\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"762\" height=\"379\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-10.png\" alt=\"\" class=\"wp-image-2853\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-10.png 762w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-10-300x149.png 300w\" sizes=\"(max-width: 762px) 100vw, 762px\" \/><\/figure><\/div>\n\n\n<p>\u6211\u4eec\u53ef\u4ee5\u53d1\u73b0\u4e0d\u7ba1\u7ecf\u8fc7\u591a\u5c11\u6b21\u8ba1\u7b97\uff0c\u9690\u85cf\u5c42\u7684\u795e\u7ecf\u5143\u7684\u503c\u90fd\u662f\u4e00\u6837\u7684\uff0c\u56e0\u4e3a\u5b83\u4eec\u6709\u7740\u540c\u6837\u7684\u8f93\u5165\u3001\u540c\u6837\u7684\u6743\u91cd\u3001\u540c\u6837\u7684\u6fc0\u6d3b\u51fd\u6570\uff0c\u56e0\u6b64\u5fc5\u7136\u6709\u540c\u6837\u7684\u7ed3\u679c\u3002\u4e5f\u5c31\u5931\u53bb\u4e86\u591a\u795e\u7ecf\u5143\u7684\u610f\u4e49\uff0c\u6211\u4eec\u79f0\u8fd9\u79cd\u95ee\u9898\u53eb\u7f51\u7edc\u7684\u5bf9\u79f0\u6027\u95ee\u9898\u3002<\/p>\n\n\n<p>\u56e0\u6b64\u6211\u4eec\u91c7\u7528\u968f\u673a\u521d\u59cb\u5316w\u4e3a\u4e00\u4e2a\u5f88\u5c0f\u7684\u6570\uff0c\u56e0\u4e3ab\u6ca1\u6709\u5bf9\u79f0\u6027\u7684\u95ee\u9898\uff0c\u56e0\u6b64\u6211\u4eec\u53ef\u4ee5\u968f\u610f\u521d\u59cb\u5316\uff0c\u53ef\u4ee5\u521d\u59cb\u5316\u4e3a0\u3002 <\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"907\" height=\"241\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-11.png\" alt=\"\" class=\"wp-image-2854\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-11.png 907w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-11-300x80.png 300w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-11-768x204.png 768w\" sizes=\"(max-width: 907px) 100vw, 907px\" \/><\/figure><\/div>\n\n\n<p> \u4e3a\u4ec0\u4e48\u968f\u673a\u521d\u59cb\u5316w\u4e3a\u4e00\u4e2a\u5f88\u5c0f\u7684\u6570\u5462\uff08\u4e5f\u5c31\u662f\u4e3a\u4ec0\u4e48\u4e580.01\u800c\u4e0d\u662f100\uff09\uff0c\u56e0\u4e3az = wx + b\uff0c\u5982\u679cw\u6bd4\u8f83\u5927\uff0cz\u4e5f\u5c31\u5927\uff0c\u56e0\u6b64\u5728\u6fc0\u6d3b\u7684\u65f6\u5019\u4f1a\u6fc0\u6d3b\u5230\u63a5\u8fd11\u7684\u4f4d\u7f6e\uff0c\u659c\u7387\u6bd4\u8f83\u4f4e\uff0c\u5b66\u4e60\u901f\u5ea6\u6bd4\u8f83\u6162\uff08\u5f53\u7136ReLU\u5e76\u4e0d\u5b58\u5728\u8fd9\u4e2a\u95ee\u9898\uff09\u3002 <\/p>\n\n\n<h2 class=\"wp-block-heading\">\u6d4b\u9a8c<\/h2>\n\n\n<p><strong>1. \u4ee5\u4e0b\u54ea\u4e00\u9879\u662f\u6b63\u786e\u7684\uff1f <\/strong><\/p>\n\n\n<ol><li> X\u662f\u4e00\u4e2a\u77e9\u9635\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5217\u90fd\u662f\u4e00\u4e2a\u8bad\u7ec3\u793a\u4f8b\u3002 <\/li><li><em>a<\/em>[2]4 \u662f\u7b2c\u4e8c\u5c42\u7b2c\u56db\u5c42\u795e\u7ecf\u5143\u7684\u6fc0\u6d3b\u7684\u8f93\u51fa\u3002 <\/li><li><em>a<\/em>[2](12)\u8868\u793a\u7b2c\u4e8c\u5c42\u548c\u7b2c\u5341\u4e8c\u5c42\u7684\u6fc0\u6d3b\u5411\u91cf\u3002 <\/li><li><em>a<\/em>[2] \u8868\u793a\u7b2c\u4e8c\u5c42\u7684\u6fc0\u6d3b\u5411\u91cf\u3002 <\/li><\/ol>\n\n\n<p>1\uff0c2\uff0c3\uff0c4\u3002<\/p>\n\n\n<p><strong>2. tanh\u6fc0\u6d3b\u51fd\u6570\u901a\u5e38\u6bd4\u9690\u85cf\u5c42\u5355\u5143\u7684sigmoid\u6fc0\u6d3b\u51fd\u6570\u6548\u679c\u66f4\u597d\uff0c\u56e0\u4e3a\u5176\u8f93\u51fa\u7684\u5e73\u5747\u503c\u66f4\u63a5\u8fd1\u4e8e\u96f6\uff0c\u56e0\u6b64\u5b83\u5c06\u6570\u636e\u96c6\u4e2d\u5728\u4e0b\u4e00\u5c42\u662f\u66f4\u597d\u7684\u9009\u62e9\uff0c\u8bf7\u95ee\u6b63\u786e\u5417\uff1f <\/strong><\/p>\n\n\n<p>\u6b63\u786e<\/p>\n\n\n<p><strong>3. \u5176\u4e2d\u54ea\u4e00\u4e2a\u662f\u7b2cl\u5c42\u5411\u524d\u4f20\u64ad\u7684\u6b63\u786e\u5411\u91cf\u5316\u5b9e\u73b0\uff0c\u5176\u4e2d1\u2264<\/strong><em><strong>l<\/strong><\/em><strong>\u2264<\/strong><em><strong>L<\/strong><\/em><\/p>\n\n\n<p>\u7b54\u6848\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"234\" height=\"65\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-13.png\" alt=\"\" class=\"wp-image-2856\"\/><\/figure><\/div>\n\n\n<p><strong>4. \u60a8\u6b63\u5728\u6784\u5efa\u4e00\u4e2a\u8bc6\u522b\u9ec4\u74dc\uff08y = 1\uff09\u4e0e\u897f\u74dc\uff08y = 0\uff09\u7684\u4e8c\u5143\u5206\u7c7b\u5668\u3002 \u4f60\u4f1a\u63a8\u8350\u54ea\u4e00\u79cd\u6fc0\u6d3b\u51fd\u6570\u7528\u4e8e\u8f93\u51fa\u5c42\uff1f <\/strong><\/p>\n\n\n<ol><li> ReLU<\/li><li>Leaky ReLU<\/li><li>sigmoid<\/li><li> tanh <\/li><\/ol>\n\n\n<p>3\uff0c \u6765\u81easigmoid\u51fd\u6570\u7684\u8f93\u51fa\u503c\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u7406\u89e3\u4e3a\u6982\u7387\u3002 <\/p>\n\n\n<p><strong>5. \u770b\u4e00\u4e0b\u4e0b\u9762\u7684\u4ee3\u7801\uff0c \u8bf7\u95eeB.shape\u7684\u503c\u662f\u591a\u5c11?  <\/strong><\/p>\n\n\n<pre class=\"wp-block-code\"><code>A = np.random.randn(4,3)\nB = np.sum(A, axis = 1, keepdims = True)<\/code><\/pre>\n\n\n<p>\uff084\uff0c1\uff09\u7531\u4e8ekeepdims=True\u7684\u5b58\u5728\uff0c\u4f1a\u4fdd\u6301\u77e9\u9635\u7684\u6027\u8d28\u800c\u4e0d\u4f1a\u53d8\u6210\uff084\uff0c\uff09\u7684\u6570\u7ec4\u5f62\u5f0f\u3002<\/p>\n\n\n<p><strong>6. \u5047\u8bbe\u4f60\u5df2\u7ecf\u5efa\u7acb\u4e86\u4e00\u4e2a\u795e\u7ecf\u7f51\u7edc\u3002 \u60a8\u51b3\u5b9a\u5c06\u6743\u91cd\u548c\u504f\u5dee\u521d\u59cb\u5316\u4e3a\u96f6\u3002 \u4ee5\u4e0b\u54ea\u9879\u9648\u8ff0\u662f\u6b63\u786e\u7684\uff1f <\/strong><\/p>\n\n\n<ol><li>\u7b2c\u4e00\u4e2a\u9690\u85cf\u5c42\u4e2d\u7684\u6bcf\u4e2a\u795e\u7ecf\u5143\u8282\u70b9\u5c06\u6267\u884c\u76f8\u540c\u7684\u8ba1\u7b97\u3002 \u6240\u4ee5\u5373\u4f7f\u7ecf\u8fc7\u591a\u6b21\u68af\u5ea6\u4e0b\u964d\u8fed\u4ee3\u540e\uff0c\u5c42\u4e2d\u7684\u6bcf\u4e2a\u795e\u7ecf\u5143\u8282\u70b9\u90fd\u4f1a\u8ba1\u7b97\u51fa\u4e0e\u5176\u4ed6\u795e\u7ecf\u5143\u8282\u70b9\u76f8\u540c\u7684\u4e1c\u897f\u3002<\/li><li> \u7b2c\u4e00\u4e2a\u9690\u85cf\u5c42\u4e2d\u7684\u6bcf\u4e2a\u795e\u7ecf\u5143\u5c06\u5728\u7b2c\u4e00\u6b21\u8fed\u4ee3\u4e2d\u6267\u884c\u76f8\u540c\u7684\u8ba1\u7b97\u3002 \u4f46\u7ecf\u8fc7\u4e00\u6b21\u68af\u5ea6\u4e0b\u964d\u8fed\u4ee3\u540e\uff0c\u4ed6\u4eec\u5c06\u5b66\u4f1a\u8ba1\u7b97\u4e0d\u540c\u7684\u4e1c\u897f\uff0c\u56e0\u4e3a\u6211\u4eec\u5df2\u7ecf\u201c\u7834\u574f\u4e86\u5bf9\u79f0\u6027\u201d\u3002 <\/li><li>\u7b2c\u4e00\u4e2a\u9690\u85cf\u5c42\u4e2d\u7684\u6bcf\u4e00\u4e2a\u795e\u7ecf\u5143\u90fd\u4f1a\u8ba1\u7b97\u51fa\u76f8\u540c\u7684\u4e1c\u897f\uff0c\u4f46\u662f\u4e0d\u540c\u5c42\u7684\u795e\u7ecf\u5143\u4f1a\u8ba1\u7b97\u4e0d\u540c\u7684\u4e1c\u897f\uff0c\u56e0\u6b64\u6211\u4eec\u5df2\u7ecf\u5b8c\u6210\u4e86\u201c\u5bf9\u79f0\u7834\u574f\u201d\u3002 <\/li><li>\u5373\u4f7f\u5728\u7b2c\u4e00\u6b21\u8fed\u4ee3\u4e2d\uff0c\u7b2c\u4e00\u4e2a\u9690\u85cf\u5c42\u7684\u795e\u7ecf\u5143\u4e5f\u4f1a\u6267\u884c\u4e0d\u540c\u7684\u8ba1\u7b97\uff0c \u4ed6\u4eec\u7684\u53c2\u6570\u5c06\u4ee5\u81ea\u5df1\u7684\u65b9\u5f0f\u4e0d\u65ad\u53d1\u5c55\u3002 <\/li><\/ol>\n\n\n<p>1.<\/p>\n\n\n<p><strong>7. Logistic\u56de\u5f52\u7684\u6743\u91cdw\u5e94\u8be5\u968f\u673a\u521d\u59cb\u5316\uff0c\u800c\u4e0d\u662f\u5168\u96f6\uff0c\u56e0\u4e3a\u5982\u679c\u521d\u59cb\u5316\u4e3a\u5168\u96f6\uff0c\u90a3\u4e48\u903b\u8f91\u56de\u5f52\u5c06\u65e0\u6cd5\u5b66\u4e60\u5230\u6709\u7528\u7684\u51b3\u7b56\u8fb9\u754c\uff0c\u56e0\u4e3a\u5b83\u5c06\u65e0\u6cd5\u201c\u7834\u574f\u5bf9\u79f0\u6027\u201d\uff0c\u662f\u6b63\u786e\u7684\u5417\uff1f <\/strong><\/p>\n\n\n<p>\u9519\u8bef\u3002 Logistic\u56de\u5f52\u6ca1\u6709\u9690\u85cf\u5c42\uff0c\u56e0\u6b64\u4e0d\u5b58\u5728\u591a\u4e2a\u795e\u7ecf\u5143\u6709\u5bf9\u79f0\u6027\u5bfc\u81f4\u9690\u85cf\u5c42\u5931\u6548\u3002<\/p>\n\n\n<p><strong>8. \u60a8\u5df2\u7ecf\u4e3a\u6240\u6709\u9690\u85cf\u5355\u5143\u4f7f\u7528tanh\u6fc0\u6d3b\u5efa\u7acb\u4e86\u4e00\u4e2a\u7f51\u7edc\u3002 \u4f7f\u7528np.random.randn\uff08..\uff0c..\uff09* 1000\u5c06\u6743\u91cd\u521d\u59cb\u5316\u4e3a\u76f8\u5bf9\u8f83\u5927\u7684\u503c\u3002 \u4f1a\u53d1\u751f\u4ec0\u4e48\uff1f <\/strong><\/p>\n\n\n<ol><li>\u8fd9\u6ca1\u5173\u7cfb\u3002\u53ea\u8981\u968f\u673a\u521d\u59cb\u5316\u6743\u91cd\uff0c\u68af\u5ea6\u4e0b\u964d\u4e0d\u53d7\u6743\u91cd\u5927\u5c0f\u7684\u5f71\u54cd\u3002<\/li><li>\u8fd9\u5c06\u5bfc\u81f4tanh\u7684\u8f93\u5165\u4e5f\u975e\u5e38\u5927\uff0c\u56e0\u6b64\u5bfc\u81f4\u68af\u5ea6\u4e5f\u53d8\u5927\u3002\u56e0\u6b64\uff0c\u60a8\u5fc5\u987b\u5c06\u03b1\u8bbe\u7f6e\u5f97\u975e\u5e38\u5c0f\u4ee5\u9632\u6b62\u53d1\u6563; \u8fd9\u4f1a\u51cf\u6162\u5b66\u4e60\u901f\u5ea6\u3002<\/li><li>\u8fd9\u4f1a\u5bfc\u81f4tanh\u7684\u8f93\u5165\u4e5f\u975e\u5e38\u5927\uff0c\u5bfc\u81f4\u5355\u4f4d\u88ab\u201c\u9ad8\u5ea6\u6fc0\u6d3b\u201d\uff0c\u4ece\u800c\u52a0\u5feb\u4e86\u5b66\u4e60\u901f\u5ea6\uff0c\u800c\u6743\u91cd\u5fc5\u987b\u4ece\u5c0f\u6570\u503c\u5f00\u59cb\u3002<\/li><li>\u8fd9\u5c06\u5bfc\u81f4tanh\u7684\u8f93\u5165\u4e5f\u5f88\u5927\uff0c\u56e0\u6b64\u5bfc\u81f4\u68af\u5ea6\u63a5\u8fd1\u4e8e\u96f6\uff0c \u4f18\u5316\u7b97\u6cd5\u5c06\u56e0\u6b64\u53d8\u5f97\u7f13\u6162\u3002<\/li><\/ol>\n\n\n<p>4\u3002 tanh\u5bf9\u4e8e\u8f83\u5927\u7684\u503c\u53d8\u5f97\u5e73\u5766\uff0c\u8fd9\u5bfc\u81f4\u5176\u68af\u5ea6\u63a5\u8fd1\u4e8e\u96f6\u3002 \u8fd9\u51cf\u6162\u4e86\u4f18\u5316\u7b97\u6cd5\u3002 <\/p>\n\n\n<p><strong>9.\u89c2\u5bdf\u4e0b\u9762\u7684\u795e\u7ecf\u7f51\u7edc\uff1a<\/strong><\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"463\" height=\"340\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-14.png\" alt=\"\" class=\"wp-image-2857\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-14.png 463w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-14-300x220.png 300w\" sizes=\"(max-width: 463px) 100vw, 463px\" \/><\/figure><\/div>\n\n\n<ol><li><em>b<\/em>[1] \u7684\u7ef4\u5ea6\u662f(4, 1)<\/li><li><em>W<\/em>[1] \u7684\u7ef4\u5ea6\u662f (4, 2) <\/li><li><em>W<\/em>[2] \u7684\u7ef4\u5ea6\u662f (1, 4) <\/li><li><em>b<\/em>[2] \u7684\u7ef4\u5ea6\u662f (1, 1) <\/li><\/ol>\n\n\n<p>1\uff0c2\uff0c3\uff0c4\u3002<\/p>\n\n\n<p><strong>10. \u4e0a\u4e00\u4e2a\u7f51\u7edc\u4e2d\uff0c<\/strong><em><strong>z<\/strong><\/em><strong>[1] \u548c <\/strong><em><strong>A<\/strong><\/em><strong>[1]\u7684\u7ef4\u5ea6\u662f\u591a\u5c11\uff08z = wx + b\uff09\uff1f  <\/strong><\/p>\n\n\n<p>z[1] \uff084\uff0cm\uff09\uff0cA[1]\uff084\uff0cm\uff09\u3002\uff08m\u662f\u6837\u672c\u4e2a\u6570\uff09\u3002<\/p>\n\n\n<h2 class=\"wp-block-heading\">\u7f16\u7a0b\u4f5c\u4e1a<\/h2>\n\n\n<p>\u9996\u5148\u5bfc\u5165\u76f8\u5173\u7684\u5305<\/p>\n\n\n<pre class=\"wp-block-preformatted\">import numpy as np<br \/>import matplotlib.pyplot as plt<br \/>from course_1_week_3.testCases import *<br \/>import sklearn.linear_model<br \/>from course_1_week_3.planar_utils import plot_decision_boundary, sigmoid, load_planar_dataset, load_extra_datasets<br \/><\/pre>\n\n\n<p>\u7136\u540e\u52a0\u8f7d\u6570\u636e\u5e76\u67e5\u770b\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\"># \u52a0\u8f7d\u6570\u636e<br \/>X, Y = load_planar_dataset()<br \/>print('X\u7684\u7ef4\u5ea6:', X.shape)<br \/>print('Y\u7684\u7ef4\u5ea6:', Y.shape)<br \/>plt.title('show point')<br \/>plt.scatter(X[0, :], X[1, :], c=Y[0, :], s=40, cmap=plt.cm.Spectral)<br \/>plt.show()<\/pre>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"545\" height=\"411\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-17.png\" alt=\"\" class=\"wp-image-2865\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-17.png 545w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-17-300x226.png 300w\" sizes=\"(max-width: 545px) 100vw, 545px\" \/><\/figure><\/div>\n\n\n<p>\u53ef\u4ee5\u770b\u5230\u6570\u636e\u7684\u6837\u5b50\u3002\u8fd9\u65f6\u5019\u6211\u4eec\u5c1d\u8bd5\u4f7f\u7528\u903b\u8f91\u56de\u5f52\u6765\u8fdb\u884c\u5206\u7c7b\u3002<\/p>\n\n\n<pre class=\"wp-block-preformatted\"># \u4f7f\u7528\u903b\u8f91\u56de\u5f52\u5904\u7406<br \/>clf = sklearn.linear_model.LogisticRegression()<br \/>clf.fit(X.T, Y.T)<br \/># planar_util\u91cc\u7684\u65b9\u6cd5   \u7ed8\u5236\u51b3\u7b56\u8fb9\u754c<br \/>plot_decision_boundary(lambda x: clf.predict(x), X, Y[0, :])<br \/>plt.title('Logistic Regression')<br \/>LR_predictions = clf.predict(X.T)<br \/>print(\"\u903b\u8f91\u56de\u5f52\u7684\u51c6\u786e\u6027\uff1a %d \" % float((np.dot(Y, LR_predictions) +<br \/>                               np.dot(1 - Y, 1 - LR_predictions)) \/ float(Y.size) * 100) +<br \/>      \"% \" + \"(\u6b63\u786e\u6807\u8bb0\u7684\u6570\u636e\u70b9\u6240\u5360\u7684\u767e\u5206\u6bd4)\")<br \/>plt.show()<\/pre>\n\n\n<p>\u753b\u51fa\u7684\u51b3\u7b56\u8fb9\u754c\u5982\u4e0b\u6548\u679c\u5e76\u4e0d\u597d\uff0c\u5e76\u4e14\u8f93\u51fa<\/p>\n\n\n<p>\u903b\u8f91\u56de\u5f52\u7684\u51c6\u786e\u6027\uff1a 47 % (\u6b63\u786e\u6807\u8bb0\u7684\u6570\u636e\u70b9\u6240\u5360\u7684\u767e\u5206\u6bd4)<\/p>\n\n\n<p>\u53ea\u670947%\u7684\u51c6\u786e\u7387\u3002<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"547\" height=\"404\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-18.png\" alt=\"\" class=\"wp-image-2866\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-18.png 547w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-18-300x222.png 300w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/figure><\/div>\n\n\n<p>\u90a3\u4e48\u5982\u679c\u4f7f\u7528\u4e0a\u4e00\u5468\u6211\u4eec\u5b66\u4e60\u7684\u5177\u6709\u903b\u8f91\u56de\u5f52\u601d\u7ef4\u7684\u795e\u7ecf\u7f51\u7edc\u5462\uff1f<\/p>\n\n\n<pre class=\"wp-block-preformatted\"># \u4f7f\u7528\u4e4b\u524d\u5199\u7684\u903b\u8f91\u56de\u5f52\u601d\u7ef4\u7684\u795e\u7ecf\u7f51\u7edc\u8fdb\u884c\u8ba1\u7b97<br \/>from course_1_week_2.Logistic import model<br \/>d = model(X.T, Y.T, X.T, Y.T)<\/pre>\n\n\n<p>\u6211\u4eec\u57282000\u6b21\u8fed\u4ee3\u540e\u53ef\u4ee5\u5f97\u5230\u4e00\u4e2a50%\u7684\u51c6\u786e\u7387\uff0c\u53ef\u89c1\u8fd9\u4e2a\u504f\u7f6eb\u786e\u5b9e\u53ef\u4ee5\u5bf9\u7ed3\u679c\u4ea7\u751f\u4e00\u5b9a\u7684\u5f71\u54cd\u3002<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"311\" height=\"184\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-24.png\" alt=\"\" class=\"wp-image-2872\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-24.png 311w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-24-300x177.png 300w\" sizes=\"(max-width: 311px) 100vw, 311px\" \/><\/figure><\/div>\n\n\n<p>\u4e0b\u9762\u6211\u4eec\u4f7f\u7528\u795e\u7ecf\u7f51\u7edc\u6765\u8fdb\u884c\u76f8\u5173\u7684\u8ba1\u7b97\u3002<\/p>\n\n\n<p>\u9996\u5148\u662f\u521d\u59cb\u5316\u53c2\u6570\uff0c\u9700\u8981\u968f\u673a\u521d\u59cb\u5316\u53c2\u6570\u3002<\/p>\n\n\n<pre class=\"wp-block-preformatted\">def init_parameters(n_x, n_h, n_y):<br \/>    <em>\"\"\"<br \/><\/em><em>    <\/em><em>\u521d\u59cb\u5316\u53c2\u6570<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> n_x: <\/em><em>\u8f93\u5165\u5c42\u4e2a\u6570<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> n_h: <\/em><em>\u9690\u85cf\u5c42\u4e2a\u6570<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> n_y: <\/em><em>\u8f93\u51fa\u5c42\u4e2a\u6570<br \/><\/em><em>    <\/em><strong><em>:return<\/em><\/strong><em>:<br \/><\/em><em>    \"\"\"<br \/><\/em><em>    <\/em># \u521d\u59cb\u5316\u4e00\u4e2a\u79cd\u5b50\uff0c\u4ee5\u4fdd\u8bc1\u5927\u5bb6\u7684\u7ed3\u679c\u4e00\u6837<br \/>    np.random.seed(2)<br \/>    W1 = np.random.randn(n_h, n_x) * 0.01<br \/>    b1 = np.zeros((n_h, 1))<br \/>    W2 = np.random.randn(n_y, n_h) * 0.01<br \/>    b2 = np.zeros((n_y, 1))<br \/>    parameters = {\"W1\": W1,<br \/>                  \"b1\": b1,<br \/>                  \"W2\": W2,<br \/>                  \"b2\": b2}<br \/>    assert (W1.shape == (n_h, n_x))<br \/>    assert (b1.shape == (n_h, 1))<br \/>    assert (W2.shape == (n_y, n_h))<br \/>    assert (b2.shape == (n_y, 1))<br \/>    return parameters<\/pre>\n\n\n<p>\u524d\u5411\u4f20\u64ad\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\">def forward_propagation(X, parameters):<br \/>    <em>\"\"\"<br \/><\/em><em>    <\/em><em>\u524d\u5411\u4f20\u64ad<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> X:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> parameters:<br \/><\/em><em>    <\/em><strong><em>:return<\/em><\/strong><em>:<br \/><\/em><em>    \"\"\"<br \/><\/em><em>    <\/em>W1 = parameters[\"W1\"]<br \/>    b1 = parameters[\"b1\"]<br \/>    W2 = parameters[\"W2\"]<br \/>    b2 = parameters[\"b2\"]<br \/>    Z1 = np.dot(W1, X) + b1<br \/>    A1 = np.tanh(Z1)<br \/>    Z2 = np.dot(W2, A1) + b2<br \/>    # \u8fd9\u91cc\u522b\u5fd8\u4e86\u4f7f\u7528sigmoid\u8fdb\u884c\u6fc0\u6d3b<br \/>    A2 = sigmoid(Z2)<br \/>    cache = {\"Z1\": Z1,<br \/>             \"A1\": A1,<br \/>             \"Z2\": Z2,<br \/>             \"A2\": A2}<br \/>    assert (A2.shape == (1, X.shape[1]))<br \/>    return A2, cache<\/pre>\n\n\n<p>\u8ba1\u7b97\u4ee3\u4ef7\uff0c\u516c\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"488\" height=\"71\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-25.png\" alt=\"\" class=\"wp-image-2873\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-25.png 488w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-25-300x44.png 300w\" sizes=\"(max-width: 488px) 100vw, 488px\" \/><\/figure><\/div>\n\n\n<pre class=\"wp-block-preformatted\">def compute_cost(A2, Y, parameters):<br \/>    <em>\"\"\"<br \/><\/em><em>    <\/em><em>\u8ba1\u7b97\u4ee3\u4ef7<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> A2: <\/em><em>\u8ba1\u7b97\u7ed3\u679c<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> Y: <\/em><em>\u6807\u7b7e<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> parameters: <\/em><em>\u7f51\u7edc\u53c2\u6570<br \/><\/em><em>    <\/em><strong><em>:return<\/em><\/strong><em>:<br \/><\/em><em>    \"\"\"<br \/><\/em><em>    <\/em>m = Y.shape[1]<br \/>    if m == 0:<br \/>        print()<br \/>    # ??? \u5e72\u561b\u7684<br \/>    W1 = parameters[\"W1\"]<br \/>    W2 = parameters[\"W2\"]<br \/>    # \u8ba1\u7b97\u6210\u672c<br \/>    logprobs = np.multiply(Y, np.log(A2)) + np.multiply((1 - Y), np.log(1 - A2))<br \/>    cost = - np.sum(logprobs) \/ m<br \/>    cost = float(np.squeeze(cost))<br \/>    assert (isinstance(cost, float))<br \/>    return cost<\/pre>\n\n\n<p>\u53cd\u5411\u4f20\u64ad\uff0c\u516c\u5f0f\u5982\u4e0b\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"964\" height=\"478\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-26.png\" alt=\"\" class=\"wp-image-2874\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-26.png 964w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-26-300x149.png 300w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-26-768x381.png 768w\" sizes=\"(max-width: 964px) 100vw, 964px\" \/><\/figure><\/div>\n\n\n<pre class=\"wp-block-preformatted\">def backward_propagation(parameters, cache, X, Y):<br \/>    <em>\"\"\"<br \/><\/em><em>    <\/em><em>\u53cd\u5411\u4f20\u64ad<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> parameters:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> cache:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> X:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> Y:<br \/><\/em><em>    <\/em><strong><em>:return<\/em><\/strong><em>:<br \/><\/em><em>    \"\"\"<br \/><\/em><em>    <\/em>m = X.shape[1]<br \/><br \/>    W1 = parameters[\"W1\"]<br \/>    W2 = parameters[\"W2\"]<br \/><br \/>    A1 = cache[\"A1\"]<br \/>    A2 = cache[\"A2\"]<br \/><br \/>    dZ2 = A2 - Y<br \/>    dW2 = (1 \/ m) * np.dot(dZ2, A1.T)<br \/>    db2 = (1 \/ m) * np.sum(dZ2, axis=1, keepdims=True)<br \/>    dZ1 = np.multiply(np.dot(W2.T, dZ2), 1 - np.power(A1, 2))<br \/>    dW1 = (1 \/ m) * np.dot(dZ1, X.T)<br \/>    db1 = (1 \/ m) * np.sum(dZ1, axis=1, keepdims=True)<br \/>    grads = {\"dW1\": dW1,<br \/>             \"db1\": db1,<br \/>             \"dW2\": dW2,<br \/>             \"db2\": db2}<br \/><br \/>    return grads<\/pre>\n\n\n<p>\u8ba1\u7b97\u51fa\u53cd\u5411\u4f20\u64ad\u7684\u503c\u540e\u6211\u4eec\u5c31\u9700\u8981\u66f4\u65b0\u65b0\u7684\u503c\uff0c\u4e0b\u56fe\u662f\u4e0d\u540c\u7684\u5b66\u4e60\u7387\u5bf9\u7ed3\u679c\u4ea7\u751f\u7684\u5f71\u54cd\uff1a<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/img-blog.csdn.net\/20180326213855129?watermark\/2\/text\/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM3MzMzMjY=\/font\/5a6L5L2T\/fontsize\/400\/fill\/I0JBQkFCMA==\/dissolve\/70\" alt=\"sgd\"\/><\/figure><\/div>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/img-blog.csdn.net\/20180326213918106?watermark\/2\/text\/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTM3MzMzMjY=\/font\/5a6L5L2T\/fontsize\/400\/fill\/I0JBQkFCMA==\/dissolve\/70\" alt=\"sgd_bad\"\/><\/figure><\/div>\n\n\n<pre class=\"wp-block-preformatted\">def update_parameters(parameters, grads, learning_rate=1.2):<br \/>    <em>\"\"\"<br \/><\/em><em>    <\/em><em>\u66f4\u65b0\u6743\u91cd<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> parameters:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> grads:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> learning_rate:<br \/><\/em><em>    <\/em><strong><em>:return<\/em><\/strong><em>:<br \/><\/em><em>    \"\"\"<br \/><\/em><em>    <\/em>W1, W2 = parameters[\"W1\"], parameters[\"W2\"]<br \/>    b1, b2 = parameters[\"b1\"], parameters[\"b2\"]<br \/><br \/>    dW1, dW2 = grads[\"dW1\"], grads[\"dW2\"]<br \/>    db1, db2 = grads[\"db1\"], grads[\"db2\"]<br \/><br \/>    W1 = W1 - learning_rate * dW1<br \/>    b1 = b1 - learning_rate * db1<br \/>    W2 = W2 - learning_rate * dW2<br \/>    b2 = b2 - learning_rate * db2<br \/><br \/>    parameters = {\"W1\": W1,<br \/>                  \"b1\": b1,<br \/>                  \"W2\": W2,<br \/>                  \"b2\": b2}<br \/><br \/>    return parameters<\/pre>\n\n\n<p>\u9884\u6d4b\u51fd\u6570\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\">def predict(parameters, X):<br \/>    <em>\"\"\"<br \/><\/em><em>    <\/em><em>\u9884\u6d4b\u51fd\u6570<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> parameters:<br \/><\/em><em>    <\/em><strong><em>:param<\/em><\/strong><em> X:<br \/><\/em><em>    <\/em><strong><em>:return<\/em><\/strong><em>:<br \/><\/em><em>    \"\"\"<br \/><\/em><em>    <\/em>A2, cache = forward_propagation(X, parameters)<br \/>    # \u56db\u820d\u4e94\u5165<br \/>    predictions = np.round(A2)<br \/><br \/>    return predictions<\/pre>\n\n\n<p>\u6700\u540e\u6211\u4eec\u5c06\u6240\u6709\u7684\u65b9\u6cd5\u96c6\u5408\u8d77\u6765\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\">def nn_model(X, Y, n_h, num_iterations, print_cost=False):<br \/>    <em>\"\"\"<br \/><\/em><em>    <\/em><em>\u53c2\u6570\uff1a<\/em><em><br \/><\/em><em>        X - <\/em><em>\u6570\u636e\u96c6<\/em><em>,<\/em><em>\u7ef4\u5ea6\u4e3a\uff08<\/em><em>2<\/em><em>\uff0c\u793a\u4f8b\u6570\uff09<\/em><em><br \/><\/em><em>        Y - <\/em><em>\u6807\u7b7e\uff0c\u7ef4\u5ea6\u4e3a\uff08<\/em><em>1<\/em><em>\uff0c\u793a\u4f8b\u6570\uff09<\/em><em><br \/><\/em><em>        n_h - <\/em><em>\u9690\u85cf\u5c42\u7684\u6570\u91cf<\/em><em><br \/><\/em><em>        num_iterations - <\/em><em>\u68af\u5ea6\u4e0b\u964d\u5faa\u73af\u4e2d\u7684\u8fed\u4ee3\u6b21\u6570<\/em><em><br \/><\/em><em>        print_cost - <\/em><em>\u5982\u679c\u4e3a<\/em><em>True<\/em><em>\uff0c\u5219\u6bcf<\/em><em>1000<\/em><em>\u6b21\u8fed\u4ee3\u6253\u5370\u4e00\u6b21\u6210\u672c\u6570\u503c<br \/><\/em><em><br \/><\/em><em>    \u8fd4\u56de\uff1a<\/em><em><br \/><\/em><em>        parameters - <\/em><em>\u6a21\u578b\u5b66\u4e60\u7684\u53c2\u6570\uff0c\u5b83\u4eec\u53ef\u4ee5\u7528\u6765\u8fdb\u884c\u9884\u6d4b\u3002<\/em><em><br \/><\/em><em>     \"\"\"<br \/><\/em><em><br \/><\/em><em>    <\/em>n_x = layer_sizes(X, Y)[0]<br \/>    n_y = layer_sizes(X, Y)[2]<br \/><br \/>    parameters = init_parameters(n_x, n_h, n_y)<br \/><br \/>    for i in range(num_iterations):<br \/>        A2, cache = forward_propagation(X, parameters)<br \/>        cost = compute_cost(A2, Y, parameters)<br \/>        grads = backward_propagation(parameters, cache, X, Y)<br \/>        parameters = update_parameters(parameters, grads, learning_rate=0.5)<br \/><br \/>        if print_cost:<br \/>            if i % 1000 == 0:<br \/>                print(\"\u7b2c \", i, \" \u6b21\u5faa\u73af\uff0c\u6210\u672c\u4e3a\uff1a\" + str(cost))<br \/>    return parameters<\/pre>\n\n\n<p>\u6211\u4eec\u8fdb\u884c\u4e00\u6b21\u6d4b\u8bd5\uff0c\u770b\u770b\u4f7f\u7528\u795e\u7ecf\u7f51\u7edc\u7684\u6548\u679c\u5982\u4f55\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\">parameters = nn_model(X, Y, n_h=4, num_iterations=10000, print_cost=True)<br \/><br \/># \u7ed8\u5236\u8fb9\u754c<br \/>plot_decision_boundary(lambda x: predict(parameters, x.T), X, Y[0, :])<br \/>plt.title(\"Decision Boundary for hidden layer size \" + str(4))<br \/><br \/>predictions = predict(parameters, X)<br \/>print('\u51c6\u786e\u7387: %d' % float((np.dot(Y, predictions.T) + np.dot(1 - Y, 1 - predictions.T)) \/ float(Y.size) * 100) + '%')<br \/>plt.show()<\/pre>\n\n\n<p>\u753b\u51fa\u4e0b\u56fe\uff0c\u5e76\u4e14\u8f93\u51fa\u51c6\u786e\u7387\u4e3a90%\u3002<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"545\" height=\"410\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-19.png\" alt=\"\" class=\"wp-image-2867\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-19.png 545w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-19-300x226.png 300w\" sizes=\"(max-width: 545px) 100vw, 545px\" \/><\/figure><\/div>\n\n\n<p>\u90a3\u5982\u679c\u6211\u4eec\u5c1d\u8bd5\u4f7f\u7528\u4e0d\u540c\u4e2a\u6570\u7684\u9690\u85cf\u5c42\u8282\u70b9\u6570\u5462\uff1f<\/p>\n\n\n<pre class=\"wp-block-preformatted\">plt.figure(figsize=(16, 32))<br \/>hidden_layer_sizes = [1, 2, 3, 4, 5, 20, 50]  # \u9690\u85cf\u5c42\u6570\u91cf<br \/>for i, n_h in enumerate(hidden_layer_sizes):<br \/>    plt.subplot(5, 2, i + 1)<br \/>    plt.title('Hidden Layer of size %d' % n_h)<br \/>    parameters = nn_model(X, Y, n_h, num_iterations=10000)<br \/>    plot_decision_boundary(lambda x: predict(parameters, x.T), X, Y[0,:])<br \/>    predictions = predict(parameters, X)<br \/>    accuracy = float((np.dot(Y, predictions.T) + np.dot(1 - Y, 1 - predictions.T)) \/ float(Y.size) * 100)<br \/>    print(\"\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a {}  \uff0c\u51c6\u786e\u7387: {} %\".format(n_h, accuracy))<br \/>plt.show()<\/pre>\n\n\n<p>\u6700\u540e\u8f93\u51fa\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\">\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a 1  \uff0c\u51c6\u786e\u7387: 67.25 %<br \/>\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a 2  \uff0c\u51c6\u786e\u7387: 67.0 %<br \/>\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a 3  \uff0c\u51c6\u786e\u7387: 90.75 %<br \/>\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a 4  \uff0c\u51c6\u786e\u7387: 90.5 %<br \/>\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a 5  \uff0c\u51c6\u786e\u7387: 91.0 %<br \/>\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a 20  \uff0c\u51c6\u786e\u7387: 91.25 %<br \/>\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a 50  \uff0c\u51c6\u786e\u7387: 90.75 %<\/pre>\n\n\n<p>\u5e76\u6709\u5982\u4e0b\u56fe\uff0c\u53ef\u4ee5\u770b\u51fa\u8f83\u5927\u7684\u9690\u85cf\u5c91\u89c4\u6a21\u53ef\u4ee5\u66f4\u597d\u7684\u62df\u5408\u6570\u636e\uff0c\u6709\u66f4\u9ad8\u7684\u51c6\u786e\u7387\u76f4\u81f3\u8fc7\u62df\u5408\u3002<\/p>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"425\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-20-1024x425.png\" alt=\"\" class=\"wp-image-2868\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-20-1024x425.png 1024w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-20-300x125.png 300w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-20-768x319.png 768w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-20-1200x498.png 1200w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-20.png 1322w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"421\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-21-1024x421.png\" alt=\"\" class=\"wp-image-2869\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-21-1024x421.png 1024w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-21-300x123.png 300w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-21-768x316.png 768w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-21-1200x493.png 1200w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-21.png 1323w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"420\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-22-1024x420.png\" alt=\"\" class=\"wp-image-2870\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-22-1024x420.png 1024w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-22-300x123.png 300w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-22-768x315.png 768w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-22.png 1110w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"577\" height=\"455\" src=\"\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-23.png\" alt=\"\" class=\"wp-image-2871\" srcset=\"http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-23.png 577w, http:\/\/www.sniper97.cn\/wp-content\/uploads\/2020\/02\/\u56fe\u7247-23-300x237.png 300w\" sizes=\"(max-width: 577px) 100vw, 577px\" \/><\/figure><\/div>\n\n\n<p>\u5b8c\u6574\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n\n\n<pre class=\"wp-block-preformatted\"># -*- coding:utf-8 -*-\n<em>\n<\/em>import numpy as np\nimport matplotlib.pyplot as plt\nfrom course_1_week_3.testCases import *\nimport sklearn.linear_model\nfrom course_1_week_3.planar_utils import plot_decision_boundary, sigmoid, load_planar_dataset, load_extra_datasets\n# \u52a0\u8f7d\u6570\u636e\nX, Y = load_planar_dataset()\nprint('X\u7684\u7ef4\u5ea6:', X.shape)\nprint('Y\u7684\u7ef4\u5ea6:', Y.shape)\nplt.title('show point')\nplt.scatter(X[0, :], X[1, :], c=Y[0, :], s=40, cmap=plt.cm.Spectral)\nplt.show()\n# \u4f7f\u7528\u903b\u8f91\u56de\u5f52\u5904\u7406\nclf = sklearn.linear_model.LogisticRegression()\nclf.fit(X.T, Y.T)\n# planar_util\u91cc\u7684\u65b9\u6cd5   \u7ed8\u5236\u51b3\u7b56\u8fb9\u754c\nplot_decision_boundary(lambda x: clf.predict(x), X, Y[0, :])\nplt.title('Logistic Regression')\nLR_predictions = clf.predict(X.T)\nprint(\"\u903b\u8f91\u56de\u5f52\u7684\u51c6\u786e\u6027\uff1a %d \" % float((np.dot(Y, LR_predictions) +\n                               np.dot(1 - Y, 1 - LR_predictions)) \/ float(Y.size) * 100) +\n      \"% \" + \"(\u6b63\u786e\u6807\u8bb0\u7684\u6570\u636e\u70b9\u6240\u5360\u7684\u767e\u5206\u6bd4)\")\nplt.show()\n# \u4f7f\u7528\u4e4b\u524d\u5199\u7684\u903b\u8f91\u56de\u5f52\u601d\u7ef4\u7684\u795e\u7ecf\u7f51\u7edc\u8fdb\u884c\u8ba1\u7b97\nfrom course_1_week_2.Logistic import model\nd = model(X.T, Y.T, X.T, Y.T)\n# \u795e\u7ecf\u7f51\u7edc\n# (5,3)    (2,3)\nX_asses, Y_asses = layer_sizes_test_case()\ndef layer_sizes(X, Y):\n    <em>\"\"\"\n    \u8fd4\u56de\u795e\u7ecf\u7f51\u7edc\u5404\u5c42\u7684\u4e2a\u6570\n    <\/em><strong><em>:param<\/em><\/strong><em> X: \u8f93\u5165\u6570\u636e\u96c6\n    <\/em><strong><em>:param<\/em><\/strong><em> Y: \u6807\u7b7e\n    <\/em><strong><em>:return<\/em><\/strong><em>:\n    \"\"\"\n    <\/em># \u8f93\u5165\u5c42\u4e2a\u6570\n    n_x = X.shape[0]\n    # \u9690\u85cf\u5c42\u4e2a\u6570\n    n_h = 4\n    # \u8f93\u51fa\u5c42\u4e2a\u6570\n    n_y = Y.shape[0]\n    return n_x, n_h, n_y\ndef init_parameters(n_x, n_h, n_y):\n    <em>\"\"\"\n    \u521d\u59cb\u5316\u53c2\u6570\n    <\/em><strong><em>:param<\/em><\/strong><em> n_x: \u8f93\u5165\u5c42\u4e2a\u6570\n    <\/em><strong><em>:param<\/em><\/strong><em> n_h: \u9690\u85cf\u5c42\u4e2a\u6570\n    <\/em><strong><em>:param<\/em><\/strong><em> n_y: \u8f93\u51fa\u5c42\u4e2a\u6570\n    <\/em><strong><em>:return<\/em><\/strong><em>:\n    \"\"\"\n    <\/em># \u521d\u59cb\u5316\u4e00\u4e2a\u79cd\u5b50\uff0c\u4ee5\u4fdd\u8bc1\u5927\u5bb6\u7684\u7ed3\u679c\u4e00\u6837\n    np.random.seed(2)\n    W1 = np.random.randn(n_h, n_x) * 0.01\n    b1 = np.zeros((n_h, 1))\n    W2 = np.random.randn(n_y, n_h) * 0.01\n    b2 = np.zeros((n_y, 1))\n    parameters = {\"W1\": W1,\n                  \"b1\": b1,\n                  \"W2\": W2,\n                  \"b2\": b2}\n    assert (W1.shape == (n_h, n_x))\n    assert (b1.shape == (n_h, 1))\n    assert (W2.shape == (n_y, n_h))\n    assert (b2.shape == (n_y, 1))\n    return parameters\ndef forward_propagation(X, parameters):\n    <em>\"\"\"\n    \u524d\u5411\u4f20\u64ad\n    <\/em><strong><em>:param<\/em><\/strong><em> X:\n    <\/em><strong><em>:param<\/em><\/strong><em> parameters:\n    <\/em><strong><em>:return<\/em><\/strong><em>:\n    \"\"\"\n    <\/em>W1 = parameters[\"W1\"]\n    b1 = parameters[\"b1\"]\n    W2 = parameters[\"W2\"]\n    b2 = parameters[\"b2\"]\n    Z1 = np.dot(W1, X) + b1\n    A1 = np.tanh(Z1)\n    Z2 = np.dot(W2, A1) + b2\n    # \u8fd9\u91cc\u522b\u5fd8\u4e86\u4f7f\u7528sigmoid\u8fdb\u884c\u6fc0\u6d3b\n    A2 = sigmoid(Z2)\n    cache = {\"Z1\": Z1,\n             \"A1\": A1,\n             \"Z2\": Z2,\n             \"A2\": A2}\n    assert (A2.shape == (1, X.shape[1]))\n    return A2, cache\ndef compute_cost(A2, Y, parameters):\n    <em>\"\"\"\n    \u8ba1\u7b97\u4ee3\u4ef7\n    <\/em><strong><em>:param<\/em><\/strong><em> A2: \u8ba1\u7b97\u7ed3\u679c\n    <\/em><strong><em>:param<\/em><\/strong><em> Y: \u6807\u7b7e\n    <\/em><strong><em>:param<\/em><\/strong><em> parameters: \u7f51\u7edc\u53c2\u6570\n    <\/em><strong><em>:return<\/em><\/strong><em>:\n    \"\"\"\n    <\/em>m = Y.shape[1]\n    if m == 0:\n        print()\n    # ??? \u5e72\u561b\u7684\n    W1 = parameters[\"W1\"]\n    W2 = parameters[\"W2\"]\n    # \u8ba1\u7b97\u6210\u672c\n    logprobs = np.multiply(Y, np.log(A2)) + np.multiply((1 - Y), np.log(1 - A2))\n    cost = - np.sum(logprobs) \/ m\n    cost = float(np.squeeze(cost))\n    assert (isinstance(cost, float))\n    return cost\ndef backward_propagation(parameters, cache, X, Y):\n    <em>\"\"\"\n    \u53cd\u5411\u4f20\u64ad\n    <\/em><strong><em>:param<\/em><\/strong><em> parameters:\n    <\/em><strong><em>:param<\/em><\/strong><em> cache:\n    <\/em><strong><em>:param<\/em><\/strong><em> X:\n    <\/em><strong><em>:param<\/em><\/strong><em> Y:\n    <\/em><strong><em>:return<\/em><\/strong><em>:\n    \"\"\"\n    <\/em>m = X.shape[1]\n    W1 = parameters[\"W1\"]\n    W2 = parameters[\"W2\"]\n    A1 = cache[\"A1\"]\n    A2 = cache[\"A2\"]\n    dZ2 = A2 - Y\n    dW2 = (1 \/ m) * np.dot(dZ2, A1.T)\n    db2 = (1 \/ m) * np.sum(dZ2, axis=1, keepdims=True)\n    dZ1 = np.multiply(np.dot(W2.T, dZ2), 1 - np.power(A1, 2))\n    dW1 = (1 \/ m) * np.dot(dZ1, X.T)\n    db1 = (1 \/ m) * np.sum(dZ1, axis=1, keepdims=True)\n    grads = {\"dW1\": dW1,\n             \"db1\": db1,\n             \"dW2\": dW2,\n             \"db2\": db2}\n    return grads\n# \u66f4\u65b0\u53c2\u6570\ndef update_parameters(parameters, grads, learning_rate=1.2):\n    <em>\"\"\"\n    \u66f4\u65b0\u6743\u91cd\n    <\/em><strong><em>:param<\/em><\/strong><em> parameters:\n    <\/em><strong><em>:param<\/em><\/strong><em> grads:\n    <\/em><strong><em>:param<\/em><\/strong><em> learning_rate:\n    <\/em><strong><em>:return<\/em><\/strong><em>:\n    \"\"\"\n    <\/em>W1, W2 = parameters[\"W1\"], parameters[\"W2\"]\n    b1, b2 = parameters[\"b1\"], parameters[\"b2\"]\n    dW1, dW2 = grads[\"dW1\"], grads[\"dW2\"]\n    db1, db2 = grads[\"db1\"], grads[\"db2\"]\n    W1 = W1 - learning_rate * dW1\n    b1 = b1 - learning_rate * db1\n    W2 = W2 - learning_rate * dW2\n    b2 = b2 - learning_rate * db2\n    parameters = {\"W1\": W1,\n                  \"b1\": b1,\n                  \"W2\": W2,\n                  \"b2\": b2}\n    return parameters\ndef nn_model(X, Y, n_h, num_iterations, print_cost=False):\n    <em>\"\"\"\n    \u53c2\u6570\uff1a\n        X - \u6570\u636e\u96c6,\u7ef4\u5ea6\u4e3a\uff082\uff0c\u793a\u4f8b\u6570\uff09\n        Y - \u6807\u7b7e\uff0c\u7ef4\u5ea6\u4e3a\uff081\uff0c\u793a\u4f8b\u6570\uff09\n        n_h - \u9690\u85cf\u5c42\u7684\u6570\u91cf\n        num_iterations - \u68af\u5ea6\u4e0b\u964d\u5faa\u73af\u4e2d\u7684\u8fed\u4ee3\u6b21\u6570\n        print_cost - \u5982\u679c\u4e3aTrue\uff0c\u5219\u6bcf1000\u6b21\u8fed\u4ee3\u6253\u5370\u4e00\u6b21\u6210\u672c\u6570\u503c\n    \u8fd4\u56de\uff1a\n        parameters - \u6a21\u578b\u5b66\u4e60\u7684\u53c2\u6570\uff0c\u5b83\u4eec\u53ef\u4ee5\u7528\u6765\u8fdb\u884c\u9884\u6d4b\u3002\n     \"\"\"\n    <\/em>n_x = layer_sizes(X, Y)[0]\n    n_y = layer_sizes(X, Y)[2]\n    parameters = init_parameters(n_x, n_h, n_y)\n    for i in range(num_iterations):\n        A2, cache = forward_propagation(X, parameters)\n        cost = compute_cost(A2, Y, parameters)\n        grads = backward_propagation(parameters, cache, X, Y)\n        parameters = update_parameters(parameters, grads, learning_rate=0.5)\n        if print_cost:\n            if i % 1000 == 0:\n                print(\"\u7b2c \", i, \" \u6b21\u5faa\u73af\uff0c\u6210\u672c\u4e3a\uff1a\" + str(cost))\n    return parameters\ndef predict(parameters, X):\n    <em>\"\"\"\n    \u9884\u6d4b\u51fd\u6570\n    <\/em><strong><em>:param<\/em><\/strong><em> parameters:\n    <\/em><strong><em>:param<\/em><\/strong><em> X:\n    <\/em><strong><em>:return<\/em><\/strong><em>:\n    \"\"\"\n    <\/em>A2, cache = forward_propagation(X, parameters)\n    # \u56db\u820d\u4e94\u5165\n    predictions = np.round(A2)\n    return predictions\nparameters = nn_model(X, Y, n_h=4, num_iterations=10000, print_cost=True)\n# \u7ed8\u5236\u8fb9\u754c\nplot_decision_boundary(lambda x: predict(parameters, x.T), X, Y[0, :])\nplt.title(\"Decision Boundary for hidden layer size \" + str(4))\npredictions = predict(parameters, X)\nprint('\u51c6\u786e\u7387: %d' % float((np.dot(Y, predictions.T) + np.dot(1 - Y, 1 - predictions.T)) \/ float(Y.size) * 100) + '%')\nplt.show()\nplt.figure(figsize=(16, 32))\nhidden_layer_sizes = [1, 2, 3, 4, 5, 20, 50]  # \u9690\u85cf\u5c42\u6570\u91cf\nfor i, n_h in enumerate(hidden_layer_sizes):\n    plt.subplot(5, 2, i + 1)\n    plt.title('Hidden Layer of size %d' % n_h)\n    parameters = nn_model(X, Y, n_h, num_iterations=10000)\n    plot_decision_boundary(lambda x: predict(parameters, x.T), X, Y[0,:])\n    predictions = predict(parameters, X)\n    accuracy = float((np.dot(Y, predictions.T) + np.dot(1 - Y, 1 - predictions.T)) \/ float(Y.size) * 100)\n    print(\"\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a {}  \uff0c\u51c6\u786e\u7387: {} %\".format(n_h, accuracy))\nplt.show()\n\"\"\"\n\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a 1  \uff0c\u51c6\u786e\u7387: 67.25 %\n\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a 2  \uff0c\u51c6\u786e\u7387: 67.0 %\n\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a 3  \uff0c\u51c6\u786e\u7387: 90.75 %\n\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a 4  \uff0c\u51c6\u786e\u7387: 90.5 %\n\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a 5  \uff0c\u51c6\u786e\u7387: 91.0 %\n\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a 20  \uff0c\u51c6\u786e\u7387: 91.25 %\n\u9690\u85cf\u5c42\u7684\u8282\u70b9\u6570\u91cf\uff1a 50  \uff0c\u51c6\u786e\u7387: 90.75 %\n\"\"\"<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5434\u6069\u8fbe\u6df1\u5ea6\u5b66\u4e60\u7b2c\u4e00\u8bfe\u7b2c\u4e09\u5468\uff0c\u6d45\u5c42\u795e\u7ecf\u7f51\u7edc 1.\u4ec0\u4e48\u662f\u795e\u7ecf\u7f51\u7edc \u795e\u7ecf\u7f51\u7edc\u5176\u5b9e\u5c31\u662f\u591a\u4e2a\u903b\u8f91\u56de\u5f52\u5355\u5143\u7684\u5806\u53e0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[7],"tags":[],"views":3474,"_links":{"self":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2842"}],"collection":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/comments?post=2842"}],"version-history":[{"count":0,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/posts\/2842\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/media?parent=2842"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/categories?post=2842"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sniper97.cn\/index.php\/wp-json\/wp\/v2\/tags?post=2842"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}