-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathlda_qda.html
328 lines (288 loc) · 16.3 KB
/
lda_qda.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>1.2. Linear and quadratic discriminant analysis — scikit-learn 0.16.1 documentation</title>
<!-- htmltitle is before nature.css - we use this hack to load bootstrap first -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="../_static/css/bootstrap.min.css" media="screen" />
<link rel="stylesheet" href="../_static/css/bootstrap-responsive.css"/>
<link rel="stylesheet" href="../_static/nature.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../_static/gallery.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../',
VERSION: '0.16.1',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="../_static/js/copybutton.js"></script>
<link rel="shortcut icon" href="../_static/favicon.ico"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="top" title="scikit-learn 0.16.1 documentation" href="../index.html" />
<link rel="up" title="1. Supervised learning" href="../supervised_learning.html" />
<link rel="next" title="1.3. Kernel ridge regression" href="kernel_ridge.html" />
<link rel="prev" title="1.1. Generalized Linear Models" href="linear_model.html" />
<script type="text/javascript" src="../_static/sidebar.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script src="../_static/js/bootstrap.min.js" type="text/javascript"></script>
<link rel="canonical" href="https://scikit-learn.org/stable/modules/lda_qda.html" />
<script type="text/javascript">
$("div.buttonNext, div.buttonPrevious").hover(
function () {
$(this).css('background-color', '#FF9C34');
},
function () {
$(this).css('background-color', '#A7D6E2');
}
);
var bodywrapper = $('.bodywrapper');
var sidebarbutton = $('#sidebarbutton');
sidebarbutton.css({'height': '900px'});
</script>
</head>
<body>
<div class="header-wrapper">
<div class="header">
<p class="logo"><a href="../index.html">
<img src="../_static/scikit-learn-logo-small.png" alt="Logo"/>
</a>
</p><div class="navbar">
<ul>
<li><a href="../../stable/index.html">Home</a></li>
<li><a href="../../stable/install.html">Installation</a></li>
<li class="btn-li"><div class="btn-group">
<a href="../documentation.html">Documentation</a>
<a class="btn dropdown-toggle" data-toggle="dropdown">
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li class="link-title">Scikit-learn 0.16 (Stable)</li>
<li><a href="../tutorial/index.html">Tutorials</a></li>
<li><a href="../user_guide.html">User guide</a></li>
<li><a href="classes.html">API</a></li>
<li><a href="../faq.html">FAQ</a></li>
<li class="divider"></li>
<li><a href="http://scikit-learn.org/dev/documentation.html">Development</a></li>
<li><a href="http://scikit-learn.org/0.15/">Scikit-learn 0.15</a></li>
</ul>
</div>
</li>
<li><a href="../auto_examples/index.html">Examples</a></li>
</ul>
<div class="search_form">
<div id="cse" style="width: 100%;"></div>
</div>
</div> <!-- end navbar --></div>
</div>
<!-- Github "fork me" ribbon -->
<a href="https://github.com/scikit-learn/scikit-learn">
<img class="fork-me"
style="position: absolute; top: 0; right: 0; border: 0;"
src="../_static/img/forkme.png"
alt="Fork me on GitHub" />
</a>
<div class="content-wrapper">
<div class="sphinxsidebar">
<div class="sphinxsidebarwrapper">
<div class="rel">
<!-- rellinks[1:] is an ugly hack to avoid link to module
index -->
<div class="rellink">
<a href="linear_model.html"
accesskey="P">Previous
<br/>
<span class="smallrellink">
1.1. Generalized...
</span>
<span class="hiddenrellink">
1.1. Generalized Linear Models
</span>
</a>
</div>
<div class="spacer">
</div>
<div class="rellink">
<a href="kernel_ridge.html"
accesskey="N">Next
<br/>
<span class="smallrellink">
1.3. Kernel ridg...
</span>
<span class="hiddenrellink">
1.3. Kernel ridge regression
</span>
</a>
</div>
<!-- Ad a link to the 'up' page -->
<div class="spacer">
</div>
<div class="rellink">
<a href="../supervised_learning.html">
Up
<br/>
<span class="smallrellink">
1. Supervised le...
</span>
<span class="hiddenrellink">
1. Supervised learning
</span>
</a>
</div>
</div>
<p class="doc-version">This documentation is for scikit-learn <strong>version 0.16.1</strong> — <a href="http://scikit-learn.org/stable/support.html#documentation-resources">Other versions</a></p>
<p class="citing">If you use the software, please consider <a href="../about.html#citing-scikit-learn">citing scikit-learn</a>.</p>
<ul>
<li><a class="reference internal" href="#">1.2. Linear and quadratic discriminant analysis</a><ul>
<li><a class="reference internal" href="#dimensionality-reduction-using-lda">1.2.1. Dimensionality reduction using LDA</a></li>
<li><a class="reference internal" href="#mathematical-idea">1.2.2. Mathematical Idea</a></li>
<li><a class="reference internal" href="#shrinkage">1.2.3. Shrinkage</a></li>
<li><a class="reference internal" href="#estimation-algorithms">1.2.4. Estimation algorithms</a></li>
</ul>
</li>
</ul>
</div>
</div>
<div class="content">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body">
<div class="section" id="linear-and-quadratic-discriminant-analysis">
<span id="lda-qda"></span><h1>1.2. Linear and quadratic discriminant analysis<a class="headerlink" href="#linear-and-quadratic-discriminant-analysis" title="Permalink to this headline">¶</a></h1>
<p>Linear discriminant analysis (<a class="reference internal" href="generated/sklearn.lda.LDA.html#sklearn.lda.LDA" title="sklearn.lda.LDA"><tt class="xref py py-class docutils literal"><span class="pre">lda.LDA</span></tt></a>) and
quadratic discriminant analysis (<a class="reference internal" href="generated/sklearn.qda.QDA.html#sklearn.qda.QDA" title="sklearn.qda.QDA"><tt class="xref py py-class docutils literal"><span class="pre">qda.QDA</span></tt></a>)
are two classic classifiers, with, as their names suggest, a linear and a
quadratic decision surface, respectively.</p>
<p>These classifiers are attractive because they have closed-form solutions that
can be easily computed, are inherently multiclass,
and have proven to work well in practice.
Also there are no parameters to tune for these algorithms.</p>
<p class="centered">
<strong><a class="reference external image-reference" href="../auto_examples/classification/plot_lda_qda.html"><img alt="ldaqda" src="../_images/plot_lda_qda_0012.png" style="width: 640.0px; height: 480.0px;" /></a>
</strong></p><p>The plot shows decision boundaries for LDA and QDA. The bottom row
demonstrates that LDA can only learn linear boundaries, while QDA can learn
quadratic boundaries and is therefore more flexible.</p>
<div class="topic">
<p class="topic-title first">Examples:</p>
<p><a class="reference internal" href="../auto_examples/classification/plot_lda_qda.html#example-classification-plot-lda-qda-py"><em>Linear and Quadratic Discriminant Analysis with confidence ellipsoid</em></a>: Comparison of LDA and QDA on synthetic data.</p>
</div>
<div class="section" id="dimensionality-reduction-using-lda">
<h2>1.2.1. Dimensionality reduction using LDA<a class="headerlink" href="#dimensionality-reduction-using-lda" title="Permalink to this headline">¶</a></h2>
<p><a class="reference internal" href="generated/sklearn.lda.LDA.html#sklearn.lda.LDA" title="sklearn.lda.LDA"><tt class="xref py py-class docutils literal"><span class="pre">lda.LDA</span></tt></a> can be used to perform supervised dimensionality reduction by
projecting the input data to a subspace consisting of the most
discriminant directions.
This is implemented in <a class="reference internal" href="generated/sklearn.lda.LDA.html#sklearn.lda.LDA.transform" title="sklearn.lda.LDA.transform"><tt class="xref py py-func docutils literal"><span class="pre">lda.LDA.transform</span></tt></a>. The desired
dimensionality can be set using the <tt class="docutils literal"><span class="pre">n_components</span></tt> constructor
parameter. This parameter has no influence on <a class="reference internal" href="generated/sklearn.lda.LDA.html#sklearn.lda.LDA.fit" title="sklearn.lda.LDA.fit"><tt class="xref py py-func docutils literal"><span class="pre">lda.LDA.fit</span></tt></a> or <a class="reference internal" href="generated/sklearn.lda.LDA.html#sklearn.lda.LDA.predict" title="sklearn.lda.LDA.predict"><tt class="xref py py-func docutils literal"><span class="pre">lda.LDA.predict</span></tt></a>.</p>
</div>
<div class="section" id="mathematical-idea">
<h2>1.2.2. Mathematical Idea<a class="headerlink" href="#mathematical-idea" title="Permalink to this headline">¶</a></h2>
<p>Both methods work by modeling the class conditional distribution of the data <img class="math" src="../_images/math/6349652f4f3fed24cf0e66ba44b19b5c170cae96.png" alt="P(X|y=k)"/>
for each class <img class="math" src="../_images/math/e9203da50e1059455123460d4e716c9c7f440cc3.png" alt="k"/>. Predictions can be obtained by using Bayes’ rule:</p>
<div class="math">
<p><img src="../_images/math/42c35ac00e7da22baf37c275ae06ddb68378e57b.png" alt="P(y | X) = P(X | y) \cdot P(y) / P(X) = P(X | y) \cdot P(Y) / ( \sum_{y'} P(X | y') \cdot p(y'))"/></p>
</div><p>In linear and quadratic discriminant analysis, <img class="math" src="../_images/math/e69ebd95e385ac5c254ef15635c37b01668decbf.png" alt="P(X|y)"/>
is modelled as a Gaussian distribution.
In the case of LDA, the Gaussians for each class are assumed to share the same covariance matrix.
This leads to a linear decision surface, as can be seen by comparing the the log-probability rations
<img class="math" src="../_images/math/0516d06a9c644cd6f93d73c8151f4206a52496c0.png" alt="log[P(y=k | X) / P(y=l | X)]"/>.</p>
<p>In the case of QDA, there are no assumptions on the covariance matrices of the Gaussians,
leading to a quadratic decision surface.</p>
</div>
<div class="section" id="shrinkage">
<h2>1.2.3. Shrinkage<a class="headerlink" href="#shrinkage" title="Permalink to this headline">¶</a></h2>
<p>Shrinkage is a tool to improve estimation of covariance matrices in situations
where the number of training samples is small compared to the number of
features. In this scenario, the empirical sample covariance is a poor
estimator. Shrinkage LDA can be used by setting the <tt class="docutils literal"><span class="pre">shrinkage</span></tt> parameter of
the <a class="reference internal" href="generated/sklearn.lda.LDA.html#sklearn.lda.LDA" title="sklearn.lda.LDA"><tt class="xref py py-class docutils literal"><span class="pre">lda.LDA</span></tt></a> class to ‘auto’. This automatically determines the
optimal shrinkage parameter in an analytic way following the lemma introduced
by Ledoit and Wolf. Note that currently shrinkage only works when setting the
<tt class="docutils literal"><span class="pre">solver</span></tt> parameter to ‘lsqr’ or ‘eigen’.</p>
<p>The <tt class="docutils literal"><span class="pre">shrinkage</span></tt> parameter can also be manually set between 0 and 1. In
particular, a value of 0 corresponds to no shrinkage (which means the empirical
covariance matrix will be used) and a value of 1 corresponds to complete
shrinkage (which means that the diagonal matrix of variances will be used as
an estimate for the covariance matrix). Setting this parameter to a value
between these two extrema will estimate a shrunk version of the covariance
matrix.</p>
<p class="centered">
<strong><a class="reference external image-reference" href="../auto_examples/classification/plot_lda.html"><img alt="shrinkage" src="../_images/plot_lda_0011.png" style="width: 600.0px; height: 450.0px;" /></a>
</strong></p></div>
<div class="section" id="estimation-algorithms">
<h2>1.2.4. Estimation algorithms<a class="headerlink" href="#estimation-algorithms" title="Permalink to this headline">¶</a></h2>
<p>The default solver is ‘svd’. It can perform both classification and transform,
and it does not rely on the calculation of the covariance matrix. This can be
an advantage in situations where the number of features is large. However, the
‘svd’ solver cannot be used with shrinkage.</p>
<p>The ‘lsqr’ solver is an efficient algorithm that only works for classification.
It supports shrinkage.</p>
<p>The ‘eigen’ solver is based on the optimization of the between class scatter to
within class scatter ratio. It can be used for both classification and
transform, and it supports shrinkage. However, the ‘eigen’ solver needs to
compute the covariance matrix, so it might not be suitable for situations with
a high number of features.</p>
<div class="topic">
<p class="topic-title first">Examples:</p>
<p><a class="reference internal" href="../auto_examples/classification/plot_lda.html#example-classification-plot-lda-py"><em>Normal and Shrinkage Linear Discriminant Analysis for classification</em></a>: Comparison of LDA classifiers with and without shrinkage.</p>
</div>
<div class="topic">
<p class="topic-title first">References:</p>
<p>Hastie T, Tibshirani R, Friedman J. The Elements of Statistical Learning. Springer, 2009.</p>
<p>Ledoit O, Wolf M. Honey, I Shrunk the Sample Covariance Matrix. The Journal of Portfolio
Management 30(4), 110-119, 2004.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
</div>
<div class="footer">
© 2010 - 2014, scikit-learn developers (BSD License).
<a href="../_sources/modules/lda_qda.txt" rel="nofollow">Show this page source</a>
</div>
<div class="rel">
<div class="buttonPrevious">
<a href="linear_model.html">Previous
</a>
</div>
<div class="buttonNext">
<a href="kernel_ridge.html">Next
</a>
</div>
</div>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-22606712-2']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript"> google.load('search', '1',
{language : 'en'}); google.setOnLoadCallback(function() {
var customSearchControl = new
google.search.CustomSearchControl('016639176250731907682:tjtqbvtvij0');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
var options = new google.search.DrawOptions();
options.setAutoComplete(true);
customSearchControl.draw('cse', options); }, true);
</script>
<script src="https://scikit-learn.org/versionwarning.js"></script>
</body>
</html>