You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pgi29wjsp/_book/logistic_regression.html

652 lines
88 KiB

5 years ago
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>使用回归的思想进行分类-逻辑回归 · GitBook</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="gitbook/style.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-katex/katex.min.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="decision_tree.html" />
<link rel="prev" href="linear_regression.html" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="chapter " data-level="1.1" data-path="./">
<a href="./">
简介
</a>
</li>
<li class="chapter " data-level="1.2" data-path="machine_learning.html">
<a href="machine_learning.html">
机器学习概述
</a>
</li>
<li class="chapter " data-level="1.3" data-path="algorithm.html">
<a href="algorithm.html">
常见机器学习算法
</a>
<ul class="articles">
<li class="chapter " data-level="1.3.1" data-path="kNN.html">
<a href="kNN.html">
近朱者赤近墨者黑-kNN
</a>
</li>
<li class="chapter " data-level="1.3.2" data-path="linear_regression.html">
<a href="linear_regression.html">
最简单的回归算法-线性回归
</a>
</li>
<li class="chapter active" data-level="1.3.3" data-path="logistic_regression.html">
<a href="logistic_regression.html">
使用回归的思想进行分类-逻辑回归
</a>
</li>
<li class="chapter " data-level="1.3.4" data-path="decision_tree.html">
<a href="decision_tree.html">
最接近人类思维的算法-决策树
</a>
</li>
<li class="chapter " data-level="1.3.5" data-path="random_forest.html">
<a href="random_forest.html">
群众的力量是伟大的-随机森林
</a>
</li>
<li class="chapter " data-level="1.3.6" data-path="kMeans.html">
<a href="kMeans.html">
物以类聚人以群分-kMeans
</a>
</li>
<li class="chapter " data-level="1.3.7" data-path="AGNES.html">
<a href="AGNES.html">
以距离为尺-AGNES
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.4" data-path="metrics.html">
<a href="metrics.html">
模型评估指标
</a>
<ul class="articles">
<li class="chapter " data-level="1.4.1" data-path="classification_metrics.html">
<a href="classification_metrics.html">
分类性能评估指标
</a>
</li>
<li class="chapter " data-level="1.4.2" data-path="regression_metrics.html">
<a href="regression_metrics.html">
回归性能评估指标
</a>
</li>
<li class="chapter " data-level="1.4.3" data-path="cluster_metrics.html">
<a href="cluster_metrics.html">
聚类性能评估指标
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.5" data-path="sklearn.html">
<a href="sklearn.html">
使用sklearn进行机器学习
</a>
</li>
<li class="chapter " data-level="1.6" >
<span>
综合实战案例
</span>
<ul class="articles">
<li class="chapter " data-level="1.6.1" >
<span>
泰坦尼克生还预测
</span>
<ul class="articles">
<li class="chapter " data-level="1.6.1.1" data-path="titanic/introduction.html">
<a href="titanic/introduction.html">
简介
</a>
</li>
<li class="chapter " data-level="1.6.1.2" data-path="titanic/EDA.html">
<a href="titanic/EDA.html">
探索性数据分析(EDA)
</a>
</li>
<li class="chapter " data-level="1.6.1.3" data-path="titanic/feature engerning.html">
<a href="titanic/feature engerning.html">
特征工程
</a>
</li>
<li class="chapter " data-level="1.6.1.4" data-path="titanic/fit and predict.html">
<a href="titanic/fit and predict.html">
构建模型进行预测
</a>
</li>
<li class="chapter " data-level="1.6.1.5" data-path="titanic/tuning.html">
<a href="titanic/tuning.html">
调参
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="1.6.2" >
<span>
使用强化学习玩乒乓球游戏
</span>
<ul class="articles">
<li class="chapter " data-level="1.6.2.1" data-path="pingpong/what is reinforce learning.html">
<a href="pingpong/what is reinforce learning.html">
什么是强化学习
</a>
</li>
<li class="chapter " data-level="1.6.2.2" data-path="pingpong/Policy Gradient.html">
<a href="pingpong/Policy Gradient.html">
Policy Gradient原理
</a>
</li>
<li class="chapter " data-level="1.6.2.3" data-path="pingpong/coding.html">
<a href="pingpong/coding.html">
使用Policy Gradient玩乒乓球游戏
</a>
</li>
</ul>
</li>
</ul>
</li>
<li class="chapter " data-level="1.7" data-path="recommand.html">
<a href="recommand.html">
实训推荐
</a>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="." >使用回归的思想进行分类-逻辑回归</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="&#x4F7F;&#x7528;&#x56DE;&#x5F52;&#x7684;&#x601D;&#x60F3;&#x8FDB;&#x884C;&#x5206;&#x7C7B;-&#x903B;&#x8F91;&#x56DE;&#x5F52;">&#x4F7F;&#x7528;&#x56DE;&#x5F52;&#x7684;&#x601D;&#x60F3;&#x8FDB;&#x884C;&#x5206;&#x7C7B;-&#x903B;&#x8F91;&#x56DE;&#x5F52;</h1>
<p>&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x662F;&#x5C5E;&#x4E8E;&#x673A;&#x5668;&#x5B66;&#x4E60;&#x91CC;&#x9762;&#x7684;&#x76D1;&#x7763;&#x5B66;&#x4E60;&#xFF0C;&#x5B83;&#x662F;&#x4EE5;&#x56DE;&#x5F52;&#x7684;&#x601D;&#x60F3;&#x6765;&#x89E3;&#x51B3;&#x5206;&#x7C7B;&#x95EE;&#x9898;&#x7684;&#x4E00;&#x79CD;&#x975E;&#x5E38;&#x7ECF;&#x5178;&#x7684;&#x4E8C;&#x5206;&#x7C7B;&#x5206;&#x7C7B;&#x5668;&#x3002;&#x7531;&#x4E8E;&#x5176;&#x8BAD;&#x7EC3;&#x540E;&#x7684;&#x53C2;&#x6570;&#x6709;&#x8F83;&#x5F3A;&#x7684;&#x53EF;&#x89E3;&#x91CA;&#x6027;&#xFF0C;&#x5728;&#x8BF8;&#x591A;&#x9886;&#x57DF;&#x4E2D;&#xFF0C;&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x901A;&#x5E38;&#x7528;&#x4F5C; baseline&#x6A21;&#x578B;&#xFF0C;&#x4EE5;&#x65B9;&#x4FBF;&#x540E;&#x671F;&#x66F4;&#x597D;&#x7684;&#x6316;&#x6398;&#x4E1A;&#x52A1;&#x76F8;&#x5173;&#x4FE1;&#x606F;&#x6216;&#x63D0;&#x5347;&#x6A21;&#x578B;&#x6027;&#x80FD;&#x3002;</p>
<h2 id="&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x5927;&#x4F53;&#x601D;&#x60F3;">&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x5927;&#x4F53;&#x601D;&#x60F3;</h2>
<h3 id="&#x4EC0;&#x4E48;&#x662F;&#x903B;&#x8F91;&#x56DE;&#x5F52;">&#x4EC0;&#x4E48;&#x662F;&#x903B;&#x8F91;&#x56DE;&#x5F52;</h3>
<p>&#x5F53;&#x4E00;&#x770B;&#x5230;&#x201C;<strong>&#x56DE;&#x5F52;</strong>&#x201D;&#x8FD9;&#x4E24;&#x4E2A;&#x5B57;&#xFF0C;&#x53EF;&#x80FD;&#x4F1A;&#x8BA4;&#x4E3A;&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x662F;&#x4E00;&#x79CD;&#x89E3;&#x51B3;&#x56DE;&#x5F52;&#x95EE;&#x9898;&#x7684;&#x7B97;&#x6CD5;&#xFF0C;&#x7136;&#x800C;&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x662F;&#x901A;&#x8FC7;&#x56DE;&#x5F52;&#x7684;&#x601D;&#x60F3;&#x6765;&#x89E3;&#x51B3;<strong>&#x4E8C;&#x5206;&#x7C7B;</strong>&#x95EE;&#x9898;&#x7684;&#x7B97;&#x6CD5;&#x3002;</p>
<p>&#x90A3;&#x4E48;&#x95EE;&#x9898;&#x6765;&#x4E86;&#xFF0C;&#x56DE;&#x5F52;&#x7684;&#x7B97;&#x6CD5;&#x600E;&#x6837;&#x89E3;&#x51B3;&#x5206;&#x7C7B;&#x95EE;&#x9898;&#x5462;&#xFF1F;&#x5176;&#x5B9E;&#x5F88;&#x7B80;&#x5355;&#xFF0C;&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x662F;&#x5C06;&#x6837;&#x672C;&#x7279;&#x5F81;&#x548C;&#x6837;&#x672C;&#x6240;&#x5C5E;&#x7C7B;&#x522B;&#x7684;&#x6982;&#x7387;&#x8054;&#x7CFB;&#x5728;&#x4E00;&#x8D77;&#xFF0C;&#x5047;&#x8BBE;&#x73B0;&#x5728;&#x5DF2;&#x7ECF;&#x8BAD;&#x7EC3;&#x597D;&#x4E86;&#x4E00;&#x4E2A;&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x7684;&#x6A21;&#x578B;&#x4E3A;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>f</mi><mo>(</mo><mi>x</mi><mo>)</mo></mrow><annotation encoding="application/x-tex">f(x)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.10764em;">f</span><span class="mopen">(</span><span class="mord mathit">x</span><span class="mclose">)</span></span></span></span>&#xFF0C;&#x6A21;&#x578B;&#x7684;&#x8F93;&#x51FA;&#x662F;&#x6837;&#x672C;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>x</mi></mrow><annotation encoding="application/x-tex">x</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.43056em;"></span><span class="strut bottom" style="height:0.43056em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit">x</span></span></span></span>&#x7684;&#x6807;&#x7B7E;&#x662F;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>1</mn></mrow><annotation encoding="application/x-tex">1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">1</span></span></span></span>&#x7684;&#x6982;&#x7387;&#xFF0C;&#x5219;&#x8BE5;&#x6A21;&#x578B;&#x53EF;&#x4EE5;&#x8868;&#x793A;&#x6210;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mover accent="true"><mi>p</mi><mo>^</mo></mover><mo>=</mo><mi>f</mi><mo>(</mo><mi>x</mi><mo>)</mo></mrow><annotation encoding="application/x-tex">\hat p=f(x)</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord accent"><span class="vlist"><span style="top:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="mord mathit">p</span></span><span style="top:0em;margin-left:0.16668em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="accent-body"><span>^</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span><span class="mrel">=</span><span class="mord mathit" style="margin-right:0.10764em;">f</span><span class="mopen">(</span><span class="mord mathit">x</span><span class="mclose">)</span></span></span></span>&#x3002;&#x82E5;&#x5F97;&#x5230;&#x4E86;&#x6837;&#x672C;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>x</mi></mrow><annotation encoding="application/x-tex">x</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.43056em;"></span><span class="strut bottom" style="height:0.43056em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit">x</span></span></span></span>&#x5C5E;&#x4E8E;&#x6807;&#x7B7E;<span class="katex"><span class="katex-mathml"><math><
0 &amp; \hat p &lt;0.5 \\
1 &amp; \hat p &gt;0.5
\end{cases}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:1.75em;"></span><span class="strut bottom" style="height:3.0000299999999998em;vertical-align:-1.25003em;"></span><span class="base textstyle uncramped"><span class="mord accent"><span class="vlist"><span style="top:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="mord mathit" style="margin-right:0.03588em;">y</span></span><span style="top:0em;margin-left:0.11112em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="accent-body"><span>^</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span><span class="mrel">=</span><span class="minner textstyle uncramped"><span class="mopen style-wrap reset-textstyle textstyle uncramped" style="top:0em;"><span class="delimsizing size4">{</span></span><span class="mord"><span class="mtable"><span class="col-align-l"><span class="vlist"><span style="top:-0.6819999999999999em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="mord textstyle uncramped"><span class="mord mathrm">0</span></span></span><span style="top:0.7579999999999999em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="mord textstyle uncramped"><span class="mord mathrm">1</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span><span class="arraycolsep" style="width:1em;"></span><span class="col-align-l"><span class="vlist"><span style="top:-0.6819999999999999em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="mord textstyle uncramped"><span class="mord accent"><span class="vlist"><span style="top:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="mord mathit">p</span></span><span style="top:0em;margin-left:0.16668em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="accent-body"><span>^</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span><span class="mrel">&lt;</span><span class="mord mathrm">0</span><span class="mord mathrm">.</span><span class="mord mathrm">5</span></span></span><span style="top:0.7579999999999999em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="mord textstyle uncramped"><span class="mord accent"><span class="vlist"><span style="top:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="mord mathit">p</span></span><span style="top:0em;margin-left:0.16668em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="accent-body"><span>^</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span><span class="mrel">&gt;</span><span class="mord mathrm">0</span><span class="mord mathrm">.</span><span class="mord mathrm">5</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span></span><span class="mclose sizing reset-size5 size5 reset-textstyle textstyle uncramped nulldelimiter"></span></span></span></span></span>(&#x5176;&#x4E2D;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mover accent="true"><mi>y</mi><mo>^</mo></mover></mrow
<p><strong>&#x7531;&#x4E8E;&#x6982;&#x7387;&#x662F; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn></mrow><annotation encoding="application/x-tex">0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span></span></span></span> &#x5230; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>1</mn></mrow><annotation encoding="application/x-tex">1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">1</span></span></span></span> &#x7684;&#x5B9E;&#x6570;&#xFF0C;&#x6240;&#x4EE5;&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x82E5;&#x53EA;&#x9700;&#x8981;&#x8BA1;&#x7B97;&#x51FA;&#x6837;&#x672C;&#x6240;&#x5C5E;&#x6807;&#x7B7E;&#x7684;&#x6982;&#x7387;&#x5C31;&#x662F;&#x4E00;&#x79CD;&#x56DE;&#x5F52;&#x7B97;&#x6CD5;&#xFF0C;&#x82E5;&#x9700;&#x8981;&#x8BA1;&#x7B97;&#x51FA;&#x6837;&#x672C;&#x6240;&#x5C5E;&#x6807;&#x7B7E;&#xFF0C;&#x5219;&#x5C31;&#x662F;&#x4E00;&#x79CD;&#x4E8C;&#x5206;&#x7C7B;&#x7B97;&#x6CD5;&#x3002;</strong></p>
<p>&#x90A3;&#x4E48;&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x4E2D;&#x6837;&#x672C;&#x6240;&#x5C5E;&#x6807;&#x7B7E;&#x7684;&#x6982;&#x7387;&#x600E;&#x6837;&#x8BA1;&#x7B97;&#x5462;&#xFF1F;&#x5176;&#x5B9E;&#x548C;&#x7EBF;&#x6027;&#x56DE;&#x5F52;&#x6709;&#x5173;&#x7CFB;&#xFF0C;&#x5B66;&#x4E60;&#x4E86;&#x7EBF;&#x6027;&#x56DE;&#x5F52;&#x7684;&#x8BDD;&#x80AF;&#x5B9A;&#x77E5;&#x9053;&#x7EBF;&#x6027;&#x56DE;&#x5F52;&#x5C31;&#x662F;&#x8BAD;&#x7EC3;&#x51FA;&#x4E00;&#x7EC4;&#x53C2;&#x6570; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>W</mi></mrow><annotation encoding="application/x-tex">W</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.13889em;">W</span></span></span></span> &#x548C; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>b</mi></mrow><annotation encoding="application/x-tex">b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.69444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit">b</span></span></span></span> &#x6765;&#x62DF;&#x5408;&#x6837;&#x672C;&#x6570;&#x636E;&#xFF0C;&#x7EBF;&#x6027;&#x56DE;&#x5F52;&#x7684;&#x8F93;&#x51FA;&#x4E3A;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mover accent="true"><mi>y</mi><mo>^</mo></mover><mo>=</mo><mi>W</mi><mi>x</mi><mo>+</mo><mi>b</mi></mrow><annotation encoding="application/x-tex">\hat y=Wx+b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="base textstyle uncramped"><span class="mord accent"><span class="vlist"><span style="top:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="mord mathit" style="margin-right:0.03588em;">y</span></span><span style="top:0em;margin-left:0.11112em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="accent-body"><span>^</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span><span class="mrel">=</span><span class="mord mathit" style="margin-right:0.13889em;">W</span><span class="mord mathit">x</span><span class="mbin">+</span><span class="mord mathit">b</span></span></span></span> &#x3002;&#x4E0D;&#x8FC7;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mover accent="true"><mi>y</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\hat y</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="base textstyle uncramped"><span class="mord accent"><span class="vlist"><span style="top:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="mord mathit" style="margin-right:0.03588em;">y</span></span><span style="top:0em;margin-left:0.11112em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="accent-body"><span>^</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span></span></span>&#x7684;&#x503C;&#x57DF;&#x662F;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mo>(</mo><mo>&#x2212;</mo><mi mathvariant="normal">&#x221E;</mi><mo separat
<h3 id="sigmoid&#x51FD;&#x6570;">sigmoid&#x51FD;&#x6570;</h3>
<p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>s</mi><mi>i</mi><mi>g</mi><mi>m</mi><mi>o</mi><mi>i</mi><mi>d</mi></mrow><annotation encoding="application/x-tex">sigmoid</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="base textstyle uncramped"><span class="mord mathit">s</span><span class="mord mathit">i</span><span class="mord mathit" style="margin-right:0.03588em;">g</span><span class="mord mathit">m</span><span class="mord mathit">o</span><span class="mord mathit">i</span><span class="mord mathit">d</span></span></span></span> &#x51FD;&#x6570;&#x7684;&#x516C;&#x5F0F;&#x4E3A;&#xFF1A;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>&#x3C3;</mi><mo>(</mo><mi>t</mi><mo>)</mo><mo>=</mo><mn>1</mn><mi mathvariant="normal">/</mi><mn>1</mn><mo>+</mo><msup><mi>e</mi><mrow><mo>&#x2212;</mo><mi>t</mi></mrow></msup></mrow><annotation encoding="application/x-tex">\sigma(t)=1/1+e^{-t}</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.7935559999999999em;"></span><span class="strut bottom" style="height:1.043556em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.03588em;">&#x3C3;</span><span class="mopen">(</span><span class="mord mathit">t</span><span class="mclose">)</span><span class="mrel">=</span><span class="mord mathrm">1</span><span class="mord mathrm">/</span><span class="mord mathrm">1</span><span class="mbin">+</span><span class="mord"><span class="mord mathit">e</span><span class="msupsub"><span class="vlist"><span style="top:-0.363em;margin-right:0.05em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="reset-textstyle scriptstyle uncramped mtight"><span class="mord scriptstyle uncramped mtight"><span class="mord mtight">&#x2212;</span><span class="mord mathit mtight">t</span></span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span></span></span></span>&#x3002;&#x51FD;&#x6570;&#x56FE;&#x50CF;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;&#xFF1A;</p>
<p><img src="img/20.jpg" alt=""></p>
<p>&#x4ECE;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>s</mi><mi>i</mi><mi>g</mi><mi>m</mi><mi>o</mi><mi>i</mi><mi>d</mi></mrow><annotation encoding="application/x-tex">sigmoid</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="base textstyle uncramped"><span class="mord mathit">s</span><span class="mord mathit">i</span><span class="mord mathit" style="margin-right:0.03588em;">g</span><span class="mord mathit">m</span><span class="mord mathit">o</span><span class="mord mathit">i</span><span class="mord mathit">d</span></span></span></span>&#x51FD;&#x6570;&#x7684;&#x56FE;&#x50CF;&#x53EF;&#x4EE5;&#x770B;&#x51FA;&#x5F53;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>t</mi></mrow><annotation encoding="application/x-tex">t</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.61508em;"></span><span class="strut bottom" style="height:0.61508em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit">t</span></span></span></span>&#x8D8B;&#x8FD1;&#x4E8E;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mo>&#x2212;</mo><mi mathvariant="normal">&#x221E;</mi></mrow><annotation encoding="application/x-tex">-\infty</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.58333em;"></span><span class="strut bottom" style="height:0.66666em;vertical-align:-0.08333em;"></span><span class="base textstyle uncramped"><span class="mord">&#x2212;</span><span class="mord mathrm">&#x221E;</span></span></span></span>&#x65F6;&#x51FD;&#x6570;&#x503C;&#x8D8B;&#x8FD1;&#x4E8E;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn></mrow><annotation encoding="application/x-tex">0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span></span></span></span>&#xFF0C;&#x5F53;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>t</mi></mrow><annotation encoding="application/x-tex">t</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.61508em;"></span><span class="strut bottom" style="height:0.61508em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit">t</span></span></span></span>&#x8D8B;&#x8FD1;&#x4E8E;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mo>+</mo><mi mathvariant="normal">&#x221E;</mi></mrow><annotation encoding="application/x-tex">+\infty</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.58333em;"></span><span class="strut bottom" style="height:0.66666em;vertical-align:-0.08333em;"></span><span class="base textstyle uncramped"><span class="mord">+</span><span class="mord mathrm">&#x221E;</span></span></span></span>&#x65F6;&#x51FD;&#x6570;&#x503C;&#x8D8B;&#x8FD1;&#x4E8E;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>1</mn></mrow><annotation encoding="application/x-tex">1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">1</span></span></span></span>&#x3002;&#x53EF;&#x89C1;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>s</mi><mi>i</mi><mi>g</mi><mi>m</mi><mi>o</mi><mi>i</mi><mi>d</mi></mrow><annotation encoding="application/x-tex">sigmoid</annotation></semantics></math></span>
<h2 id="&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x7684;&#x635F;&#x5931;&#x51FD;&#x6570;">&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x7684;&#x635F;&#x5931;&#x51FD;&#x6570;</h2>
<p>&#x5728;&#x9884;&#x6D4B;&#x6837;&#x672C;&#x5C5E;&#x4E8E;&#x54EA;&#x4E2A;&#x7C7B;&#x522B;&#x65F6;&#x53D6;&#x51B3;&#x4E8E;&#x7B97;&#x51FA;&#x6765;&#x7684;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mover accent="true"><mi>p</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\hat p</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="base textstyle uncramped"><span class="mord accent"><span class="vlist"><span style="top:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="mord mathit">p</span></span><span style="top:0em;margin-left:0.16668em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="accent-body"><span>^</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span></span></span>&#x3002;&#x4ECE;&#x53E6;&#x5916;&#x4E00;&#x4E2A;&#x89D2;&#x5EA6;&#x6765;&#x8BF4;&#xFF0C;&#x5047;&#x8BBE;&#x73B0;&#x5728;&#x6709;&#x4E00;&#x4E2A;&#x6837;&#x672C;&#x7684;&#x771F;&#x5B9E;&#x7C7B;&#x522B;&#x4E3A; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>1</mn></mrow><annotation encoding="application/x-tex">1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">1</span></span></span></span> &#xFF0C;&#x6A21;&#x578B;&#x9884;&#x6D4B;&#x6837;&#x672C;&#x4E3A;&#x7C7B;&#x522B; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>1</mn></mrow><annotation encoding="application/x-tex">1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">1</span></span></span></span> &#x7684;&#x6982;&#x7387;&#x4E3A; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn><mi mathvariant="normal">.</mi><mn>9</mn></mrow><annotation encoding="application/x-tex">0.9</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span><span class="mord mathrm">.</span><span class="mord mathrm">9</span></span></span></span> &#x7684;&#x8BDD;&#xFF0C;&#x5C31;&#x610F;&#x5473;&#x7740;&#x8FD9;&#x4E2A;&#x6A21;&#x578B;&#x8BA4;&#x4E3A;&#x5F53;&#x524D;&#x6837;&#x672C;&#x7684;&#x7C7B;&#x522B;&#x6709; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>9</mn><mn>0</mn><mi mathvariant="normal">%</mi></mrow><annotation encoding="application/x-tex">90\%</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:0.80556em;vertical-align:-0.05556em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">9</span><span class="mord mathrm">0</span><span class="mord mathrm">%</span></span></span></span> &#x7684;&#x53EF;&#x80FD;&#x6027;&#x4E3A; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>1</mn></mrow><annotation encoding="application/x-tex">1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span clas
<p>&#x5F53;&#x7136;&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x7684;&#x635F;&#x5931;&#x51FD;&#x6570;&#x4E0D;&#x4EC5;&#x4EC5;&#x4E0E; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mover accent="true"><mi>p</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\hat p</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.8888799999999999em;vertical-align:-0.19444em;"></span><span class="base textstyle uncramped"><span class="mord accent"><span class="vlist"><span style="top:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="mord mathit">p</span></span><span style="top:0em;margin-left:0.16668em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="accent-body"><span>^</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span></span></span></span> &#x6709;&#x5173;&#xFF0C;&#x5B83;&#x8FD8;&#x4E0E;&#x771F;&#x5B9E;&#x7C7B;&#x522B;&#x6709;&#x5173;&#x3002;&#x5047;&#x8BBE;&#x73B0;&#x5728;&#x6709;&#x4E24;&#x79CD;&#x60C5;&#x51B5;&#xFF0C;<strong>&#x60C5;&#x51B5; A</strong> &#xFF1A;&#x73B0;&#x5728;&#x6709;&#x4E2A;&#x6837;&#x672C;&#x7684;&#x771F;&#x5B9E;&#x7C7B;&#x522B;&#x662F; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn></mrow><annotation encoding="application/x-tex">0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span></span></span></span> &#xFF0C;&#x4F46;&#x662F;&#x6A21;&#x578B;&#x9884;&#x6D4B;&#x51FA;&#x6765;&#x8BE5;&#x6837;&#x672C;&#x662F;&#x7C7B;&#x522B; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>1</mn></mrow><annotation encoding="application/x-tex">1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">1</span></span></span></span> &#x7684;&#x6982;&#x7387;&#x662F; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn><mi mathvariant="normal">.</mi><mn>7</mn></mrow><annotation encoding="application/x-tex">0.7</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span><span class="mord mathrm">.</span><span class="mord mathrm">7</span></span></span></span>&#xFF08;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x7C7B;&#x522B; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn></mrow><annotation encoding="application/x-tex">0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span></span></span></span> &#x7684;&#x6982;&#x7387;&#x4E3A; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn><mi mathvariant="normal">.</mi><mn>3</mn></mrow><annotation encoding="application/x-tex">0.3</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span><span class="mord mathrm">.</span><span clas
<p>&#x5047;&#x8BBE;&#x73B0;&#x5728;&#x53C8;&#x6709;&#x4E24;&#x79CD;&#x60C5;&#x51B5;&#xFF0C;<strong>&#x60C5;&#x51B5;A&#xFF1A;</strong> &#x73B0;&#x5728;&#x6709;&#x4E2A;&#x6837;&#x672C;&#x7684;&#x771F;&#x5B9E;&#x7C7B;&#x522B;&#x662F; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn></mrow><annotation encoding="application/x-tex">0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span></span></span></span> &#xFF0C;&#x4F46;&#x662F;&#x6A21;&#x578B;&#x9884;&#x6D4B;&#x51FA;&#x6765;&#x8BE5;&#x6837;&#x672C;&#x662F;&#x7C7B;&#x522B; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>1</mn></mrow><annotation encoding="application/x-tex">1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">1</span></span></span></span> &#x7684;&#x6982;&#x7387;&#x662F; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn><mi mathvariant="normal">.</mi><mn>7</mn></mrow><annotation encoding="application/x-tex">0.7</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span><span class="mord mathrm">.</span><span class="mord mathrm">7</span></span></span></span>&#xFF08;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x7C7B;&#x522B; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn></mrow><annotation encoding="application/x-tex">0</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span></span></span></span> &#x7684;&#x6982;&#x7387;&#x4E3A; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>0</mn><mi mathvariant="normal">.</mi><mn>3</mn></mrow><annotation encoding="application/x-tex">0.3</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">0</span><span class="mord mathrm">.</span><span class="mord mathrm">3</span></span></span></span>&#xFF09;&#xFF1B;<strong>&#x60C5;&#x51B5;B&#xFF1A;</strong>&#x73B0;&#x5728;&#x6709;&#x4E2A;&#x6837;&#x672C;&#x7684;&#x771F;&#x5B9E;&#x7C7B;&#x522B;&#x662F; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>1</mn></mrow><annotation encoding="application/x-tex">1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">1</span></span></span></span>&#xFF0C;&#x4F46;&#x662F;&#x6A21;&#x578B;&#x9884;&#x6D4B;&#x51FA;&#x6765;&#x8BE5;&#x6837;&#x672C;&#x662F;&#x7C7B;&#x522B; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mn>1</mn></mrow><annotation encoding="application/x-tex">1</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.64444em;"></span><span class="strut bottom" style="height:0.64444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathrm">1</span></span></span></span> &#x7684;&#x6982;&#x7387;&#x662F; <span class="katex"
<p>&#x6240;&#x4EE5;&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x7684;&#x635F;&#x5931;&#x51FD;&#x6570;&#x5982;&#x4E0B;&#xFF0C;&#x5176;&#x4E2D; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>c</mi><mi>o</mi><mi>s</mi><mi>t</mi></mrow><annotation encoding="application/x-tex">cost</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.61508em;"></span><span class="strut bottom" style="height:0.61508em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit">c</span><span class="mord mathit">o</span><span class="mord mathit">s</span><span class="mord mathit">t</span></span></span></span> &#x8868;&#x793A;&#x635F;&#x5931;&#x51FD;&#x6570;&#x7684;&#x503C;&#xFF0C;$y$ &#x8868;&#x793A;&#x6837;&#x672C;&#x7684;&#x771F;&#x5B9E;&#x7C7B;&#x522B;&#xFF1A;</p>
<p><span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>c</mi><mi>o</mi><mi>s</mi><mi>t</mi><mo>=</mo><mo>&#x2212;</mo><mi>y</mi><mi>l</mi><mi>o</mi><mi>g</mi><mo>(</mo><mover accent="true"><mi>p</mi><mo>^</mo></mover><mo>)</mo><mo>&#x2212;</mo><mo>(</mo><mn>1</mn><mo>&#x2212;</mo><mi>y</mi><mo>)</mo><mi>l</mi><mi>o</mi><mi>g</mi><mo>(</mo><mn>1</mn><mo>&#x2212;</mo><mover accent="true"><mi>p</mi><mo>^</mo></mover><mo>)</mo></mrow><annotation encoding="application/x-tex">
cost=-ylog(\hat p)-(1-y)log(1-\hat p)
</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mord mathit">c</span><span class="mord mathit">o</span><span class="mord mathit">s</span><span class="mord mathit">t</span><span class="mrel">=</span><span class="mord">&#x2212;</span><span class="mord mathit" style="margin-right:0.03588em;">y</span><span class="mord mathit" style="margin-right:0.01968em;">l</span><span class="mord mathit">o</span><span class="mord mathit" style="margin-right:0.03588em;">g</span><span class="mopen">(</span><span class="mord accent"><span class="vlist"><span style="top:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="mord mathit">p</span></span><span style="top:0em;margin-left:0.16668em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="accent-body"><span>^</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span><span class="mclose">)</span><span class="mbin">&#x2212;</span><span class="mopen">(</span><span class="mord mathrm">1</span><span class="mbin">&#x2212;</span><span class="mord mathit" style="margin-right:0.03588em;">y</span><span class="mclose">)</span><span class="mord mathit" style="margin-right:0.01968em;">l</span><span class="mord mathit">o</span><span class="mord mathit" style="margin-right:0.03588em;">g</span><span class="mopen">(</span><span class="mord mathrm">1</span><span class="mbin">&#x2212;</span><span class="mord accent"><span class="vlist"><span style="top:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="mord mathit">p</span></span><span style="top:0em;margin-left:0.16668em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="accent-body"><span>^</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span><span class="mclose">)</span></span></span></span></p>
<p>&#x77E5;&#x9053;&#x4E86;&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x7684;&#x635F;&#x5931;&#x51FD;&#x6570;&#x4E4B;&#x540E;&#xFF0C;&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x7684;<strong>&#x8BAD;&#x7EC3;&#x6D41;&#x7A0B;</strong>&#x5C31;&#x5F88;&#x660E;&#x663E;&#x4E86;&#xFF0C;&#x5C31;&#x662F;&#x5BFB;&#x627E;&#x4E00;&#x7EC4;&#x5408;&#x9002;&#x7684; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>W</mi></mrow><annotation encoding="application/x-tex">W</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.68333em;"></span><span class="strut bottom" style="height:0.68333em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit" style="margin-right:0.13889em;">W</span></span></span></span> &#x548C; <span class="katex"><span class="katex-mathml"><math><semantics><mrow><mi>b</mi></mrow><annotation encoding="application/x-tex">b</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.69444em;"></span><span class="strut bottom" style="height:0.69444em;vertical-align:0em;"></span><span class="base textstyle uncramped"><span class="mord mathit">b</span></span></span></span> &#xFF0C;&#x4F7F;&#x5F97;&#x635F;&#x5931;&#x503C;&#x6700;&#x5C0F;&#x3002;&#x627E;&#x5230;&#x8FD9;&#x7EC4;&#x53C2;&#x6570;&#x540E;&#x6A21;&#x578B;&#x5C31;&#x786E;&#x5B9A;&#x4E0B;&#x6765;&#x4E86;&#x3002;&#x600E;&#x4E48;&#x627E;&#xFF1F;&#x5F88;&#x660E;&#x663E;&#xFF0C;&#x7528;<strong>&#x68AF;&#x5EA6;&#x4E0B;&#x964D;</strong>&#xFF0C;&#x800C;&#x4E14;&#x4E0D;&#x96BE;&#x7B97;&#x51FA;&#x68AF;&#x5EA6;&#x4E3A;&#xFF1A;<span class="katex"><span class="katex-mathml"><math><semantics><mrow><mo>(</mo><mover accent="true"><mi>y</mi><mo>^</mo></mover><mo>&#x2212;</mo><mi>y</mi><mo>)</mo><mi>x</mi></mrow><annotation encoding="application/x-tex">(\hat y - y)x</annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="strut" style="height:0.75em;"></span><span class="strut bottom" style="height:1em;vertical-align:-0.25em;"></span><span class="base textstyle uncramped"><span class="mopen">(</span><span class="mord accent"><span class="vlist"><span style="top:0em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="mord mathit" style="margin-right:0.03588em;">y</span></span><span style="top:0em;margin-left:0.11112em;"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span><span class="accent-body"><span>^</span></span></span><span class="baseline-fix"><span class="fontsize-ensurer reset-size5 size5"><span style="font-size:0em;">&#x200B;</span></span>&#x200B;</span></span></span><span class="mbin">&#x2212;</span><span class="mord mathit" style="margin-right:0.03588em;">y</span><span class="mclose">)</span><span class="mord mathit">x</span></span></span></span>&#x3002;</p>
<p>&#x6240;&#x4EE5;&#x903B;&#x8F91;&#x56DE;&#x5F52;&#x68AF;&#x5EA6;&#x4E0B;&#x964D;&#x7684;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-python"><span class="hljs-comment">#loss</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">J</span><span class="hljs-params">(theta, X_b, y)</span>:</span>
y_hat = self._sigmoid(X_b.dot(theta))
<span class="hljs-keyword">try</span>:
<span class="hljs-keyword">return</span> -np.sum(y*np.log(y_hat)+(<span class="hljs-number">1</span>-y)*np.log(<span class="hljs-number">1</span>-y_hat)) / len(y)
<span class="hljs-keyword">except</span>:
<span class="hljs-keyword">return</span> float(<span class="hljs-string">&apos;inf&apos;</span>)
<span class="hljs-comment"># &#x7B97;theta&#x5BF9;loss&#x7684;&#x504F;&#x5BFC;</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">dJ</span><span class="hljs-params">(theta, X_b, y)</span>:</span>
<span class="hljs-keyword">return</span> X_b.T.dot(self._sigmoid(X_b.dot(theta)) - y) / len(y)
<span class="hljs-comment"># &#x6279;&#x91CF;&#x68AF;&#x5EA6;&#x4E0B;&#x964D;</span>
<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">gradient_descent</span><span class="hljs-params">(X_b, y, initial_theta, leraning_rate, n_iters=<span class="hljs-number">1e4</span>, epsilon=<span class="hljs-number">1e-8</span>)</span>:</span>
theta = initial_theta
cur_iter = <span class="hljs-number">0</span>
<span class="hljs-keyword">while</span> cur_iter &lt; n_iters:
gradient = dJ(theta, X_b, y)
last_theta = theta
theta = theta - leraning_rate * gradient
<span class="hljs-keyword">if</span> (abs(J(theta, X_b, y) - J(last_theta, X_b, y)) &lt; epsilon):
<span class="hljs-keyword">break</span>
cur_iter += <span class="hljs-number">1</span>
<span class="hljs-keyword">return</span> theta
</code></pre>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="linear_regression.html" class="navigation navigation-prev " aria-label="Previous page: 最简单的回归算法-线性回归">
<i class="fa fa-angle-left"></i>
</a>
<a href="decision_tree.html" class="navigation navigation-next " aria-label="Next page: 最接近人类思维的算法-决策树">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"使用回归的思想进行分类-逻辑回归","level":"1.3.3","depth":2,"next":{"title":"最接近人类思维的算法-决策树","level":"1.3.4","depth":2,"path":"decision_tree.md","ref":"decision_tree.md","articles":[]},"previous":{"title":"最简单的回归算法-线性回归","level":"1.3.2","depth":2,"path":"linear_regression.md","ref":"linear_regression.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["katex"],"pluginsConfig":{"katex":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"logistic_regression.md","mtime":"2019-07-04T06:31:48.716Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-07-06T07:31:21.537Z"},"basePath":".","book":{"language":""}});
});
</script>
</div>
<script src="gitbook/gitbook.js"></script>
<script src="gitbook/theme.js"></script>
<script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="gitbook/gitbook-plugin-search/search.js"></script>
<script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
</body>
</html>