adding more material, miss theorem and its proof

This commit is contained in:
mhjensen
2019-10-20 23:11:22 +02:00
parent cbaec5ba67
commit 48e5ebfd92
21 changed files with 1324 additions and 401 deletions
+34 -23
View File
@@ -76,17 +76,24 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec9'),
('Classical PCA Theorem', 2, None, '___sec10'),
('Prof of the PCA Theorem', 2, None, '___sec11'),
('Getting started with PCA', 2, None, '___sec12'),
('Principal Component Analysis', 2, None, '___sec13'),
('PCA and scikit-learn', 2, None, '___sec14'),
('More on the PCA', 2, None, '___sec15'),
('Incremental PCA', 2, None, '___sec16'),
('Randomized PCA', 2, None, '___sec17'),
('Kernel PCA', 2, None, '___sec18'),
('LLE', 2, None, '___sec19'),
('Other techniques', 2, None, '___sec20')]}
('Covariance Matrix Examples', 2, None, '___sec10'),
('Correlation Matrix', 2, None, '___sec11'),
('Correlation Matrix with Pandas', 2, None, '___sec12'),
('Correlation Matrix with Pandas and the Franke function',
2,
None,
'___sec13'),
('Classical PCA Theorem', 2, None, '___sec14'),
('Prof of the PCA Theorem', 2, None, '___sec15'),
('Getting started with PCA', 2, None, '___sec16'),
('Principal Component Analysis', 2, None, '___sec17'),
('PCA and scikit-learn', 2, None, '___sec18'),
('More on the PCA', 2, None, '___sec19'),
('Incremental PCA', 2, None, '___sec20'),
('Randomized PCA', 2, None, '___sec21'),
('Kernel PCA', 2, None, '___sec22'),
('LLE', 2, None, '___sec23'),
('Other techniques', 2, None, '___sec24')]}
end of tocinfo -->
<body>
@@ -134,17 +141,21 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DimRed-bs008.html#___sec7" style="font-size: 80%;">Basic ideas of the Principal Component Analysis (PCA)</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs009.html#___sec8" style="font-size: 80%;">Introducing the Covariance and Correlation functions</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs010.html#___sec9" style="font-size: 80%;">Correlation Function and Design/Feature Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Other techniques</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Covariance Matrix Examples</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Correlation Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Correlation Matrix with Pandas</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Correlation Matrix with Pandas and the Franke function</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs022.html#___sec21" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs023.html#___sec22" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs024.html#___sec23" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs025.html#___sec24" style="font-size: 80%;">Other techniques</a></li>
</ul>
</li>
@@ -203,7 +214,7 @@ MathJax.Hub.Config({
<li><a href="._DimRed-bs008.html">9</a></li>
<li><a href="._DimRed-bs009.html">10</a></li>
<li><a href="">...</a></li>
<li><a href="._DimRed-bs021.html">22</a></li>
<li><a href="._DimRed-bs025.html">26</a></li>
<li><a href="._DimRed-bs001.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+34 -23
View File
@@ -76,17 +76,24 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec9'),
('Classical PCA Theorem', 2, None, '___sec10'),
('Prof of the PCA Theorem', 2, None, '___sec11'),
('Getting started with PCA', 2, None, '___sec12'),
('Principal Component Analysis', 2, None, '___sec13'),
('PCA and scikit-learn', 2, None, '___sec14'),
('More on the PCA', 2, None, '___sec15'),
('Incremental PCA', 2, None, '___sec16'),
('Randomized PCA', 2, None, '___sec17'),
('Kernel PCA', 2, None, '___sec18'),
('LLE', 2, None, '___sec19'),
('Other techniques', 2, None, '___sec20')]}
('Covariance Matrix Examples', 2, None, '___sec10'),
('Correlation Matrix', 2, None, '___sec11'),
('Correlation Matrix with Pandas', 2, None, '___sec12'),
('Correlation Matrix with Pandas and the Franke function',
2,
None,
'___sec13'),
('Classical PCA Theorem', 2, None, '___sec14'),
('Prof of the PCA Theorem', 2, None, '___sec15'),
('Getting started with PCA', 2, None, '___sec16'),
('Principal Component Analysis', 2, None, '___sec17'),
('PCA and scikit-learn', 2, None, '___sec18'),
('More on the PCA', 2, None, '___sec19'),
('Incremental PCA', 2, None, '___sec20'),
('Randomized PCA', 2, None, '___sec21'),
('Kernel PCA', 2, None, '___sec22'),
('LLE', 2, None, '___sec23'),
('Other techniques', 2, None, '___sec24')]}
end of tocinfo -->
<body>
@@ -134,17 +141,21 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DimRed-bs008.html#___sec7" style="font-size: 80%;">Basic ideas of the Principal Component Analysis (PCA)</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs009.html#___sec8" style="font-size: 80%;">Introducing the Covariance and Correlation functions</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs010.html#___sec9" style="font-size: 80%;">Correlation Function and Design/Feature Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Other techniques</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Covariance Matrix Examples</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Correlation Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Correlation Matrix with Pandas</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Correlation Matrix with Pandas and the Franke function</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs022.html#___sec21" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs023.html#___sec22" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs024.html#___sec23" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs025.html#___sec24" style="font-size: 80%;">Other techniques</a></li>
</ul>
</li>
@@ -203,7 +214,7 @@ data.
<li><a href="._DimRed-bs009.html">10</a></li>
<li><a href="._DimRed-bs010.html">11</a></li>
<li><a href="">...</a></li>
<li><a href="._DimRed-bs021.html">22</a></li>
<li><a href="._DimRed-bs025.html">26</a></li>
<li><a href="._DimRed-bs002.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+34 -23
View File
@@ -76,17 +76,24 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec9'),
('Classical PCA Theorem', 2, None, '___sec10'),
('Prof of the PCA Theorem', 2, None, '___sec11'),
('Getting started with PCA', 2, None, '___sec12'),
('Principal Component Analysis', 2, None, '___sec13'),
('PCA and scikit-learn', 2, None, '___sec14'),
('More on the PCA', 2, None, '___sec15'),
('Incremental PCA', 2, None, '___sec16'),
('Randomized PCA', 2, None, '___sec17'),
('Kernel PCA', 2, None, '___sec18'),
('LLE', 2, None, '___sec19'),
('Other techniques', 2, None, '___sec20')]}
('Covariance Matrix Examples', 2, None, '___sec10'),
('Correlation Matrix', 2, None, '___sec11'),
('Correlation Matrix with Pandas', 2, None, '___sec12'),
('Correlation Matrix with Pandas and the Franke function',
2,
None,
'___sec13'),
('Classical PCA Theorem', 2, None, '___sec14'),
('Prof of the PCA Theorem', 2, None, '___sec15'),
('Getting started with PCA', 2, None, '___sec16'),
('Principal Component Analysis', 2, None, '___sec17'),
('PCA and scikit-learn', 2, None, '___sec18'),
('More on the PCA', 2, None, '___sec19'),
('Incremental PCA', 2, None, '___sec20'),
('Randomized PCA', 2, None, '___sec21'),
('Kernel PCA', 2, None, '___sec22'),
('LLE', 2, None, '___sec23'),
('Other techniques', 2, None, '___sec24')]}
end of tocinfo -->
<body>
@@ -134,17 +141,21 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DimRed-bs008.html#___sec7" style="font-size: 80%;">Basic ideas of the Principal Component Analysis (PCA)</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs009.html#___sec8" style="font-size: 80%;">Introducing the Covariance and Correlation functions</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs010.html#___sec9" style="font-size: 80%;">Correlation Function and Design/Feature Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Other techniques</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Covariance Matrix Examples</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Correlation Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Correlation Matrix with Pandas</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Correlation Matrix with Pandas and the Franke function</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs022.html#___sec21" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs023.html#___sec22" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs024.html#___sec23" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs025.html#___sec24" style="font-size: 80%;">Other techniques</a></li>
</ul>
</li>
@@ -202,7 +213,7 @@ ensures that all features are exactly between \( 0 \) and \( 1 \). The
<li><a href="._DimRed-bs010.html">11</a></li>
<li><a href="._DimRed-bs011.html">12</a></li>
<li><a href="">...</a></li>
<li><a href="._DimRed-bs021.html">22</a></li>
<li><a href="._DimRed-bs025.html">26</a></li>
<li><a href="._DimRed-bs003.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+34 -23
View File
@@ -76,17 +76,24 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec9'),
('Classical PCA Theorem', 2, None, '___sec10'),
('Prof of the PCA Theorem', 2, None, '___sec11'),
('Getting started with PCA', 2, None, '___sec12'),
('Principal Component Analysis', 2, None, '___sec13'),
('PCA and scikit-learn', 2, None, '___sec14'),
('More on the PCA', 2, None, '___sec15'),
('Incremental PCA', 2, None, '___sec16'),
('Randomized PCA', 2, None, '___sec17'),
('Kernel PCA', 2, None, '___sec18'),
('LLE', 2, None, '___sec19'),
('Other techniques', 2, None, '___sec20')]}
('Covariance Matrix Examples', 2, None, '___sec10'),
('Correlation Matrix', 2, None, '___sec11'),
('Correlation Matrix with Pandas', 2, None, '___sec12'),
('Correlation Matrix with Pandas and the Franke function',
2,
None,
'___sec13'),
('Classical PCA Theorem', 2, None, '___sec14'),
('Prof of the PCA Theorem', 2, None, '___sec15'),
('Getting started with PCA', 2, None, '___sec16'),
('Principal Component Analysis', 2, None, '___sec17'),
('PCA and scikit-learn', 2, None, '___sec18'),
('More on the PCA', 2, None, '___sec19'),
('Incremental PCA', 2, None, '___sec20'),
('Randomized PCA', 2, None, '___sec21'),
('Kernel PCA', 2, None, '___sec22'),
('LLE', 2, None, '___sec23'),
('Other techniques', 2, None, '___sec24')]}
end of tocinfo -->
<body>
@@ -134,17 +141,21 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DimRed-bs008.html#___sec7" style="font-size: 80%;">Basic ideas of the Principal Component Analysis (PCA)</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs009.html#___sec8" style="font-size: 80%;">Introducing the Covariance and Correlation functions</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs010.html#___sec9" style="font-size: 80%;">Correlation Function and Design/Feature Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Other techniques</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Covariance Matrix Examples</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Correlation Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Correlation Matrix with Pandas</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Correlation Matrix with Pandas and the Franke function</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs022.html#___sec21" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs023.html#___sec22" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs024.html#___sec23" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs025.html#___sec24" style="font-size: 80%;">Other techniques</a></li>
</ul>
</li>
@@ -205,7 +216,7 @@ techniques.
<li><a href="._DimRed-bs011.html">12</a></li>
<li><a href="._DimRed-bs012.html">13</a></li>
<li><a href="">...</a></li>
<li><a href="._DimRed-bs021.html">22</a></li>
<li><a href="._DimRed-bs025.html">26</a></li>
<li><a href="._DimRed-bs004.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+34 -23
View File
@@ -76,17 +76,24 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec9'),
('Classical PCA Theorem', 2, None, '___sec10'),
('Prof of the PCA Theorem', 2, None, '___sec11'),
('Getting started with PCA', 2, None, '___sec12'),
('Principal Component Analysis', 2, None, '___sec13'),
('PCA and scikit-learn', 2, None, '___sec14'),
('More on the PCA', 2, None, '___sec15'),
('Incremental PCA', 2, None, '___sec16'),
('Randomized PCA', 2, None, '___sec17'),
('Kernel PCA', 2, None, '___sec18'),
('LLE', 2, None, '___sec19'),
('Other techniques', 2, None, '___sec20')]}
('Covariance Matrix Examples', 2, None, '___sec10'),
('Correlation Matrix', 2, None, '___sec11'),
('Correlation Matrix with Pandas', 2, None, '___sec12'),
('Correlation Matrix with Pandas and the Franke function',
2,
None,
'___sec13'),
('Classical PCA Theorem', 2, None, '___sec14'),
('Prof of the PCA Theorem', 2, None, '___sec15'),
('Getting started with PCA', 2, None, '___sec16'),
('Principal Component Analysis', 2, None, '___sec17'),
('PCA and scikit-learn', 2, None, '___sec18'),
('More on the PCA', 2, None, '___sec19'),
('Incremental PCA', 2, None, '___sec20'),
('Randomized PCA', 2, None, '___sec21'),
('Kernel PCA', 2, None, '___sec22'),
('LLE', 2, None, '___sec23'),
('Other techniques', 2, None, '___sec24')]}
end of tocinfo -->
<body>
@@ -134,17 +141,21 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DimRed-bs008.html#___sec7" style="font-size: 80%;">Basic ideas of the Principal Component Analysis (PCA)</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs009.html#___sec8" style="font-size: 80%;">Introducing the Covariance and Correlation functions</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs010.html#___sec9" style="font-size: 80%;">Correlation Function and Design/Feature Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Other techniques</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Covariance Matrix Examples</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Correlation Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Correlation Matrix with Pandas</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Correlation Matrix with Pandas and the Franke function</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs022.html#___sec21" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs023.html#___sec22" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs024.html#___sec23" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs025.html#___sec24" style="font-size: 80%;">Other techniques</a></li>
</ul>
</li>
@@ -280,7 +291,7 @@ svm<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
<li><a href="._DimRed-bs012.html">13</a></li>
<li><a href="._DimRed-bs013.html">14</a></li>
<li><a href="">...</a></li>
<li><a href="._DimRed-bs021.html">22</a></li>
<li><a href="._DimRed-bs025.html">26</a></li>
<li><a href="._DimRed-bs005.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+34 -23
View File
@@ -76,17 +76,24 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec9'),
('Classical PCA Theorem', 2, None, '___sec10'),
('Prof of the PCA Theorem', 2, None, '___sec11'),
('Getting started with PCA', 2, None, '___sec12'),
('Principal Component Analysis', 2, None, '___sec13'),
('PCA and scikit-learn', 2, None, '___sec14'),
('More on the PCA', 2, None, '___sec15'),
('Incremental PCA', 2, None, '___sec16'),
('Randomized PCA', 2, None, '___sec17'),
('Kernel PCA', 2, None, '___sec18'),
('LLE', 2, None, '___sec19'),
('Other techniques', 2, None, '___sec20')]}
('Covariance Matrix Examples', 2, None, '___sec10'),
('Correlation Matrix', 2, None, '___sec11'),
('Correlation Matrix with Pandas', 2, None, '___sec12'),
('Correlation Matrix with Pandas and the Franke function',
2,
None,
'___sec13'),
('Classical PCA Theorem', 2, None, '___sec14'),
('Prof of the PCA Theorem', 2, None, '___sec15'),
('Getting started with PCA', 2, None, '___sec16'),
('Principal Component Analysis', 2, None, '___sec17'),
('PCA and scikit-learn', 2, None, '___sec18'),
('More on the PCA', 2, None, '___sec19'),
('Incremental PCA', 2, None, '___sec20'),
('Randomized PCA', 2, None, '___sec21'),
('Kernel PCA', 2, None, '___sec22'),
('LLE', 2, None, '___sec23'),
('Other techniques', 2, None, '___sec24')]}
end of tocinfo -->
<body>
@@ -134,17 +141,21 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DimRed-bs008.html#___sec7" style="font-size: 80%;">Basic ideas of the Principal Component Analysis (PCA)</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs009.html#___sec8" style="font-size: 80%;">Introducing the Covariance and Correlation functions</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs010.html#___sec9" style="font-size: 80%;">Correlation Function and Design/Feature Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Other techniques</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Covariance Matrix Examples</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Correlation Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Correlation Matrix with Pandas</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Correlation Matrix with Pandas and the Franke function</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs022.html#___sec21" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs023.html#___sec22" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs024.html#___sec23" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs025.html#___sec24" style="font-size: 80%;">Other techniques</a></li>
</ul>
</li>
@@ -230,7 +241,7 @@ svm<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
<li><a href="._DimRed-bs013.html">14</a></li>
<li><a href="._DimRed-bs014.html">15</a></li>
<li><a href="">...</a></li>
<li><a href="._DimRed-bs021.html">22</a></li>
<li><a href="._DimRed-bs025.html">26</a></li>
<li><a href="._DimRed-bs006.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+34 -23
View File
@@ -76,17 +76,24 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec9'),
('Classical PCA Theorem', 2, None, '___sec10'),
('Prof of the PCA Theorem', 2, None, '___sec11'),
('Getting started with PCA', 2, None, '___sec12'),
('Principal Component Analysis', 2, None, '___sec13'),
('PCA and scikit-learn', 2, None, '___sec14'),
('More on the PCA', 2, None, '___sec15'),
('Incremental PCA', 2, None, '___sec16'),
('Randomized PCA', 2, None, '___sec17'),
('Kernel PCA', 2, None, '___sec18'),
('LLE', 2, None, '___sec19'),
('Other techniques', 2, None, '___sec20')]}
('Covariance Matrix Examples', 2, None, '___sec10'),
('Correlation Matrix', 2, None, '___sec11'),
('Correlation Matrix with Pandas', 2, None, '___sec12'),
('Correlation Matrix with Pandas and the Franke function',
2,
None,
'___sec13'),
('Classical PCA Theorem', 2, None, '___sec14'),
('Prof of the PCA Theorem', 2, None, '___sec15'),
('Getting started with PCA', 2, None, '___sec16'),
('Principal Component Analysis', 2, None, '___sec17'),
('PCA and scikit-learn', 2, None, '___sec18'),
('More on the PCA', 2, None, '___sec19'),
('Incremental PCA', 2, None, '___sec20'),
('Randomized PCA', 2, None, '___sec21'),
('Kernel PCA', 2, None, '___sec22'),
('LLE', 2, None, '___sec23'),
('Other techniques', 2, None, '___sec24')]}
end of tocinfo -->
<body>
@@ -134,17 +141,21 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DimRed-bs008.html#___sec7" style="font-size: 80%;">Basic ideas of the Principal Component Analysis (PCA)</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs009.html#___sec8" style="font-size: 80%;">Introducing the Covariance and Correlation functions</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs010.html#___sec9" style="font-size: 80%;">Correlation Function and Design/Feature Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Other techniques</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Covariance Matrix Examples</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Correlation Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Correlation Matrix with Pandas</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Correlation Matrix with Pandas and the Franke function</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs022.html#___sec21" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs023.html#___sec22" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs024.html#___sec23" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs025.html#___sec24" style="font-size: 80%;">Other techniques</a></li>
</ul>
</li>
@@ -209,7 +220,7 @@ logreg<span style="color: #666666">.</span>fit(X_train_scaled, y_train)
<li><a href="._DimRed-bs014.html">15</a></li>
<li><a href="._DimRed-bs015.html">16</a></li>
<li><a href="">...</a></li>
<li><a href="._DimRed-bs021.html">22</a></li>
<li><a href="._DimRed-bs025.html">26</a></li>
<li><a href="._DimRed-bs007.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+34 -23
View File
@@ -76,17 +76,24 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec9'),
('Classical PCA Theorem', 2, None, '___sec10'),
('Prof of the PCA Theorem', 2, None, '___sec11'),
('Getting started with PCA', 2, None, '___sec12'),
('Principal Component Analysis', 2, None, '___sec13'),
('PCA and scikit-learn', 2, None, '___sec14'),
('More on the PCA', 2, None, '___sec15'),
('Incremental PCA', 2, None, '___sec16'),
('Randomized PCA', 2, None, '___sec17'),
('Kernel PCA', 2, None, '___sec18'),
('LLE', 2, None, '___sec19'),
('Other techniques', 2, None, '___sec20')]}
('Covariance Matrix Examples', 2, None, '___sec10'),
('Correlation Matrix', 2, None, '___sec11'),
('Correlation Matrix with Pandas', 2, None, '___sec12'),
('Correlation Matrix with Pandas and the Franke function',
2,
None,
'___sec13'),
('Classical PCA Theorem', 2, None, '___sec14'),
('Prof of the PCA Theorem', 2, None, '___sec15'),
('Getting started with PCA', 2, None, '___sec16'),
('Principal Component Analysis', 2, None, '___sec17'),
('PCA and scikit-learn', 2, None, '___sec18'),
('More on the PCA', 2, None, '___sec19'),
('Incremental PCA', 2, None, '___sec20'),
('Randomized PCA', 2, None, '___sec21'),
('Kernel PCA', 2, None, '___sec22'),
('LLE', 2, None, '___sec23'),
('Other techniques', 2, None, '___sec24')]}
end of tocinfo -->
<body>
@@ -134,17 +141,21 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DimRed-bs008.html#___sec7" style="font-size: 80%;">Basic ideas of the Principal Component Analysis (PCA)</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs009.html#___sec8" style="font-size: 80%;">Introducing the Covariance and Correlation functions</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs010.html#___sec9" style="font-size: 80%;">Correlation Function and Design/Feature Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Other techniques</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Covariance Matrix Examples</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Correlation Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Correlation Matrix with Pandas</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Correlation Matrix with Pandas and the Franke function</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs022.html#___sec21" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs023.html#___sec22" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs024.html#___sec23" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs025.html#___sec24" style="font-size: 80%;">Other techniques</a></li>
</ul>
</li>
@@ -264,7 +275,7 @@ applications.
<li><a href="._DimRed-bs015.html">16</a></li>
<li><a href="._DimRed-bs016.html">17</a></li>
<li><a href="">...</a></li>
<li><a href="._DimRed-bs021.html">22</a></li>
<li><a href="._DimRed-bs025.html">26</a></li>
<li><a href="._DimRed-bs008.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+34 -23
View File
@@ -76,17 +76,24 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec9'),
('Classical PCA Theorem', 2, None, '___sec10'),
('Prof of the PCA Theorem', 2, None, '___sec11'),
('Getting started with PCA', 2, None, '___sec12'),
('Principal Component Analysis', 2, None, '___sec13'),
('PCA and scikit-learn', 2, None, '___sec14'),
('More on the PCA', 2, None, '___sec15'),
('Incremental PCA', 2, None, '___sec16'),
('Randomized PCA', 2, None, '___sec17'),
('Kernel PCA', 2, None, '___sec18'),
('LLE', 2, None, '___sec19'),
('Other techniques', 2, None, '___sec20')]}
('Covariance Matrix Examples', 2, None, '___sec10'),
('Correlation Matrix', 2, None, '___sec11'),
('Correlation Matrix with Pandas', 2, None, '___sec12'),
('Correlation Matrix with Pandas and the Franke function',
2,
None,
'___sec13'),
('Classical PCA Theorem', 2, None, '___sec14'),
('Prof of the PCA Theorem', 2, None, '___sec15'),
('Getting started with PCA', 2, None, '___sec16'),
('Principal Component Analysis', 2, None, '___sec17'),
('PCA and scikit-learn', 2, None, '___sec18'),
('More on the PCA', 2, None, '___sec19'),
('Incremental PCA', 2, None, '___sec20'),
('Randomized PCA', 2, None, '___sec21'),
('Kernel PCA', 2, None, '___sec22'),
('LLE', 2, None, '___sec23'),
('Other techniques', 2, None, '___sec24')]}
end of tocinfo -->
<body>
@@ -134,17 +141,21 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="#___sec7" style="font-size: 80%;">Basic ideas of the Principal Component Analysis (PCA)</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs009.html#___sec8" style="font-size: 80%;">Introducing the Covariance and Correlation functions</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs010.html#___sec9" style="font-size: 80%;">Correlation Function and Design/Feature Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Other techniques</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Covariance Matrix Examples</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Correlation Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Correlation Matrix with Pandas</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Correlation Matrix with Pandas and the Franke function</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs022.html#___sec21" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs023.html#___sec22" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs024.html#___sec23" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs025.html#___sec24" style="font-size: 80%;">Other techniques</a></li>
</ul>
</li>
@@ -194,7 +205,7 @@ We have a data set defined by a design/feature matrix \( \boldsymbol{X} \) (see
<li><a href="._DimRed-bs016.html">17</a></li>
<li><a href="._DimRed-bs017.html">18</a></li>
<li><a href="">...</a></li>
<li><a href="._DimRed-bs021.html">22</a></li>
<li><a href="._DimRed-bs025.html">26</a></li>
<li><a href="._DimRed-bs009.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+36 -25
View File
@@ -76,17 +76,24 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec9'),
('Classical PCA Theorem', 2, None, '___sec10'),
('Prof of the PCA Theorem', 2, None, '___sec11'),
('Getting started with PCA', 2, None, '___sec12'),
('Principal Component Analysis', 2, None, '___sec13'),
('PCA and scikit-learn', 2, None, '___sec14'),
('More on the PCA', 2, None, '___sec15'),
('Incremental PCA', 2, None, '___sec16'),
('Randomized PCA', 2, None, '___sec17'),
('Kernel PCA', 2, None, '___sec18'),
('LLE', 2, None, '___sec19'),
('Other techniques', 2, None, '___sec20')]}
('Covariance Matrix Examples', 2, None, '___sec10'),
('Correlation Matrix', 2, None, '___sec11'),
('Correlation Matrix with Pandas', 2, None, '___sec12'),
('Correlation Matrix with Pandas and the Franke function',
2,
None,
'___sec13'),
('Classical PCA Theorem', 2, None, '___sec14'),
('Prof of the PCA Theorem', 2, None, '___sec15'),
('Getting started with PCA', 2, None, '___sec16'),
('Principal Component Analysis', 2, None, '___sec17'),
('PCA and scikit-learn', 2, None, '___sec18'),
('More on the PCA', 2, None, '___sec19'),
('Incremental PCA', 2, None, '___sec20'),
('Randomized PCA', 2, None, '___sec21'),
('Kernel PCA', 2, None, '___sec22'),
('LLE', 2, None, '___sec23'),
('Other techniques', 2, None, '___sec24')]}
end of tocinfo -->
<body>
@@ -134,17 +141,21 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DimRed-bs008.html#___sec7" style="font-size: 80%;">Basic ideas of the Principal Component Analysis (PCA)</a></li>
<!-- navigation toc: --> <li><a href="#___sec8" style="font-size: 80%;">Introducing the Covariance and Correlation functions</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs010.html#___sec9" style="font-size: 80%;">Correlation Function and Design/Feature Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Other techniques</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Covariance Matrix Examples</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Correlation Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Correlation Matrix with Pandas</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Correlation Matrix with Pandas and the Franke function</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs022.html#___sec21" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs023.html#___sec22" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs024.html#___sec23" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs025.html#___sec24" style="font-size: 80%;">Other techniques</a></li>
</ul>
</li>
@@ -164,7 +175,7 @@ MathJax.Hub.Config({
<p>
Suppose we have defined two vectors
$\hat{x} and \hat{y} with \( n \) elements each. The covariance matrix $\boldsymbol{C}is defined as
\( \hat{x} \) and \( \hat{y} \) with \( n \) elements each. The covariance matrix \( \boldsymbol{C} \) is defined as
$$
\boldsymbol{C}[\boldsymbol{x},\boldsymbol{y}] = \begin{bmatrix} cov[\boldsymbol{x},\boldsymbol{x}] & cov[\boldsymbol{x},\boldsymbol{y}] \\
cov[\boldsymbol{y},\boldsymbol{x}] & cov[\boldsymbol{y},\boldsymbol{y}] \\
@@ -196,7 +207,7 @@ introducing instead the correlation matrix defined via the so-called
correlation function
$$
corr[\boldsymbol{x},\boldsymbol{y}]=\frac{cov[\boldsymbol{x},\boldsymbol{y}]}{\sqrt{var[\boldsymbol{x}]\var\boldsymbol{y}]}}.
corr[\boldsymbol{x},\boldsymbol{y}]=\frac{cov[\boldsymbol{x},\boldsymbol{y}]}{\sqrt{var[\boldsymbol{x}]\var[\boldsymbol{y}]}}.
$$
<p>
@@ -239,7 +250,7 @@ In the above example this is the function we constructed using <b>pandas</b>.
<li><a href="._DimRed-bs017.html">18</a></li>
<li><a href="._DimRed-bs018.html">19</a></li>
<li><a href="">...</a></li>
<li><a href="._DimRed-bs021.html">22</a></li>
<li><a href="._DimRed-bs025.html">26</a></li>
<li><a href="._DimRed-bs010.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+34 -23
View File
@@ -76,17 +76,24 @@ Automatically generated HTML file from DocOnce source
2,
None,
'___sec9'),
('Classical PCA Theorem', 2, None, '___sec10'),
('Prof of the PCA Theorem', 2, None, '___sec11'),
('Getting started with PCA', 2, None, '___sec12'),
('Principal Component Analysis', 2, None, '___sec13'),
('PCA and scikit-learn', 2, None, '___sec14'),
('More on the PCA', 2, None, '___sec15'),
('Incremental PCA', 2, None, '___sec16'),
('Randomized PCA', 2, None, '___sec17'),
('Kernel PCA', 2, None, '___sec18'),
('LLE', 2, None, '___sec19'),
('Other techniques', 2, None, '___sec20')]}
('Covariance Matrix Examples', 2, None, '___sec10'),
('Correlation Matrix', 2, None, '___sec11'),
('Correlation Matrix with Pandas', 2, None, '___sec12'),
('Correlation Matrix with Pandas and the Franke function',
2,
None,
'___sec13'),
('Classical PCA Theorem', 2, None, '___sec14'),
('Prof of the PCA Theorem', 2, None, '___sec15'),
('Getting started with PCA', 2, None, '___sec16'),
('Principal Component Analysis', 2, None, '___sec17'),
('PCA and scikit-learn', 2, None, '___sec18'),
('More on the PCA', 2, None, '___sec19'),
('Incremental PCA', 2, None, '___sec20'),
('Randomized PCA', 2, None, '___sec21'),
('Kernel PCA', 2, None, '___sec22'),
('LLE', 2, None, '___sec23'),
('Other techniques', 2, None, '___sec24')]}
end of tocinfo -->
<body>
@@ -134,17 +141,21 @@ MathJax.Hub.Config({
<!-- navigation toc: --> <li><a href="._DimRed-bs008.html#___sec7" style="font-size: 80%;">Basic ideas of the Principal Component Analysis (PCA)</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs009.html#___sec8" style="font-size: 80%;">Introducing the Covariance and Correlation functions</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs010.html#___sec9" style="font-size: 80%;">Correlation Function and Design/Feature Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Other techniques</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs011.html#___sec10" style="font-size: 80%;">Covariance Matrix Examples</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs012.html#___sec11" style="font-size: 80%;">Correlation Matrix</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs013.html#___sec12" style="font-size: 80%;">Correlation Matrix with Pandas</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs014.html#___sec13" style="font-size: 80%;">Correlation Matrix with Pandas and the Franke function</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs015.html#___sec14" style="font-size: 80%;">Classical PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs016.html#___sec15" style="font-size: 80%;">Prof of the PCA Theorem</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs017.html#___sec16" style="font-size: 80%;">Getting started with PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs018.html#___sec17" style="font-size: 80%;">Principal Component Analysis</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs019.html#___sec18" style="font-size: 80%;">PCA and scikit-learn</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs020.html#___sec19" style="font-size: 80%;">More on the PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs021.html#___sec20" style="font-size: 80%;">Incremental PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs022.html#___sec21" style="font-size: 80%;">Randomized PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs023.html#___sec22" style="font-size: 80%;">Kernel PCA</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs024.html#___sec23" style="font-size: 80%;">LLE</a></li>
<!-- navigation toc: --> <li><a href="._DimRed-bs025.html#___sec24" style="font-size: 80%;">Other techniques</a></li>
</ul>
</li>
@@ -203,7 +214,7 @@ MathJax.Hub.Config({
<li><a href="._DimRed-bs008.html">9</a></li>
<li><a href="._DimRed-bs009.html">10</a></li>
<li><a href="">...</a></li>
<li><a href="._DimRed-bs021.html">22</a></li>
<li><a href="._DimRed-bs025.html">26</a></li>
<li><a href="._DimRed-bs001.html">&raquo;</a></li>
</ul>
<!-- ------------------- end of main content --------------- -->
+166 -27
View File
@@ -526,7 +526,7 @@ We have a data set defined by a design/feature matrix \( \boldsymbol{X} \) (see
<p>
Suppose we have defined two vectors
$\hat{x} and \hat{y} with \( n \) elements each. The covariance matrix $\boldsymbol{C}is defined as
\( \hat{x} \) and \( \hat{y} \) with \( n \) elements each. The covariance matrix \( \boldsymbol{C} \) is defined as
<p>&nbsp;<br>
$$
\boldsymbol{C}[\boldsymbol{x},\boldsymbol{y}] = \begin{bmatrix} cov[\boldsymbol{x},\boldsymbol{x}] & cov[\boldsymbol{x},\boldsymbol{y}] \\
@@ -567,7 +567,7 @@ correlation function
<p>&nbsp;<br>
$$
corr[\boldsymbol{x},\boldsymbol{y}]=\frac{cov[\boldsymbol{x},\boldsymbol{y}]}{\sqrt{var[\boldsymbol{x}]\var\boldsymbol{y}]}}.
corr[\boldsymbol{x},\boldsymbol{y}]=\frac{cov[\boldsymbol{x},\boldsymbol{y}]}{\sqrt{var[\boldsymbol{x}]\var[\boldsymbol{y}]}}.
$$
<p>&nbsp;<br>
@@ -652,13 +652,22 @@ corr[\boldsymbol{x}_{p-1},\boldsymbol{x}_0] & corr[\boldsymbol{x}_{p-1},\bolds
\end{bmatrix},
$$
<p>&nbsp;<br>
</section>
<section>
<h2 id="___sec10">Covariance Matrix Examples </h2>
<p>
The Numpy function <b>np.cov</b> calculates the covariance elements using the factor \( 1/(n-1) \) instead of \( 1/n \) since it assumes we do not have the exact mean values.
The following simple function uses the <b>np.vstack</b> function which takes each vector of dimension \( 1\times n \) and produces a \( 2\times n \) matrix \( \hat{W} \)
The Numpy function <b>np.cov</b> calculates the covariance elements using
the factor \( 1/(n-1) \) instead of \( 1/n \) since it assumes we do not have
the exact mean values. The following simple function uses the
<b>np.vstack</b> function which takes each vector of dimension \( 1\times n \)
and produces a \( 2\times n \) matrix \( \boldsymbol{W} \)
<p>&nbsp;<br>
$$
\hat{W} = \begin{bmatrix} x_0 & y_0 \\
\boldsymbol{W} = \begin{bmatrix} x_0 & y_0 \\
x_1 & y_1 \\
x_2 & y_2\\
\dots & \dots \\
@@ -669,9 +678,9 @@ $$
<p>&nbsp;<br>
<p>
which in turn is converted into into the \( 3\times 3 \) covariance matrix
\( \hat{\Sigma} \) via the Numpy function <b>np.cov()</b>. We note that we can also calculate
the mean value of each set of samples \( \hat{x} \) etc using the Numpy
which in turn is converted into into the \( 2\times 2 \) covariance matrix
\( \boldsymbol{C} \) via the Numpy function <b>np.cov()</b>. We note that we can also calculate
the mean value of each set of samples \( \boldsymbol{x} \) etc using the Numpy
function <b>np.mean(x)</b>. We can also extract the eigenvalues of the
covariance matrix through the <b>np.linalg.eig()</b> function.
@@ -680,35 +689,165 @@ covariance matrix through the <b>np.linalg.eig()</b> function.
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22"># Importing various packages</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
n = <span style="color: #B452CD">100</span>
x = np.random.normal(size=n)
<span style="color: #8B008B; font-weight: bold">print</span>(np.mean(x))
y = <span style="color: #B452CD">4</span>+<span style="color: #B452CD">3</span>*x+np.random.normal(size=n)
<span style="color: #8B008B; font-weight: bold">print</span>(np.mean(y))
z = x**<span style="color: #B452CD">3</span>+np.random.normal(size=n)
<span style="color: #8B008B; font-weight: bold">print</span>(np.mean(z))
W = np.vstack((x, y, z))
Sigma = np.cov(W)
<span style="color: #8B008B; font-weight: bold">print</span>(Sigma)
Eigvals, Eigvecs = np.linalg.eig(Sigma)
<span style="color: #8B008B; font-weight: bold">print</span>(Eigvals)
W = np.vstack((x, y))
C = np.cov(W)
<span style="color: #8B008B; font-weight: bold">print</span>(C)
</pre></div>
</section>
<section>
<h2 id="___sec10">Classical PCA Theorem </h2>
<h2 id="___sec11">Correlation Matrix </h2>
<p>
The previous example can be converted into the correlation matrix by
simply scaling the matrix elements with the variances. We should also
subtract the mean values for each column. This leads to the following
code which sets up the correlations matrix for the previous example in
a more brute force way. Here we scale the mean values for each column of the design matrix, calculate the relevant mean values and variances and then finally set up the \( 2\times 2 \) correlation matrix (since we have only two vectors).
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
n = <span style="color: #B452CD">100</span>
<span style="color: #228B22"># define two vectors </span>
x = np.random.random(size=n)
y = <span style="color: #B452CD">4</span>+<span style="color: #B452CD">3</span>*x+np.random.normal(size=n)
<span style="color: #228B22">#scaling the x and y vectors </span>
x = x - np.mean(x)
y = y - np.mean(y)
variance_x = np.sum(x<span style="color: #707a7c">@x</span>)/n
variance_y = np.sum(y<span style="color: #707a7c">@y</span>)/n
<span style="color: #8B008B; font-weight: bold">print</span>(variance_x)
<span style="color: #8B008B; font-weight: bold">print</span>(variance_y)
cov_xy = np.sum(x<span style="color: #707a7c">@y</span>)/n
cov_xx = np.sum(x<span style="color: #707a7c">@x</span>)/n
cov_yy = np.sum(y<span style="color: #707a7c">@y</span>)/n
C = np.zeros((<span style="color: #B452CD">2</span>,<span style="color: #B452CD">2</span>))
C[<span style="color: #B452CD">0</span>,<span style="color: #B452CD">0</span>]= cov_xx/variance_x
C[<span style="color: #B452CD">1</span>,<span style="color: #B452CD">1</span>]= cov_yy/variance_y
C[<span style="color: #B452CD">0</span>,<span style="color: #B452CD">1</span>]= cov_xy/np.sqrt(variance_y*variance_x)
C[<span style="color: #B452CD">1</span>,<span style="color: #B452CD">0</span>]= C[<span style="color: #B452CD">0</span>,<span style="color: #B452CD">1</span>]
<span style="color: #8B008B; font-weight: bold">print</span>(C)
</pre></div>
<p>
We see that the matrix elements along the diagonal are one as they
should be and that the matrix is symmetric. Furthermore, diagonalizing
this matrix we easily see that it is a positive definite matrix.
<p>
The above procedure with <b>numpy</b> can be made more compact if we use <b>pandas</b>.
</section>
<section>
<h2 id="___sec11">Prof of the PCA Theorem </h2>
<h2 id="___sec12">Correlation Matrix with Pandas </h2>
<p>
We whow here how we can set up the correlation matrix using <b>pandas</b>, as done in this simple code
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</span>
n = <span style="color: #B452CD">10</span>
x = np.random.normal(size=n)
x = x - np.mean(x)
y = <span style="color: #B452CD">4</span>+<span style="color: #B452CD">3</span>*x+np.random.normal(size=n)
y = y - np.mean(y)
X = (np.vstack((x, y))).T
<span style="color: #8B008B; font-weight: bold">print</span>(X)
Xpd = pd.DataFrame(X)
<span style="color: #8B008B; font-weight: bold">print</span>(Xpd)
correlation_matrix = Xpd.corr()
<span style="color: #8B008B; font-weight: bold">print</span>(correlation_matrix)
</pre></div>
<p>
We expand this model to the Franke function discussed above.
</section>
<section>
<h2 id="___sec12">Getting started with PCA </h2>
<h2 id="___sec13">Correlation Matrix with Pandas and the Franke function </h2>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="font-size: 80%; line-height: 125%"><span></span><span style="color: #228B22"># Common imports</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</span>
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">FrankeFunction</span>(x,y):
term1 = <span style="color: #B452CD">0.75</span>*np.exp(-(<span style="color: #B452CD">0.25</span>*(<span style="color: #B452CD">9</span>*x-<span style="color: #B452CD">2</span>)**<span style="color: #B452CD">2</span>) - <span style="color: #B452CD">0.25</span>*((<span style="color: #B452CD">9</span>*y-<span style="color: #B452CD">2</span>)**<span style="color: #B452CD">2</span>))
term2 = <span style="color: #B452CD">0.75</span>*np.exp(-((<span style="color: #B452CD">9</span>*x+<span style="color: #B452CD">1</span>)**<span style="color: #B452CD">2</span>)/<span style="color: #B452CD">49.0</span> - <span style="color: #B452CD">0.1</span>*(<span style="color: #B452CD">9</span>*y+<span style="color: #B452CD">1</span>))
term3 = <span style="color: #B452CD">0.5</span>*np.exp(-(<span style="color: #B452CD">9</span>*x-<span style="color: #B452CD">7</span>)**<span style="color: #B452CD">2</span>/<span style="color: #B452CD">4.0</span> - <span style="color: #B452CD">0.25</span>*((<span style="color: #B452CD">9</span>*y-<span style="color: #B452CD">3</span>)**<span style="color: #B452CD">2</span>))
term4 = -<span style="color: #B452CD">0.2</span>*np.exp(-(<span style="color: #B452CD">9</span>*x-<span style="color: #B452CD">4</span>)**<span style="color: #B452CD">2</span> - (<span style="color: #B452CD">9</span>*y-<span style="color: #B452CD">7</span>)**<span style="color: #B452CD">2</span>)
<span style="color: #8B008B; font-weight: bold">return</span> term1 + term2 + term3 + term4
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">create_X</span>(x, y, n ):
<span style="color: #8B008B; font-weight: bold">if</span> <span style="color: #658b00">len</span>(x.shape) &gt; <span style="color: #B452CD">1</span>:
x = np.ravel(x)
y = np.ravel(y)
N = <span style="color: #658b00">len</span>(x)
l = <span style="color: #658b00">int</span>((n+<span style="color: #B452CD">1</span>)*(n+<span style="color: #B452CD">2</span>)/<span style="color: #B452CD">2</span>) <span style="color: #228B22"># Number of elements in beta</span>
X = np.ones((N,l))
<span style="color: #8B008B; font-weight: bold">for</span> i <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(<span style="color: #B452CD">1</span>,n+<span style="color: #B452CD">1</span>):
q = <span style="color: #658b00">int</span>((i)*(i+<span style="color: #B452CD">1</span>)/<span style="color: #B452CD">2</span>)
<span style="color: #8B008B; font-weight: bold">for</span> k <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(i+<span style="color: #B452CD">1</span>):
X[:,q+k] = (x**(i-k))*(y**k)
<span style="color: #8B008B; font-weight: bold">return</span> X
<span style="color: #228B22"># Making meshgrid of datapoints and compute Franke&#39;s function</span>
n = <span style="color: #B452CD">4</span>
N = <span style="color: #B452CD">100</span>
x = np.sort(np.random.uniform(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">1</span>, N))
y = np.sort(np.random.uniform(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">1</span>, N))
z = FrankeFunction(x, y)
X = create_X(x, y, n=n)
Xpd = pd.DataFrame(X)
<span style="color: #228B22"># subtract the mean values and set up the covariance matrix</span>
Xpd = Xpd - Xpd.mean()
covariance_matrix = Xpd.cov()
<span style="color: #8B008B; font-weight: bold">print</span>(covariance_matrix)
</pre></div>
<p>
We note here that the covariance is zero for the first rows and
columns since all matrix elements in the design matrix were set to one
(we are fitting the function in terms of a polynomial of degree \( n \)).
<p>
This means that the variance for these elements will be zero and will
cause problems when we set up the correlation matrix. We can simply
drop these elements as follows and then construct the correlation
matrix.
</section>
<section>
<h2 id="___sec14">Classical PCA Theorem </h2>
</section>
<section>
<h2 id="___sec15">Prof of the PCA Theorem </h2>
</section>
<section>
<h2 id="___sec16">Getting started with PCA </h2>
<p>
@@ -724,7 +863,7 @@ X_pca = pca.transform(X_train_scaled)
<section>
<h2 id="___sec13">Principal Component Analysis </h2>
<h2 id="___sec17">Principal Component Analysis </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -761,7 +900,7 @@ X2D = X_centered.dot(W2)
<section>
<h2 id="___sec14">PCA and scikit-learn </h2>
<h2 id="___sec18">PCA and scikit-learn </h2>
<p>
Scikit-Learn&#8217;s PCA class implements PCA using SVD decomposition just like we did before. The
@@ -792,7 +931,7 @@ More material to come here.
<section>
<h2 id="___sec15">More on the PCA </h2>
<h2 id="___sec19">More on the PCA </h2>
<p>
Instead of arbitrarily choosing the number of dimensions to reduce down to, it is generally preferable to
@@ -823,7 +962,7 @@ X_reduced = pca.fit_transform(X)
<section>
<h2 id="___sec16">Incremental PCA </h2>
<h2 id="___sec20">Incremental PCA </h2>
<p>
One problem with the preceding implementation of PCA is that it requires the whole training set to fit in
@@ -835,7 +974,7 @@ instances arrive).
<section>
<h2 id="___sec17">Randomized PCA </h2>
<h2 id="___sec21">Randomized PCA </h2>
<p>
Scikit-Learn offers yet another option to perform PCA, called Randomized PCA. This is a stochastic
@@ -849,7 +988,7 @@ previous algorithms when \( d \) is much smaller than \( n \).
<section>
<h2 id="___sec18">Kernel PCA </h2>
<h2 id="___sec22">Kernel PCA </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -875,7 +1014,7 @@ X_reduced = rbf_pca.fit_transform(X)
<section>
<h2 id="___sec19">LLE </h2>
<h2 id="___sec23">LLE </h2>
<p>
Locally Linear Embedding (LLE) is another very powerful nonlinear dimensionality reduction
@@ -887,7 +1026,7 @@ these local relationships are best preserved (more details shortly).
<section>
<h2 id="___sec20">Other techniques </h2>
<h2 id="___sec24">Other techniques </h2>
<p>
There are many other dimensionality reduction techniques, several of which are available in Scikit-Learn.
+184 -38
View File
@@ -96,17 +96,24 @@ div { text-align: justify; text-justify: inter-word; }
2,
None,
'___sec9'),
('Classical PCA Theorem', 2, None, '___sec10'),
('Prof of the PCA Theorem', 2, None, '___sec11'),
('Getting started with PCA', 2, None, '___sec12'),
('Principal Component Analysis', 2, None, '___sec13'),
('PCA and scikit-learn', 2, None, '___sec14'),
('More on the PCA', 2, None, '___sec15'),
('Incremental PCA', 2, None, '___sec16'),
('Randomized PCA', 2, None, '___sec17'),
('Kernel PCA', 2, None, '___sec18'),
('LLE', 2, None, '___sec19'),
('Other techniques', 2, None, '___sec20')]}
('Covariance Matrix Examples', 2, None, '___sec10'),
('Correlation Matrix', 2, None, '___sec11'),
('Correlation Matrix with Pandas', 2, None, '___sec12'),
('Correlation Matrix with Pandas and the Franke function',
2,
None,
'___sec13'),
('Classical PCA Theorem', 2, None, '___sec14'),
('Prof of the PCA Theorem', 2, None, '___sec15'),
('Getting started with PCA', 2, None, '___sec16'),
('Principal Component Analysis', 2, None, '___sec17'),
('PCA and scikit-learn', 2, None, '___sec18'),
('More on the PCA', 2, None, '___sec19'),
('Incremental PCA', 2, None, '___sec20'),
('Randomized PCA', 2, None, '___sec21'),
('Kernel PCA', 2, None, '___sec22'),
('LLE', 2, None, '___sec23'),
('Other techniques', 2, None, '___sec24')]}
end of tocinfo -->
<body>
@@ -522,7 +529,7 @@ We have a data set defined by a design/feature matrix \( \boldsymbol{X} \) (see
<p>
Suppose we have defined two vectors
$\hat{x} and \hat{y} with \( n \) elements each. The covariance matrix $\boldsymbol{C}is defined as
\( \hat{x} \) and \( \hat{y} \) with \( n \) elements each. The covariance matrix \( \boldsymbol{C} \) is defined as
$$
\boldsymbol{C}[\boldsymbol{x},\boldsymbol{y}] = \begin{bmatrix} cov[\boldsymbol{x},\boldsymbol{x}] & cov[\boldsymbol{x},\boldsymbol{y}] \\
cov[\boldsymbol{y},\boldsymbol{x}] & cov[\boldsymbol{y},\boldsymbol{y}] \\
@@ -554,7 +561,7 @@ introducing instead the correlation matrix defined via the so-called
correlation function
$$
corr[\boldsymbol{x},\boldsymbol{y}]=\frac{cov[\boldsymbol{x},\boldsymbol{y}]}{\sqrt{var[\boldsymbol{x}]\var\boldsymbol{y}]}}.
corr[\boldsymbol{x},\boldsymbol{y}]=\frac{cov[\boldsymbol{x},\boldsymbol{y}]}{\sqrt{var[\boldsymbol{x}]\var[\boldsymbol{y}]}}.
$$
<p>
@@ -628,10 +635,19 @@ corr[\boldsymbol{x}_{p-1},\boldsymbol{x}_0] & corr[\boldsymbol{x}_{p-1},\bolds
$$
<p>
The Numpy function <b>np.cov</b> calculates the covariance elements using the factor \( 1/(n-1) \) instead of \( 1/n \) since it assumes we do not have the exact mean values.
The following simple function uses the <b>np.vstack</b> function which takes each vector of dimension \( 1\times n \) and produces a \( 2\times n \) matrix \( \hat{W} \)
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec10">Covariance Matrix Examples </h2>
<p>
The Numpy function <b>np.cov</b> calculates the covariance elements using
the factor \( 1/(n-1) \) instead of \( 1/n \) since it assumes we do not have
the exact mean values. The following simple function uses the
<b>np.vstack</b> function which takes each vector of dimension \( 1\times n \)
and produces a \( 2\times n \) matrix \( \boldsymbol{W} \)
$$
\hat{W} = \begin{bmatrix} x_0 & y_0 \\
\boldsymbol{W} = \begin{bmatrix} x_0 & y_0 \\
x_1 & y_1 \\
x_2 & y_2\\
\dots & \dots \\
@@ -641,9 +657,9 @@ $$
$$
<p>
which in turn is converted into into the \( 3\times 3 \) covariance matrix
\( \hat{\Sigma} \) via the Numpy function <b>np.cov()</b>. We note that we can also calculate
the mean value of each set of samples \( \hat{x} \) etc using the Numpy
which in turn is converted into into the \( 2\times 2 \) covariance matrix
\( \boldsymbol{C} \) via the Numpy function <b>np.cov()</b>. We note that we can also calculate
the mean value of each set of samples \( \boldsymbol{x} \) etc using the Numpy
function <b>np.mean(x)</b>. We can also extract the eigenvalues of the
covariance matrix through the <b>np.linalg.eig()</b> function.
@@ -652,34 +668,164 @@ covariance matrix through the <b>np.linalg.eig()</b> function.
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span><span style="color: #228B22"># Importing various packages</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
n = <span style="color: #B452CD">100</span>
x = np.random.normal(size=n)
<span style="color: #8B008B; font-weight: bold">print</span>(np.mean(x))
y = <span style="color: #B452CD">4</span>+<span style="color: #B452CD">3</span>*x+np.random.normal(size=n)
<span style="color: #8B008B; font-weight: bold">print</span>(np.mean(y))
z = x**<span style="color: #B452CD">3</span>+np.random.normal(size=n)
<span style="color: #8B008B; font-weight: bold">print</span>(np.mean(z))
W = np.vstack((x, y, z))
Sigma = np.cov(W)
<span style="color: #8B008B; font-weight: bold">print</span>(Sigma)
Eigvals, Eigvecs = np.linalg.eig(Sigma)
<span style="color: #8B008B; font-weight: bold">print</span>(Eigvals)
W = np.vstack((x, y))
C = np.cov(W)
<span style="color: #8B008B; font-weight: bold">print</span>(C)
</pre></div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec10">Classical PCA Theorem </h2>
<h2 id="___sec11">Correlation Matrix </h2>
<p>
The previous example can be converted into the correlation matrix by
simply scaling the matrix elements with the variances. We should also
subtract the mean values for each column. This leads to the following
code which sets up the correlations matrix for the previous example in
a more brute force way. Here we scale the mean values for each column of the design matrix, calculate the relevant mean values and variances and then finally set up the \( 2\times 2 \) correlation matrix (since we have only two vectors).
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
n = <span style="color: #B452CD">100</span>
<span style="color: #228B22"># define two vectors </span>
x = np.random.random(size=n)
y = <span style="color: #B452CD">4</span>+<span style="color: #B452CD">3</span>*x+np.random.normal(size=n)
<span style="color: #228B22">#scaling the x and y vectors </span>
x = x - np.mean(x)
y = y - np.mean(y)
variance_x = np.sum(x<span style="color: #707a7c">@x</span>)/n
variance_y = np.sum(y<span style="color: #707a7c">@y</span>)/n
<span style="color: #8B008B; font-weight: bold">print</span>(variance_x)
<span style="color: #8B008B; font-weight: bold">print</span>(variance_y)
cov_xy = np.sum(x<span style="color: #707a7c">@y</span>)/n
cov_xx = np.sum(x<span style="color: #707a7c">@x</span>)/n
cov_yy = np.sum(y<span style="color: #707a7c">@y</span>)/n
C = np.zeros((<span style="color: #B452CD">2</span>,<span style="color: #B452CD">2</span>))
C[<span style="color: #B452CD">0</span>,<span style="color: #B452CD">0</span>]= cov_xx/variance_x
C[<span style="color: #B452CD">1</span>,<span style="color: #B452CD">1</span>]= cov_yy/variance_y
C[<span style="color: #B452CD">0</span>,<span style="color: #B452CD">1</span>]= cov_xy/np.sqrt(variance_y*variance_x)
C[<span style="color: #B452CD">1</span>,<span style="color: #B452CD">0</span>]= C[<span style="color: #B452CD">0</span>,<span style="color: #B452CD">1</span>]
<span style="color: #8B008B; font-weight: bold">print</span>(C)
</pre></div>
<p>
We see that the matrix elements along the diagonal are one as they
should be and that the matrix is symmetric. Furthermore, diagonalizing
this matrix we easily see that it is a positive definite matrix.
<p>
The above procedure with <b>numpy</b> can be made more compact if we use <b>pandas</b>.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec11">Prof of the PCA Theorem </h2>
<h2 id="___sec12">Correlation Matrix with Pandas </h2>
<p>
We whow here how we can set up the correlation matrix using <b>pandas</b>, as done in this simple code
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span><span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</span>
n = <span style="color: #B452CD">10</span>
x = np.random.normal(size=n)
x = x - np.mean(x)
y = <span style="color: #B452CD">4</span>+<span style="color: #B452CD">3</span>*x+np.random.normal(size=n)
y = y - np.mean(y)
X = (np.vstack((x, y))).T
<span style="color: #8B008B; font-weight: bold">print</span>(X)
Xpd = pd.DataFrame(X)
<span style="color: #8B008B; font-weight: bold">print</span>(Xpd)
correlation_matrix = Xpd.corr()
<span style="color: #8B008B; font-weight: bold">print</span>(correlation_matrix)
</pre></div>
<p>
We expand this model to the Franke function discussed above.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec12">Getting started with PCA </h2>
<h2 id="___sec13">Correlation Matrix with Pandas and the Franke function </h2>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "perldoc" -->
<div class="highlight" style="background: #eeeedd"><pre style="line-height: 125%"><span></span><span style="color: #228B22"># Common imports</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">numpy</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">np</span>
<span style="color: #8B008B; font-weight: bold">import</span> <span style="color: #008b45; text-decoration: underline">pandas</span> <span style="color: #8B008B; font-weight: bold">as</span> <span style="color: #008b45; text-decoration: underline">pd</span>
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">FrankeFunction</span>(x,y):
term1 = <span style="color: #B452CD">0.75</span>*np.exp(-(<span style="color: #B452CD">0.25</span>*(<span style="color: #B452CD">9</span>*x-<span style="color: #B452CD">2</span>)**<span style="color: #B452CD">2</span>) - <span style="color: #B452CD">0.25</span>*((<span style="color: #B452CD">9</span>*y-<span style="color: #B452CD">2</span>)**<span style="color: #B452CD">2</span>))
term2 = <span style="color: #B452CD">0.75</span>*np.exp(-((<span style="color: #B452CD">9</span>*x+<span style="color: #B452CD">1</span>)**<span style="color: #B452CD">2</span>)/<span style="color: #B452CD">49.0</span> - <span style="color: #B452CD">0.1</span>*(<span style="color: #B452CD">9</span>*y+<span style="color: #B452CD">1</span>))
term3 = <span style="color: #B452CD">0.5</span>*np.exp(-(<span style="color: #B452CD">9</span>*x-<span style="color: #B452CD">7</span>)**<span style="color: #B452CD">2</span>/<span style="color: #B452CD">4.0</span> - <span style="color: #B452CD">0.25</span>*((<span style="color: #B452CD">9</span>*y-<span style="color: #B452CD">3</span>)**<span style="color: #B452CD">2</span>))
term4 = -<span style="color: #B452CD">0.2</span>*np.exp(-(<span style="color: #B452CD">9</span>*x-<span style="color: #B452CD">4</span>)**<span style="color: #B452CD">2</span> - (<span style="color: #B452CD">9</span>*y-<span style="color: #B452CD">7</span>)**<span style="color: #B452CD">2</span>)
<span style="color: #8B008B; font-weight: bold">return</span> term1 + term2 + term3 + term4
<span style="color: #8B008B; font-weight: bold">def</span> <span style="color: #008b45">create_X</span>(x, y, n ):
<span style="color: #8B008B; font-weight: bold">if</span> <span style="color: #658b00">len</span>(x.shape) &gt; <span style="color: #B452CD">1</span>:
x = np.ravel(x)
y = np.ravel(y)
N = <span style="color: #658b00">len</span>(x)
l = <span style="color: #658b00">int</span>((n+<span style="color: #B452CD">1</span>)*(n+<span style="color: #B452CD">2</span>)/<span style="color: #B452CD">2</span>) <span style="color: #228B22"># Number of elements in beta</span>
X = np.ones((N,l))
<span style="color: #8B008B; font-weight: bold">for</span> i <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(<span style="color: #B452CD">1</span>,n+<span style="color: #B452CD">1</span>):
q = <span style="color: #658b00">int</span>((i)*(i+<span style="color: #B452CD">1</span>)/<span style="color: #B452CD">2</span>)
<span style="color: #8B008B; font-weight: bold">for</span> k <span style="color: #8B008B">in</span> <span style="color: #658b00">range</span>(i+<span style="color: #B452CD">1</span>):
X[:,q+k] = (x**(i-k))*(y**k)
<span style="color: #8B008B; font-weight: bold">return</span> X
<span style="color: #228B22"># Making meshgrid of datapoints and compute Franke&#39;s function</span>
n = <span style="color: #B452CD">4</span>
N = <span style="color: #B452CD">100</span>
x = np.sort(np.random.uniform(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">1</span>, N))
y = np.sort(np.random.uniform(<span style="color: #B452CD">0</span>, <span style="color: #B452CD">1</span>, N))
z = FrankeFunction(x, y)
X = create_X(x, y, n=n)
Xpd = pd.DataFrame(X)
<span style="color: #228B22"># subtract the mean values and set up the covariance matrix</span>
Xpd = Xpd - Xpd.mean()
covariance_matrix = Xpd.cov()
<span style="color: #8B008B; font-weight: bold">print</span>(covariance_matrix)
</pre></div>
<p>
We note here that the covariance is zero for the first rows and
columns since all matrix elements in the design matrix were set to one
(we are fitting the function in terms of a polynomial of degree \( n \)).
<p>
This means that the variance for these elements will be zero and will
cause problems when we set up the correlation matrix. We can simply
drop these elements as follows and then construct the correlation
matrix.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec14">Classical PCA Theorem </h2>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec15">Prof of the PCA Theorem </h2>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec16">Getting started with PCA </h2>
<p>
@@ -694,7 +840,7 @@ X_pca = pca.transform(X_train_scaled)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec13">Principal Component Analysis </h2>
<h2 id="___sec17">Principal Component Analysis </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -730,7 +876,7 @@ X2D = X_centered.dot(W2)
<p>
<!-- !split -->
<h2 id="___sec14">PCA and scikit-learn </h2>
<h2 id="___sec18">PCA and scikit-learn </h2>
<p>
Scikit-Learn&#8217;s PCA class implements PCA using SVD decomposition just like we did before. The
@@ -761,7 +907,7 @@ More material to come here.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec15">More on the PCA </h2>
<h2 id="___sec19">More on the PCA </h2>
<p>
Instead of arbitrarily choosing the number of dimensions to reduce down to, it is generally preferable to
@@ -791,7 +937,7 @@ X_reduced = pca.fit_transform(X)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec16">Incremental PCA </h2>
<h2 id="___sec20">Incremental PCA </h2>
<p>
One problem with the preceding implementation of PCA is that it requires the whole training set to fit in
@@ -803,7 +949,7 @@ instances arrive).
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec17">Randomized PCA </h2>
<h2 id="___sec21">Randomized PCA </h2>
<p>
Scikit-Learn offers yet another option to perform PCA, called Randomized PCA. This is a stochastic
@@ -818,7 +964,7 @@ previous algorithms when \( d \) is much smaller than \( n \).
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec18">Kernel PCA </h2>
<h2 id="___sec22">Kernel PCA </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -847,7 +993,7 @@ X_reduced = rbf_pca.fit_transform(X)
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec19">LLE </h2>
<h2 id="___sec23">LLE </h2>
<p>
Locally Linear Embedding (LLE) is another very powerful nonlinear dimensionality reduction
@@ -859,7 +1005,7 @@ these local relationships are best preserved (more details shortly).
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec20">Other techniques </h2>
<h2 id="___sec24">Other techniques </h2>
<p>
There are many other dimensionality reduction techniques, several of which are available in Scikit-Learn.
+184 -38
View File
@@ -101,17 +101,24 @@ div { text-align: justify; text-justify: inter-word; }
2,
None,
'___sec9'),
('Classical PCA Theorem', 2, None, '___sec10'),
('Prof of the PCA Theorem', 2, None, '___sec11'),
('Getting started with PCA', 2, None, '___sec12'),
('Principal Component Analysis', 2, None, '___sec13'),
('PCA and scikit-learn', 2, None, '___sec14'),
('More on the PCA', 2, None, '___sec15'),
('Incremental PCA', 2, None, '___sec16'),
('Randomized PCA', 2, None, '___sec17'),
('Kernel PCA', 2, None, '___sec18'),
('LLE', 2, None, '___sec19'),
('Other techniques', 2, None, '___sec20')]}
('Covariance Matrix Examples', 2, None, '___sec10'),
('Correlation Matrix', 2, None, '___sec11'),
('Correlation Matrix with Pandas', 2, None, '___sec12'),
('Correlation Matrix with Pandas and the Franke function',
2,
None,
'___sec13'),
('Classical PCA Theorem', 2, None, '___sec14'),
('Prof of the PCA Theorem', 2, None, '___sec15'),
('Getting started with PCA', 2, None, '___sec16'),
('Principal Component Analysis', 2, None, '___sec17'),
('PCA and scikit-learn', 2, None, '___sec18'),
('More on the PCA', 2, None, '___sec19'),
('Incremental PCA', 2, None, '___sec20'),
('Randomized PCA', 2, None, '___sec21'),
('Kernel PCA', 2, None, '___sec22'),
('LLE', 2, None, '___sec23'),
('Other techniques', 2, None, '___sec24')]}
end of tocinfo -->
<body>
@@ -527,7 +534,7 @@ We have a data set defined by a design/feature matrix \( \boldsymbol{X} \) (see
<p>
Suppose we have defined two vectors
$\hat{x} and \hat{y} with \( n \) elements each. The covariance matrix $\boldsymbol{C}is defined as
\( \hat{x} \) and \( \hat{y} \) with \( n \) elements each. The covariance matrix \( \boldsymbol{C} \) is defined as
$$
\boldsymbol{C}[\boldsymbol{x},\boldsymbol{y}] = \begin{bmatrix} cov[\boldsymbol{x},\boldsymbol{x}] & cov[\boldsymbol{x},\boldsymbol{y}] \\
cov[\boldsymbol{y},\boldsymbol{x}] & cov[\boldsymbol{y},\boldsymbol{y}] \\
@@ -559,7 +566,7 @@ introducing instead the correlation matrix defined via the so-called
correlation function
$$
corr[\boldsymbol{x},\boldsymbol{y}]=\frac{cov[\boldsymbol{x},\boldsymbol{y}]}{\sqrt{var[\boldsymbol{x}]\var\boldsymbol{y}]}}.
corr[\boldsymbol{x},\boldsymbol{y}]=\frac{cov[\boldsymbol{x},\boldsymbol{y}]}{\sqrt{var[\boldsymbol{x}]\var[\boldsymbol{y}]}}.
$$
<p>
@@ -633,10 +640,19 @@ corr[\boldsymbol{x}_{p-1},\boldsymbol{x}_0] & corr[\boldsymbol{x}_{p-1},\bolds
$$
<p>
The Numpy function <b>np.cov</b> calculates the covariance elements using the factor \( 1/(n-1) \) instead of \( 1/n \) since it assumes we do not have the exact mean values.
The following simple function uses the <b>np.vstack</b> function which takes each vector of dimension \( 1\times n \) and produces a \( 2\times n \) matrix \( \hat{W} \)
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec10">Covariance Matrix Examples </h2>
<p>
The Numpy function <b>np.cov</b> calculates the covariance elements using
the factor \( 1/(n-1) \) instead of \( 1/n \) since it assumes we do not have
the exact mean values. The following simple function uses the
<b>np.vstack</b> function which takes each vector of dimension \( 1\times n \)
and produces a \( 2\times n \) matrix \( \boldsymbol{W} \)
$$
\hat{W} = \begin{bmatrix} x_0 & y_0 \\
\boldsymbol{W} = \begin{bmatrix} x_0 & y_0 \\
x_1 & y_1 \\
x_2 & y_2\\
\dots & \dots \\
@@ -646,9 +662,9 @@ $$
$$
<p>
which in turn is converted into into the \( 3\times 3 \) covariance matrix
\( \hat{\Sigma} \) via the Numpy function <b>np.cov()</b>. We note that we can also calculate
the mean value of each set of samples \( \hat{x} \) etc using the Numpy
which in turn is converted into into the \( 2\times 2 \) covariance matrix
\( \boldsymbol{C} \) via the Numpy function <b>np.cov()</b>. We note that we can also calculate
the mean value of each set of samples \( \boldsymbol{x} \) etc using the Numpy
function <b>np.mean(x)</b>. We can also extract the eigenvalues of the
covariance matrix through the <b>np.linalg.eig()</b> function.
@@ -657,34 +673,164 @@ covariance matrix through the <b>np.linalg.eig()</b> function.
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Importing various packages</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
n <span style="color: #666666">=</span> <span style="color: #666666">100</span>
x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>normal(size<span style="color: #666666">=</span>n)
<span style="color: #008000; font-weight: bold">print</span>(np<span style="color: #666666">.</span>mean(x))
y <span style="color: #666666">=</span> <span style="color: #666666">4+3*</span>x<span style="color: #666666">+</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>normal(size<span style="color: #666666">=</span>n)
<span style="color: #008000; font-weight: bold">print</span>(np<span style="color: #666666">.</span>mean(y))
z <span style="color: #666666">=</span> x<span style="color: #666666">**3+</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>normal(size<span style="color: #666666">=</span>n)
<span style="color: #008000; font-weight: bold">print</span>(np<span style="color: #666666">.</span>mean(z))
W <span style="color: #666666">=</span> np<span style="color: #666666">.</span>vstack((x, y, z))
Sigma <span style="color: #666666">=</span> np<span style="color: #666666">.</span>cov(W)
<span style="color: #008000; font-weight: bold">print</span>(Sigma)
Eigvals, Eigvecs <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linalg<span style="color: #666666">.</span>eig(Sigma)
<span style="color: #008000; font-weight: bold">print</span>(Eigvals)
W <span style="color: #666666">=</span> np<span style="color: #666666">.</span>vstack((x, y))
C <span style="color: #666666">=</span> np<span style="color: #666666">.</span>cov(W)
<span style="color: #008000; font-weight: bold">print</span>(C)
</pre></div>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec10">Classical PCA Theorem </h2>
<h2 id="___sec11">Correlation Matrix </h2>
<p>
The previous example can be converted into the correlation matrix by
simply scaling the matrix elements with the variances. We should also
subtract the mean values for each column. This leads to the following
code which sets up the correlations matrix for the previous example in
a more brute force way. Here we scale the mean values for each column of the design matrix, calculate the relevant mean values and variances and then finally set up the \( 2\times 2 \) correlation matrix (since we have only two vectors).
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
n <span style="color: #666666">=</span> <span style="color: #666666">100</span>
<span style="color: #408080; font-style: italic"># define two vectors </span>
x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>random(size<span style="color: #666666">=</span>n)
y <span style="color: #666666">=</span> <span style="color: #666666">4+3*</span>x<span style="color: #666666">+</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>normal(size<span style="color: #666666">=</span>n)
<span style="color: #408080; font-style: italic">#scaling the x and y vectors </span>
x <span style="color: #666666">=</span> x <span style="color: #666666">-</span> np<span style="color: #666666">.</span>mean(x)
y <span style="color: #666666">=</span> y <span style="color: #666666">-</span> np<span style="color: #666666">.</span>mean(y)
variance_x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>sum(x<span style="color: #AA22FF">@x</span>)<span style="color: #666666">/</span>n
variance_y <span style="color: #666666">=</span> np<span style="color: #666666">.</span>sum(y<span style="color: #AA22FF">@y</span>)<span style="color: #666666">/</span>n
<span style="color: #008000; font-weight: bold">print</span>(variance_x)
<span style="color: #008000; font-weight: bold">print</span>(variance_y)
cov_xy <span style="color: #666666">=</span> np<span style="color: #666666">.</span>sum(x<span style="color: #AA22FF">@y</span>)<span style="color: #666666">/</span>n
cov_xx <span style="color: #666666">=</span> np<span style="color: #666666">.</span>sum(x<span style="color: #AA22FF">@x</span>)<span style="color: #666666">/</span>n
cov_yy <span style="color: #666666">=</span> np<span style="color: #666666">.</span>sum(y<span style="color: #AA22FF">@y</span>)<span style="color: #666666">/</span>n
C <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros((<span style="color: #666666">2</span>,<span style="color: #666666">2</span>))
C[<span style="color: #666666">0</span>,<span style="color: #666666">0</span>]<span style="color: #666666">=</span> cov_xx<span style="color: #666666">/</span>variance_x
C[<span style="color: #666666">1</span>,<span style="color: #666666">1</span>]<span style="color: #666666">=</span> cov_yy<span style="color: #666666">/</span>variance_y
C[<span style="color: #666666">0</span>,<span style="color: #666666">1</span>]<span style="color: #666666">=</span> cov_xy<span style="color: #666666">/</span>np<span style="color: #666666">.</span>sqrt(variance_y<span style="color: #666666">*</span>variance_x)
C[<span style="color: #666666">1</span>,<span style="color: #666666">0</span>]<span style="color: #666666">=</span> C[<span style="color: #666666">0</span>,<span style="color: #666666">1</span>]
<span style="color: #008000; font-weight: bold">print</span>(C)
</pre></div>
<p>
We see that the matrix elements along the diagonal are one as they
should be and that the matrix is symmetric. Furthermore, diagonalizing
this matrix we easily see that it is a positive definite matrix.
<p>
The above procedure with <b>numpy</b> can be made more compact if we use <b>pandas</b>.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec11">Prof of the PCA Theorem </h2>
<h2 id="___sec12">Correlation Matrix with Pandas </h2>
<p>
We whow here how we can set up the correlation matrix using <b>pandas</b>, as done in this simple code
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</span>
n <span style="color: #666666">=</span> <span style="color: #666666">10</span>
x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>normal(size<span style="color: #666666">=</span>n)
x <span style="color: #666666">=</span> x <span style="color: #666666">-</span> np<span style="color: #666666">.</span>mean(x)
y <span style="color: #666666">=</span> <span style="color: #666666">4+3*</span>x<span style="color: #666666">+</span>np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>normal(size<span style="color: #666666">=</span>n)
y <span style="color: #666666">=</span> y <span style="color: #666666">-</span> np<span style="color: #666666">.</span>mean(y)
X <span style="color: #666666">=</span> (np<span style="color: #666666">.</span>vstack((x, y)))<span style="color: #666666">.</span>T
<span style="color: #008000; font-weight: bold">print</span>(X)
Xpd <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>DataFrame(X)
<span style="color: #008000; font-weight: bold">print</span>(Xpd)
correlation_matrix <span style="color: #666666">=</span> Xpd<span style="color: #666666">.</span>corr()
<span style="color: #008000; font-weight: bold">print</span>(correlation_matrix)
</pre></div>
<p>
We expand this model to the Franke function discussed above.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec12">Getting started with PCA </h2>
<h2 id="___sec13">Correlation Matrix with Pandas and the Franke function </h2>
<p>
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span><span style="color: #408080; font-style: italic"># Common imports</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">pandas</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">pd</span>
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">FrankeFunction</span>(x,y):
term1 <span style="color: #666666">=</span> <span style="color: #666666">0.75*</span>np<span style="color: #666666">.</span>exp(<span style="color: #666666">-</span>(<span style="color: #666666">0.25*</span>(<span style="color: #666666">9*</span>x<span style="color: #666666">-2</span>)<span style="color: #666666">**2</span>) <span style="color: #666666">-</span> <span style="color: #666666">0.25*</span>((<span style="color: #666666">9*</span>y<span style="color: #666666">-2</span>)<span style="color: #666666">**2</span>))
term2 <span style="color: #666666">=</span> <span style="color: #666666">0.75*</span>np<span style="color: #666666">.</span>exp(<span style="color: #666666">-</span>((<span style="color: #666666">9*</span>x<span style="color: #666666">+1</span>)<span style="color: #666666">**2</span>)<span style="color: #666666">/49.0</span> <span style="color: #666666">-</span> <span style="color: #666666">0.1*</span>(<span style="color: #666666">9*</span>y<span style="color: #666666">+1</span>))
term3 <span style="color: #666666">=</span> <span style="color: #666666">0.5*</span>np<span style="color: #666666">.</span>exp(<span style="color: #666666">-</span>(<span style="color: #666666">9*</span>x<span style="color: #666666">-7</span>)<span style="color: #666666">**2/4.0</span> <span style="color: #666666">-</span> <span style="color: #666666">0.25*</span>((<span style="color: #666666">9*</span>y<span style="color: #666666">-3</span>)<span style="color: #666666">**2</span>))
term4 <span style="color: #666666">=</span> <span style="color: #666666">-0.2*</span>np<span style="color: #666666">.</span>exp(<span style="color: #666666">-</span>(<span style="color: #666666">9*</span>x<span style="color: #666666">-4</span>)<span style="color: #666666">**2</span> <span style="color: #666666">-</span> (<span style="color: #666666">9*</span>y<span style="color: #666666">-7</span>)<span style="color: #666666">**2</span>)
<span style="color: #008000; font-weight: bold">return</span> term1 <span style="color: #666666">+</span> term2 <span style="color: #666666">+</span> term3 <span style="color: #666666">+</span> term4
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">create_X</span>(x, y, n ):
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #008000">len</span>(x<span style="color: #666666">.</span>shape) <span style="color: #666666">&gt;</span> <span style="color: #666666">1</span>:
x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>ravel(x)
y <span style="color: #666666">=</span> np<span style="color: #666666">.</span>ravel(y)
N <span style="color: #666666">=</span> <span style="color: #008000">len</span>(x)
l <span style="color: #666666">=</span> <span style="color: #008000">int</span>((n<span style="color: #666666">+1</span>)<span style="color: #666666">*</span>(n<span style="color: #666666">+2</span>)<span style="color: #666666">/2</span>) <span style="color: #408080; font-style: italic"># Number of elements in beta</span>
X <span style="color: #666666">=</span> np<span style="color: #666666">.</span>ones((N,l))
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #666666">1</span>,n<span style="color: #666666">+1</span>):
q <span style="color: #666666">=</span> <span style="color: #008000">int</span>((i)<span style="color: #666666">*</span>(i<span style="color: #666666">+1</span>)<span style="color: #666666">/2</span>)
<span style="color: #008000; font-weight: bold">for</span> k <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(i<span style="color: #666666">+1</span>):
X[:,q<span style="color: #666666">+</span>k] <span style="color: #666666">=</span> (x<span style="color: #666666">**</span>(i<span style="color: #666666">-</span>k))<span style="color: #666666">*</span>(y<span style="color: #666666">**</span>k)
<span style="color: #008000; font-weight: bold">return</span> X
<span style="color: #408080; font-style: italic"># Making meshgrid of datapoints and compute Franke&#39;s function</span>
n <span style="color: #666666">=</span> <span style="color: #666666">4</span>
N <span style="color: #666666">=</span> <span style="color: #666666">100</span>
x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>sort(np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>uniform(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, N))
y <span style="color: #666666">=</span> np<span style="color: #666666">.</span>sort(np<span style="color: #666666">.</span>random<span style="color: #666666">.</span>uniform(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, N))
z <span style="color: #666666">=</span> FrankeFunction(x, y)
X <span style="color: #666666">=</span> create_X(x, y, n<span style="color: #666666">=</span>n)
Xpd <span style="color: #666666">=</span> pd<span style="color: #666666">.</span>DataFrame(X)
<span style="color: #408080; font-style: italic"># subtract the mean values and set up the covariance matrix</span>
Xpd <span style="color: #666666">=</span> Xpd <span style="color: #666666">-</span> Xpd<span style="color: #666666">.</span>mean()
covariance_matrix <span style="color: #666666">=</span> Xpd<span style="color: #666666">.</span>cov()
<span style="color: #008000; font-weight: bold">print</span>(covariance_matrix)
</pre></div>
<p>
We note here that the covariance is zero for the first rows and
columns since all matrix elements in the design matrix were set to one
(we are fitting the function in terms of a polynomial of degree \( n \)).
<p>
This means that the variance for these elements will be zero and will
cause problems when we set up the correlation matrix. We can simply
drop these elements as follows and then construct the correlation
matrix.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec14">Classical PCA Theorem </h2>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec15">Prof of the PCA Theorem </h2>
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec16">Getting started with PCA </h2>
<p>
@@ -699,7 +845,7 @@ X_pca <span style="color: #666666">=</span> pca<span style="color: #666666">.</s
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec13">Principal Component Analysis </h2>
<h2 id="___sec17">Principal Component Analysis </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -735,7 +881,7 @@ X2D <span style="color: #666666">=</span> X_centered<span style="color: #666666"
<p>
<!-- !split -->
<h2 id="___sec14">PCA and scikit-learn </h2>
<h2 id="___sec18">PCA and scikit-learn </h2>
<p>
Scikit-Learn&#8217;s PCA class implements PCA using SVD decomposition just like we did before. The
@@ -766,7 +912,7 @@ More material to come here.
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec15">More on the PCA </h2>
<h2 id="___sec19">More on the PCA </h2>
<p>
Instead of arbitrarily choosing the number of dimensions to reduce down to, it is generally preferable to
@@ -796,7 +942,7 @@ X_reduced <span style="color: #666666">=</span> pca<span style="color: #666666">
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec16">Incremental PCA </h2>
<h2 id="___sec20">Incremental PCA </h2>
<p>
One problem with the preceding implementation of PCA is that it requires the whole training set to fit in
@@ -808,7 +954,7 @@ instances arrive).
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec17">Randomized PCA </h2>
<h2 id="___sec21">Randomized PCA </h2>
<p>
Scikit-Learn offers yet another option to perform PCA, called Randomized PCA. This is a stochastic
@@ -823,7 +969,7 @@ previous algorithms when \( d \) is much smaller than \( n \).
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec18">Kernel PCA </h2>
<h2 id="___sec22">Kernel PCA </h2>
<div class="alert alert-block alert-block alert-text-normal">
<b></b>
<p>
@@ -852,7 +998,7 @@ X_reduced <span style="color: #666666">=</span> rbf_pca<span style="color: #6666
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec19">LLE </h2>
<h2 id="___sec23">LLE </h2>
<p>
Locally Linear Embedding (LLE) is another very powerful nonlinear dimensionality reduction
@@ -864,7 +1010,7 @@ these local relationships are best preserved (more details shortly).
<p>
<!-- !split --><br><br><br><br><br><br><br><br><br><br>
<h2 id="___sec20">Other techniques </h2>
<h2 id="___sec24">Other techniques </h2>
<p>
There are many other dimensionality reduction techniques, several of which are available in Scikit-Learn.
+183 -27
View File
@@ -412,7 +412,7 @@
"## Introducing the Covariance and Correlation functions\n",
"\n",
"Suppose we have defined two vectors\n",
"$\\hat{x} and \\hat{y} with $n$ elements each. The covariance matrix $\\boldsymbol{C}is defined as"
"$\\hat{x}$ and $\\hat{y}$ with $n$ elements each. The covariance matrix $\\boldsymbol{C}$ is defined as"
]
},
{
@@ -492,7 +492,7 @@
"metadata": {},
"source": [
"$$\n",
"corr[\\boldsymbol{x},\\boldsymbol{y}]=\\frac{cov[\\boldsymbol{x},\\boldsymbol{y}]}{\\sqrt{var[\\boldsymbol{x}]\\var\\boldsymbol{y}]}}.\n",
"corr[\\boldsymbol{x},\\boldsymbol{y}]=\\frac{cov[\\boldsymbol{x},\\boldsymbol{y}]}{\\sqrt{var[\\boldsymbol{x}]\\var[\\boldsymbol{y}]}}.\n",
"$$"
]
},
@@ -628,8 +628,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The Numpy function **np.cov** calculates the covariance elements using the factor $1/(n-1)$ instead of $1/n$ since it assumes we do not have the exact mean values. \n",
"The following simple function uses the **np.vstack** function which takes each vector of dimension $1\\times n$ and produces a $2\\times n$ matrix $\\hat{W}$"
"## Covariance Matrix Examples\n",
"\n",
"\n",
"The Numpy function **np.cov** calculates the covariance elements using\n",
"the factor $1/(n-1)$ instead of $1/n$ since it assumes we do not have\n",
"the exact mean values. The following simple function uses the\n",
"**np.vstack** function which takes each vector of dimension $1\\times n$\n",
"and produces a $2\\times n$ matrix $\\boldsymbol{W}$"
]
},
{
@@ -637,7 +643,7 @@
"metadata": {},
"source": [
"$$\n",
"\\hat{W} = \\begin{bmatrix} x_0 & y_0 \\\\\n",
"\\boldsymbol{W} = \\begin{bmatrix} x_0 & y_0 \\\\\n",
" x_1 & y_1 \\\\\n",
" x_2 & y_2\\\\\n",
" \\dots & \\dots \\\\\n",
@@ -651,9 +657,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"which in turn is converted into into the $3\\times 3$ covariance matrix\n",
"$\\hat{\\Sigma}$ via the Numpy function **np.cov()**. We note that we can also calculate\n",
"the mean value of each set of samples $\\hat{x}$ etc using the Numpy\n",
"which in turn is converted into into the $2\\times 2$ covariance matrix\n",
"$\\boldsymbol{C}$ via the Numpy function **np.cov()**. We note that we can also calculate\n",
"the mean value of each set of samples $\\boldsymbol{x}$ etc using the Numpy\n",
"function **np.mean(x)**. We can also extract the eigenvalues of the\n",
"covariance matrix through the **np.linalg.eig()** function."
]
@@ -668,25 +674,175 @@
"source": [
"# Importing various packages\n",
"import numpy as np\n",
"\n",
"n = 100\n",
"x = np.random.normal(size=n)\n",
"print(np.mean(x))\n",
"y = 4+3*x+np.random.normal(size=n)\n",
"print(np.mean(y))\n",
"z = x**3+np.random.normal(size=n)\n",
"print(np.mean(z))\n",
"W = np.vstack((x, y, z))\n",
"Sigma = np.cov(W)\n",
"print(Sigma)\n",
"Eigvals, Eigvecs = np.linalg.eig(Sigma)\n",
"print(Eigvals)"
"W = np.vstack((x, y))\n",
"C = np.cov(W)\n",
"print(C)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Correlation Matrix\n",
"\n",
"The previous example can be converted into the correlation matrix by\n",
"simply scaling the matrix elements with the variances. We should also\n",
"subtract the mean values for each column. This leads to the following\n",
"code which sets up the correlations matrix for the previous example in\n",
"a more brute force way. Here we scale the mean values for each column of the design matrix, calculate the relevant mean values and variances and then finally set up the $2\\times 2$ correlation matrix (since we have only two vectors)."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"n = 100\n",
"# define two vectors \n",
"x = np.random.random(size=n)\n",
"y = 4+3*x+np.random.normal(size=n)\n",
"#scaling the x and y vectors \n",
"x = x - np.mean(x)\n",
"y = y - np.mean(y)\n",
"variance_x = np.sum(x@x)/n\n",
"variance_y = np.sum(y@y)/n\n",
"print(variance_x)\n",
"print(variance_y)\n",
"cov_xy = np.sum(x@y)/n\n",
"cov_xx = np.sum(x@x)/n\n",
"cov_yy = np.sum(y@y)/n\n",
"C = np.zeros((2,2))\n",
"C[0,0]= cov_xx/variance_x\n",
"C[1,1]= cov_yy/variance_y\n",
"C[0,1]= cov_xy/np.sqrt(variance_y*variance_x)\n",
"C[1,0]= C[0,1]\n",
"print(C)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We see that the matrix elements along the diagonal are one as they\n",
"should be and that the matrix is symmetric. Furthermore, diagonalizing\n",
"this matrix we easily see that it is a positive definite matrix.\n",
"\n",
"The above procedure with **numpy** can be made more compact if we use **pandas**.\n",
"\n",
"## Correlation Matrix with Pandas\n",
"\n",
"We whow here how we can set up the correlation matrix using **pandas**, as done in this simple code"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"n = 10\n",
"x = np.random.normal(size=n)\n",
"x = x - np.mean(x)\n",
"y = 4+3*x+np.random.normal(size=n)\n",
"y = y - np.mean(y)\n",
"X = (np.vstack((x, y))).T\n",
"print(X)\n",
"Xpd = pd.DataFrame(X)\n",
"print(Xpd)\n",
"correlation_matrix = Xpd.corr()\n",
"print(correlation_matrix)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We expand this model to the Franke function discussed above.\n",
"\n",
"## Correlation Matrix with Pandas and the Franke function"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# Common imports\n",
"import numpy as np\n",
"import pandas as pd\n",
"\n",
"\n",
"def FrankeFunction(x,y):\n",
"\tterm1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2))\n",
"\tterm2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1))\n",
"\tterm3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2))\n",
"\tterm4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2)\n",
"\treturn term1 + term2 + term3 + term4\n",
"\n",
"\n",
"def create_X(x, y, n ):\n",
"\tif len(x.shape) > 1:\n",
"\t\tx = np.ravel(x)\n",
"\t\ty = np.ravel(y)\n",
"\n",
"\tN = len(x)\n",
"\tl = int((n+1)*(n+2)/2)\t\t# Number of elements in beta\n",
"\tX = np.ones((N,l))\n",
"\n",
"\tfor i in range(1,n+1):\n",
"\t\tq = int((i)*(i+1)/2)\n",
"\t\tfor k in range(i+1):\n",
"\t\t\tX[:,q+k] = (x**(i-k))*(y**k)\n",
"\n",
"\treturn X\n",
"\n",
"\n",
"# Making meshgrid of datapoints and compute Franke's function\n",
"n = 4\n",
"N = 100\n",
"x = np.sort(np.random.uniform(0, 1, N))\n",
"y = np.sort(np.random.uniform(0, 1, N))\n",
"z = FrankeFunction(x, y)\n",
"X = create_X(x, y, n=n) \n",
"\n",
"Xpd = pd.DataFrame(X)\n",
"# subtract the mean values and set up the covariance matrix\n",
"Xpd = Xpd - Xpd.mean()\n",
"covariance_matrix = Xpd.cov()\n",
"print(covariance_matrix)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We note here that the covariance is zero for the first rows and\n",
"columns since all matrix elements in the design matrix were set to one\n",
"(we are fitting the function in terms of a polynomial of degree $n$).\n",
"\n",
"This means that the variance for these elements will be zero and will\n",
"cause problems when we set up the correlation matrix. We can simply\n",
"drop these elements as follows and then construct the correlation\n",
"matrix. \n",
"\n",
"\n",
"\n",
"## Classical PCA Theorem\n",
"\n",
"\n",
@@ -702,7 +858,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 11,
"metadata": {
"collapsed": false
},
@@ -730,7 +886,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 12,
"metadata": {
"collapsed": false
},
@@ -757,7 +913,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 13,
"metadata": {
"collapsed": false
},
@@ -781,7 +937,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 14,
"metadata": {
"collapsed": false
},
@@ -803,7 +959,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 15,
"metadata": {
"collapsed": false
},
@@ -833,7 +989,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 16,
"metadata": {
"collapsed": false
},
@@ -856,7 +1012,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 17,
"metadata": {
"collapsed": false
},
@@ -903,7 +1059,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 18,
"metadata": {
"collapsed": false
},
@@ -948,7 +1104,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 19,
"metadata": {
"collapsed": false
},
@@ -978,7 +1134,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 20,
"metadata": {
"collapsed": false
},
@@ -1013,7 +1169,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 21,
"metadata": {
"collapsed": false
},
Binary file not shown.
Binary file not shown.
+136 -16
View File
@@ -341,7 +341,7 @@ We have a data set defined by a design/feature matrix $\bm{X}$ (see below for it
===== Introducing the Covariance and Correlation functions =====
Suppose we have defined two vectors
$\hat{x} and \hat{y} with $n$ elements each. The covariance matrix $\bm{C}is defined as
$\hat{x}$ and $\hat{y}$ with $n$ elements each. The covariance matrix $\bm{C}$ is defined as
!bt
\[
\bm{C}[\bm{x},\bm{y}] = \begin{bmatrix} cov[\bm{x},\bm{x}] & cov[\bm{x},\bm{y}] \\
@@ -378,7 +378,7 @@ correlation function
!bt
\[
corr[\bm{x},\bm{y}]=\frac{cov[\bm{x},\bm{y}]}{\sqrt{var[\bm{x}]\var\bm{y}]}}.
corr[\bm{x},\bm{y}]=\frac{cov[\bm{x},\bm{y}]}{\sqrt{var[\bm{x}]\var[\bm{y}]}}.
\]
!et
@@ -456,14 +456,20 @@ corr[\bm{x}_{p-1},\bm{x}_0] & corr[\bm{x}_{p-1},\bm{x}_1] & corr[\bm{x}_{p-1},
!et
!split
===== Covariance Matrix Examples =====
The Numpy function _np.cov_ calculates the covariance elements using
the factor $1/(n-1)$ instead of $1/n$ since it assumes we do not have
the exact mean values. The following simple function uses the
_np.vstack_ function which takes each vector of dimension $1\times n$
and produces a $2\times n$ matrix $\bm{W}$
The Numpy function _np.cov_ calculates the covariance elements using the factor $1/(n-1)$ instead of $1/n$ since it assumes we do not have the exact mean values.
The following simple function uses the _np.vstack_ function which takes each vector of dimension $1\times n$ and produces a $2\times n$ matrix $\hat{W}$
!bt
\[
\hat{W} = \begin{bmatrix} x_0 & y_0 \\
\bm{W} = \begin{bmatrix} x_0 & y_0 \\
x_1 & y_1 \\
x_2 & y_2\\
\dots & \dots \\
@@ -473,30 +479,144 @@ The following simple function uses the _np.vstack_ function which takes each vec
\]
!et
which in turn is converted into into the $3\times 3$ covariance matrix
$\hat{\Sigma}$ via the Numpy function _np.cov()_. We note that we can also calculate
the mean value of each set of samples $\hat{x}$ etc using the Numpy
which in turn is converted into into the $2\times 2$ covariance matrix
$\bm{C}$ via the Numpy function _np.cov()_. We note that we can also calculate
the mean value of each set of samples $\bm{x}$ etc using the Numpy
function _np.mean(x)_. We can also extract the eigenvalues of the
covariance matrix through the _np.linalg.eig()_ function.
!bc pycod
# Importing various packages
import numpy as np
n = 100
x = np.random.normal(size=n)
print(np.mean(x))
y = 4+3*x+np.random.normal(size=n)
print(np.mean(y))
z = x**3+np.random.normal(size=n)
print(np.mean(z))
W = np.vstack((x, y, z))
Sigma = np.cov(W)
print(Sigma)
Eigvals, Eigvecs = np.linalg.eig(Sigma)
print(Eigvals)
W = np.vstack((x, y))
C = np.cov(W)
print(C)
!ec
!split
===== Correlation Matrix =====
The previous example can be converted into the correlation matrix by
simply scaling the matrix elements with the variances. We should also
subtract the mean values for each column. This leads to the following
code which sets up the correlations matrix for the previous example in
a more brute force way. Here we scale the mean values for each column of the design matrix, calculate the relevant mean values and variances and then finally set up the $2\times 2$ correlation matrix (since we have only two vectors).
!bc pycod
import numpy as np
n = 100
# define two vectors
x = np.random.random(size=n)
y = 4+3*x+np.random.normal(size=n)
#scaling the x and y vectors
x = x - np.mean(x)
y = y - np.mean(y)
variance_x = np.sum(x@x)/n
variance_y = np.sum(y@y)/n
print(variance_x)
print(variance_y)
cov_xy = np.sum(x@y)/n
cov_xx = np.sum(x@x)/n
cov_yy = np.sum(y@y)/n
C = np.zeros((2,2))
C[0,0]= cov_xx/variance_x
C[1,1]= cov_yy/variance_y
C[0,1]= cov_xy/np.sqrt(variance_y*variance_x)
C[1,0]= C[0,1]
print(C)
!ec
We see that the matrix elements along the diagonal are one as they
should be and that the matrix is symmetric. Furthermore, diagonalizing
this matrix we easily see that it is a positive definite matrix.
The above procedure with _numpy_ can be made more compact if we use _pandas_.
!split
===== Correlation Matrix with Pandas =====
We whow here how we can set up the correlation matrix using _pandas_, as done in this simple code
!bc pycod
import numpy as np
import pandas as pd
n = 10
x = np.random.normal(size=n)
x = x - np.mean(x)
y = 4+3*x+np.random.normal(size=n)
y = y - np.mean(y)
X = (np.vstack((x, y))).T
print(X)
Xpd = pd.DataFrame(X)
print(Xpd)
correlation_matrix = Xpd.corr()
print(correlation_matrix)
!ec
We expand this model to the Franke function discussed above.
!split
===== Correlation Matrix with Pandas and the Franke function =====
!bc pycod
# Common imports
import numpy as np
import pandas as pd
def FrankeFunction(x,y):
term1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2))
term2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1))
term3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2))
term4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2)
return term1 + term2 + term3 + term4
def create_X(x, y, n ):
if len(x.shape) > 1:
x = np.ravel(x)
y = np.ravel(y)
N = len(x)
l = int((n+1)*(n+2)/2) # Number of elements in beta
X = np.ones((N,l))
for i in range(1,n+1):
q = int((i)*(i+1)/2)
for k in range(i+1):
X[:,q+k] = (x**(i-k))*(y**k)
return X
# Making meshgrid of datapoints and compute Franke's function
n = 4
N = 100
x = np.sort(np.random.uniform(0, 1, N))
y = np.sort(np.random.uniform(0, 1, N))
z = FrankeFunction(x, y)
X = create_X(x, y, n=n)
Xpd = pd.DataFrame(X)
# subtract the mean values and set up the covariance matrix
Xpd = Xpd - Xpd.mean()
covariance_matrix = Xpd.cov()
print(covariance_matrix)
!ec
We note here that the covariance is zero for the first rows and
columns since all matrix elements in the design matrix were set to one
(we are fitting the function in terms of a polynomial of degree $n$).
This means that the variance for these elements will be zero and will
cause problems when we set up the correlation matrix. We can simply
drop these elements as follows and then construct the correlation
matrix.
+24
View File
@@ -0,0 +1,24 @@
# Importing various packages
import numpy as np
n = 100
# define two vectors
x = np.random.random(size=n)
y = 4+3*x+np.random.normal(size=n)
#scaling the x and y vectors
x = x - np.mean(x)
y = y - np.mean(y)
variance_x = np.sum(x@x)/n
variance_y = np.sum(y@y)/n
print(variance_x)
print(variance_y)
cov_xy = np.sum(x@y)/n
cov_xx = np.sum(x@x)/n
cov_yy = np.sum(y@y)/n
C = np.zeros((2,2))
C[0,0]= cov_xx/variance_x
C[1,1]= cov_yy/variance_y
C[0,1]= cov_xy/np.sqrt(variance_y*variance_x)
C[1,0]= C[0,1]
print(C)
Eigvals, Eigvecs = np.linalg.eig(C)
print(Eigvals)
+43
View File
@@ -0,0 +1,43 @@
# Common imports
import numpy as np
import pandas as pd
def FrankeFunction(x,y):
term1 = 0.75*np.exp(-(0.25*(9*x-2)**2) - 0.25*((9*y-2)**2))
term2 = 0.75*np.exp(-((9*x+1)**2)/49.0 - 0.1*(9*y+1))
term3 = 0.5*np.exp(-(9*x-7)**2/4.0 - 0.25*((9*y-3)**2))
term4 = -0.2*np.exp(-(9*x-4)**2 - (9*y-7)**2)
return term1 + term2 + term3 + term4
def create_X(x, y, n ):
if len(x.shape) > 1:
x = np.ravel(x)
y = np.ravel(y)
N = len(x)
l = int((n+1)*(n+2)/2) # Number of elements in beta
X = np.ones((N,l))
for i in range(1,n+1):
q = int((i)*(i+1)/2)
for k in range(i+1):
X[:,q+k] = (x**(i-k))*(y**k)
return X
# Making meshgrid of datapoints and compute Franke's function
n = 4
N = 1000
x = np.sort(np.random.uniform(0, 1, N))
y = np.sort(np.random.uniform(0, 1, N))
z = FrankeFunction(x, y)
X = create_X(x, y, n=n)
Xpd = pd.DataFrame(X)
Xpd = Xpd - Xpd.mean()
correlation_matrix = Xpd.cov()
print(correlation_matrix)
+28
View File
@@ -0,0 +1,28 @@
# Importing various packages
import numpy as np
n = 10
x = np.random.normal(size=n)
x = x - np.mean(x)
y = 4+3*x+np.random.normal(size=n)
y = y - np.mean(y)
X = (np.vstack((x, y))).T
print(X)
import pandas as pd
Xpd = pd.DataFrame(X)
print(Xpd)
correlation_matrix = Xpd.corr()
print(correlation_matrix)
variance_x = np.sum(x@x)/n
variance_y = np.sum(y@y)/n
cov_xy = np.sum(x@y)/n
cov_xx = np.sum(x@x)/n
cov_yy = np.sum(y@y)/n
C = np.zeros((2,2))
C[0,0]= cov_xx/variance_x
C[1,1]= cov_yy/variance_y
C[0,1]= cov_xy/np.sqrt(variance_y*variance_x)
C[1,0]= C[0,1]
print(C)