updating figures
This commit is contained in:
@@ -55,7 +55,7 @@
|
||||
<link rel="index" title="Index" href="genindex.html" />
|
||||
<link rel="search" title="Search" href="search.html" />
|
||||
<link rel="next" title="7. Support Vector Machines, overarching aims" href="chapter5.html" />
|
||||
<link rel="prev" title="5. Ridge and Lasso Regression" href="chapter3.html" />
|
||||
<link rel="prev" title="5. Resampling Methods" href="chapter3.html" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="docsearch:language" content="en" />
|
||||
|
||||
@@ -144,12 +144,12 @@
|
||||
</li>
|
||||
<li class="toctree-l1">
|
||||
<a class="reference internal" href="chapter2.html">
|
||||
4. Resampling Methods
|
||||
4. Ridge and Lasso Regression
|
||||
</a>
|
||||
</li>
|
||||
<li class="toctree-l1">
|
||||
<a class="reference internal" href="chapter3.html">
|
||||
5. Ridge and Lasso Regression
|
||||
5. Resampling Methods
|
||||
</a>
|
||||
</li>
|
||||
<li class="toctree-l1 current active">
|
||||
@@ -725,18 +725,112 @@ the probability of a given category. This leads us to the logistic function.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cell_output docutils container">
|
||||
<div class="output traceback highlight-ipythontb notranslate"><div class="highlight"><pre><span></span><span class="gt">---------------------------------------------------------------------------</span>
|
||||
<span class="ne">FileNotFoundError</span><span class="g g-Whitespace"> </span>Traceback (most recent call last)
|
||||
<span class="o"><</span><span class="n">ipython</span><span class="o">-</span><span class="nb">input</span><span class="o">-</span><span class="mi">1</span><span class="o">-</span><span class="n">a77d5ac269b2</span><span class="o">></span> <span class="ow">in</span> <span class="o"><</span><span class="n">module</span><span class="o">></span>
|
||||
<span class="g g-Whitespace"> </span><span class="mi">38</span> <span class="n">plt</span><span class="o">.</span><span class="n">savefig</span><span class="p">(</span><span class="n">image_path</span><span class="p">(</span><span class="n">fig_id</span><span class="p">)</span> <span class="o">+</span> <span class="s2">".png"</span><span class="p">,</span> <span class="nb">format</span><span class="o">=</span><span class="s1">'png'</span><span class="p">)</span>
|
||||
<span class="g g-Whitespace"> </span><span class="mi">39</span>
|
||||
<span class="ne">---> </span><span class="mi">40</span> <span class="n">infile</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">data_path</span><span class="p">(</span><span class="s2">"chddata.csv"</span><span class="p">),</span><span class="s1">'r'</span><span class="p">)</span>
|
||||
<span class="g g-Whitespace"> </span><span class="mi">41</span>
|
||||
<span class="g g-Whitespace"> </span><span class="mi">42</span> <span class="c1"># Read the chd data as csv file and organize the data into arrays with age group, age, and chd</span>
|
||||
<div class="output text_html"><div>
|
||||
<style scoped>
|
||||
.dataframe tbody tr th:only-of-type {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
<span class="ne">FileNotFoundError</span>: [Errno 2] No such file or directory: 'DataFiles/chddata.csv'
|
||||
</pre></div>
|
||||
</div>
|
||||
.dataframe tbody tr th {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.dataframe thead th {
|
||||
text-align: right;
|
||||
}
|
||||
</style>
|
||||
<table border="1" class="dataframe">
|
||||
<thead>
|
||||
<tr style="text-align: right;">
|
||||
<th></th>
|
||||
<th>ID</th>
|
||||
<th>Age</th>
|
||||
<th>Agegroup</th>
|
||||
<th>CHD</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>0</th>
|
||||
<td>1</td>
|
||||
<td>21</td>
|
||||
<td>1</td>
|
||||
<td>0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>1</th>
|
||||
<td>2</td>
|
||||
<td>23</td>
|
||||
<td>1</td>
|
||||
<td>0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>2</th>
|
||||
<td>3</td>
|
||||
<td>25</td>
|
||||
<td>1</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>3</th>
|
||||
<td>4</td>
|
||||
<td>29</td>
|
||||
<td>1</td>
|
||||
<td>0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>4</th>
|
||||
<td>5</td>
|
||||
<td>21</td>
|
||||
<td>1</td>
|
||||
<td>0</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>...</th>
|
||||
<td>...</td>
|
||||
<td>...</td>
|
||||
<td>...</td>
|
||||
<td>...</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>95</th>
|
||||
<td>96</td>
|
||||
<td>61</td>
|
||||
<td>8</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>96</th>
|
||||
<td>97</td>
|
||||
<td>69</td>
|
||||
<td>8</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>97</th>
|
||||
<td>98</td>
|
||||
<td>65</td>
|
||||
<td>8</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>98</th>
|
||||
<td>99</td>
|
||||
<td>64</td>
|
||||
<td>8</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>99</th>
|
||||
<td>100</td>
|
||||
<td>63</td>
|
||||
<td>8</td>
|
||||
<td>0</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p>100 rows × 4 columns</p>
|
||||
</div></div><img alt="_images/chapter4_5_1.png" src="_images/chapter4_5_1.png" />
|
||||
</div>
|
||||
</div>
|
||||
<p>What we could attempt however is to plot the mean value for each group.</p>
|
||||
@@ -753,6 +847,9 @@ the probability of a given category. This leads us to the logistic function.</p>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cell_output docutils container">
|
||||
<img alt="_images/chapter4_7_0.png" src="_images/chapter4_7_0.png" />
|
||||
</div>
|
||||
</div>
|
||||
<p>We are now trying to find a function <span class="math notranslate nohighlight">\(f(y\vert x)\)</span>, that is a function which gives us an expected value for the output <span class="math notranslate nohighlight">\(y\)</span> with a given input <span class="math notranslate nohighlight">\(x\)</span>.
|
||||
In standard linear regression with a linear dependence on <span class="math notranslate nohighlight">\(x\)</span>, we would write this in terms of our model</p>
|
||||
@@ -852,6 +949,11 @@ p(t) = \frac{1}{1+\mathrm \exp{-t}}=\frac{\exp{t}}{1+\mathrm \exp{t}}.
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cell_output docutils container">
|
||||
<img alt="_images/chapter4_13_0.png" src="_images/chapter4_13_0.png" />
|
||||
<img alt="_images/chapter4_13_1.png" src="_images/chapter4_13_1.png" />
|
||||
<img alt="_images/chapter4_13_2.png" src="_images/chapter4_13_2.png" />
|
||||
</div>
|
||||
</div>
|
||||
<p>We assume now that we have two classes with <span class="math notranslate nohighlight">\(y_i\)</span> either <span class="math notranslate nohighlight">\(0\)</span> or <span class="math notranslate nohighlight">\(1\)</span>. Furthermore we assume also that we have only two parameters <span class="math notranslate nohighlight">\(\beta\)</span> in our fitting of the Sigmoid function, that is we define probabilities</p>
|
||||
<div class="math notranslate nohighlight">
|
||||
@@ -1016,6 +1118,24 @@ classification.</p>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cell_output docutils container">
|
||||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>(426, 30)
|
||||
(143, 30)
|
||||
Test set accuracy with Logistic Regression: 0.94
|
||||
Test set accuracy Logistic Regression with scaled data: 0.96
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/opt/anaconda3/lib/python3.8/site-packages/sklearn/linear_model/_logistic.py:762: ConvergenceWarning: lbfgs failed to converge (status=1):
|
||||
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
|
||||
|
||||
Increase the number of iterations (max_iter) or scale the data as shown in:
|
||||
https://scikit-learn.org/stable/modules/preprocessing.html
|
||||
Please also refer to the documentation for alternative solver options:
|
||||
https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression
|
||||
n_iter_i = _check_optimize_result(
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<p>In addition to the above scores, we could also study the covariance (and the correlation matrix).
|
||||
We use <strong>Pandas</strong> to compute the correlation matrix.</p>
|
||||
@@ -1058,6 +1178,10 @@ We use <strong>Pandas</strong> to compute the correlation matrix.</p>
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cell_output docutils container">
|
||||
<img alt="_images/chapter4_51_0.png" src="_images/chapter4_51_0.png" />
|
||||
<img alt="_images/chapter4_51_1.png" src="_images/chapter4_51_1.png" />
|
||||
</div>
|
||||
</div>
|
||||
<p>In the above example we note two things. In the first plot we display
|
||||
the overlap of benign and malignant tumors as functions of the various
|
||||
@@ -1138,6 +1262,39 @@ applications. This will be discussed later this semester (<a class="reference ex
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cell_output docutils container">
|
||||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>(426, 30)
|
||||
(143, 30)
|
||||
Test set accuracy with Logistic Regression: 0.94
|
||||
Test set accuracy Logistic Regression with scaled data: 0.96
|
||||
[1. 1. 1. 1. 1. 1.
|
||||
1. 1. 0.92857143 0.92857143]
|
||||
Test set accuracy with Logistic Regression and scaled data: 0.96
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/opt/anaconda3/lib/python3.8/site-packages/sklearn/linear_model/_logistic.py:762: ConvergenceWarning: lbfgs failed to converge (status=1):
|
||||
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
|
||||
|
||||
Increase the number of iterations (max_iter) or scale the data as shown in:
|
||||
https://scikit-learn.org/stable/modules/preprocessing.html
|
||||
Please also refer to the documentation for alternative solver options:
|
||||
https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression
|
||||
n_iter_i = _check_optimize_result(
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="output traceback highlight-ipythontb notranslate"><div class="highlight"><pre><span></span><span class="gt">---------------------------------------------------------------------------</span>
|
||||
<span class="ne">ModuleNotFoundError</span><span class="g g-Whitespace"> </span>Traceback (most recent call last)
|
||||
<span class="o"><</span><span class="n">ipython</span><span class="o">-</span><span class="nb">input</span><span class="o">-</span><span class="mi">8</span><span class="o">-</span><span class="mi">12</span><span class="n">adb44b1c20</span><span class="o">></span> <span class="ow">in</span> <span class="o"><</span><span class="n">module</span><span class="o">></span>
|
||||
<span class="g g-Whitespace"> </span><span class="mi">34</span>
|
||||
<span class="g g-Whitespace"> </span><span class="mi">35</span>
|
||||
<span class="ne">---> </span><span class="mi">36</span> <span class="kn">import</span> <span class="nn">scikitplot</span> <span class="k">as</span> <span class="nn">skplt</span>
|
||||
<span class="g g-Whitespace"> </span><span class="mi">37</span> <span class="n">y_pred</span> <span class="o">=</span> <span class="n">logreg</span><span class="o">.</span><span class="n">predict</span><span class="p">(</span><span class="n">X_test_scaled</span><span class="p">)</span>
|
||||
<span class="g g-Whitespace"> </span><span class="mi">38</span> <span class="n">skplt</span><span class="o">.</span><span class="n">metrics</span><span class="o">.</span><span class="n">plot_confusion_matrix</span><span class="p">(</span><span class="n">y_test</span><span class="p">,</span> <span class="n">y_pred</span><span class="p">,</span> <span class="n">normalize</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
|
||||
|
||||
<span class="ne">ModuleNotFoundError</span>: No module named 'scikitplot'
|
||||
</pre></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="optimization-the-central-part-of-any-machine-learning-algortithm">
|
||||
@@ -2256,7 +2413,7 @@ function.</p>
|
||||
|
||||
<div class='prev-next-bottom'>
|
||||
|
||||
<a class='left-prev' id="prev-link" href="chapter3.html" title="previous page"><span class="section-number">5. </span>Ridge and Lasso Regression</a>
|
||||
<a class='left-prev' id="prev-link" href="chapter3.html" title="previous page"><span class="section-number">5. </span>Resampling Methods</a>
|
||||
<a class='right-next' id="next-link" href="chapter5.html" title="next page"><span class="section-number">7. </span>Support Vector Machines, overarching aims</a>
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user