tek4

Kernel Methods Trong Machine Learning – Tự Học TensorFlow

by - September. 21, 2021
Kiến thức
<blockquote> <p style="text-align: justify;">Ch&agrave;o mừng c&aacute;c bạn quay trở lại với loạt b&agrave;i&nbsp;<a href="../../tu-hoc-tensorflow-deep-learning-cho-nguoi-moi-bat-dau/" target="_blank" rel="noopener">Tự Học Tensorflow</a>&nbsp;của&nbsp;<a href="../../" target="_blank" rel="noopener">tek4.vn</a>. B&agrave;i viết n&agrave;y sẽ giới thiệu đến c&aacute;c bạn về Kernel Methods trong machine learning v&agrave; v&iacute; dụ về Gaussian Kernel. Bắt đầu th&ocirc;i!</p> </blockquote> <p style="text-align: justify;">Xem th&ecirc;m b&agrave;i viết trước:&nbsp;<a href="../../linear-classifier-voi-tensorflow-tu-hoc-tensorflow/#ftoc-heading-17" target="_blank" rel="noopener">Linear Classifier với Tensorflow &ndash; V&iacute; dụ về binary classification</a></p> <p style="text-align: justify;"><img class="aligncenter size-full wp-image-7366 disappear appear" src="../../wp-content/uploads/2021/01/12.png" sizes="(max-width: 1112px) 100vw, 1112px" srcset="https://old.tek4.vn/wp-content/uploads/2021/01/12.png 1112w, https://old.tek4.vn/wp-content/uploads/2021/01/12-300x156.png 300w, https://old.tek4.vn/wp-content/uploads/2021/01/12-1024x534.png 1024w, https://old.tek4.vn/wp-content/uploads/2021/01/12-768x401.png 768w" alt="Kernel Methods" width="1112" height="580" loading="lazy" /></p> <p style="text-align: justify;">Mục đ&iacute;ch của b&agrave;i n&agrave;y l&agrave; hướng dẫn l&agrave;m cho một tập dữ liệu c&oacute; thể ph&acirc;n t&aacute;ch một c&aacute;ch tuyến t&iacute;nh. B&agrave;i viết được chia l&agrave;m 2 phần:</p> <ol style="text-align: justify;"> <li>Chuyển đổi đặc trưng</li> <li>Đ&agrave;o tạo bộ ph&acirc;n loại Kernel với Tensorflow</li> </ol> <p style="text-align: justify;">Trong phần đầu ti&ecirc;n, ch&uacute;ng ta sẽ hiểu &yacute; tưởng đằng sau bộ ph&acirc;n loại kernel trong khi phần thứ hai, ta sẽ thấy c&aacute;ch đ&agrave;o tạo bộ ph&acirc;n loại kernel với Tensorflow. Ch&uacute;ng ta sẽ sử dụng tập dữ liệu adult dataset. Mục ti&ecirc;u của tập dữ liệu n&agrave;y l&agrave; ph&acirc;n loại doanh thu dưới 50k v&agrave; tr&ecirc;n 50k, biết được h&agrave;nh vi của từng hộ gia đ&igrave;nh.</p> <h3 id="ftoc-heading-1" class="ftwp-heading" style="text-align: justify;">Tại sao cần Kernel Methods?</h3> <p style="text-align: justify;">Mục đ&iacute;ch của mọi bộ ph&acirc;n loại l&agrave; dự đo&aacute;n c&aacute;c lớp một c&aacute;ch ch&iacute;nh x&aacute;c. V&igrave; vậy, tập dữ liệu phải được t&aacute;ch biệt. Nh&igrave;n v&agrave;o h&igrave;nh b&ecirc;n dưới kh&aacute; đơn giản để thấy rằng tất cả c&aacute;c điểm tr&ecirc;n đường m&agrave;u đen thuộc loại thứ nhất v&agrave; c&aacute;c điểm kh&aacute;c thuộc loại thứ hai. Tuy nhi&ecirc;n, rất hiếm khi c&oacute; một bộ dữ liệu đơn giản như vậy. Trong hầu hết c&aacute;c trường hợp, dữ liệu kh&ocirc;ng thể t&aacute;ch rời. N&oacute; mang lại kh&oacute; khăn cho c&aacute;c bộ ph&acirc;n loại như hồi quy logistic.</p> <div id="urvanov-syntax-highlighter-610feb7c8bb7f814475874" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb7f814475874-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb7f814475874-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb7f814475874-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610feb7c8bb7f814475874-1" class="crayon-line"><span class="crayon-e">import </span><span class="crayon-e">numpy </span><span class="crayon-st">as</span> <span class="crayon-e">np</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb7f814475874-2" class="crayon-line crayon-striped-line"><span class="crayon-e">import </span><span class="crayon-v">matplotlib</span><span class="crayon-sy">.</span><span class="crayon-e">pyplot </span><span class="crayon-st">as</span> <span class="crayon-e">plt</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb7f814475874-3" class="crayon-line"><span class="crayon-e">from </span><span class="crayon-v">mpl_toolkits</span><span class="crayon-sy">.</span><span class="crayon-e">mplot3d </span><span class="crayon-e">import </span><span class="crayon-v">Axes3D</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610feb7c8bb8a555426026" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8a555426026-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8a555426026-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8a555426026-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8a555426026-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8a555426026-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8a555426026-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8a555426026-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8a555426026-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8a555426026-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8a555426026-10">10</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610feb7c8bb8a555426026-1" class="crayon-line"><span class="crayon-v">x_lin</span> <span class="crayon-o">=</span> <span class="crayon-v">np</span><span class="crayon-sy">.</span><span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span><span class="crayon-cn">2</span><span class="crayon-sy">,</span><span class="crayon-cn">3</span><span class="crayon-sy">,</span><span class="crayon-cn">4</span><span class="crayon-sy">,</span><span class="crayon-cn">5</span><span class="crayon-sy">,</span><span class="crayon-cn">6</span><span class="crayon-sy">,</span><span class="crayon-cn">7</span><span class="crayon-sy">,</span><span class="crayon-cn">8</span><span class="crayon-sy">,</span><span class="crayon-cn">9</span><span class="crayon-sy">,</span><span class="crayon-cn">10</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb8a555426026-2" class="crayon-line crayon-striped-line"><span class="crayon-v">y_lin</span> <span class="crayon-o">=</span> <span class="crayon-v">np</span><span class="crayon-sy">.</span><span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">2</span><span class="crayon-sy">,</span><span class="crayon-cn">2</span><span class="crayon-sy">,</span><span class="crayon-cn">3</span><span class="crayon-sy">,</span><span class="crayon-cn">2</span><span class="crayon-sy">,</span><span class="crayon-cn">2</span><span class="crayon-sy">,</span><span class="crayon-cn">9</span><span class="crayon-sy">,</span><span class="crayon-cn">6</span><span class="crayon-sy">,</span><span class="crayon-cn">8</span><span class="crayon-sy">,</span><span class="crayon-cn">8</span><span class="crayon-sy">,</span><span class="crayon-cn">9</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb8a555426026-3" class="crayon-line"><span class="crayon-v">label_lin</span> <span class="crayon-o">=</span> <span class="crayon-v">np</span><span class="crayon-sy">.</span><span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb8a555426026-4" class="crayon-line crayon-striped-line"></div> <div id="urvanov-syntax-highlighter-610feb7c8bb8a555426026-5" class="crayon-line"><span class="crayon-v">fig</span> <span class="crayon-o">=</span> <span class="crayon-v">plt</span><span class="crayon-sy">.</span><span class="crayon-e">figure</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb8a555426026-6" class="crayon-line crayon-striped-line"><span class="crayon-v">ax</span><span class="crayon-o">=</span><span class="crayon-v">fig</span><span class="crayon-sy">.</span><span class="crayon-e">add_subplot</span><span class="crayon-sy">(</span><span class="crayon-cn">111</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb8a555426026-7" class="crayon-line"><span class="crayon-v">plt</span><span class="crayon-sy">.</span><span class="crayon-e">scatter</span><span class="crayon-sy">(</span><span class="crayon-v">x_lin</span><span class="crayon-sy">,</span> <span class="crayon-v">y_lin</span><span class="crayon-sy">,</span> <span class="crayon-v">c</span><span class="crayon-o">=</span><span class="crayon-v">label_lin</span><span class="crayon-sy">,</span> <span class="crayon-v">s</span><span class="crayon-o">=</span><span class="crayon-cn">60</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb8a555426026-8" class="crayon-line crayon-striped-line"><span class="crayon-v">plt</span><span class="crayon-sy">.</span><span class="crayon-e">plot</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-o">-</span><span class="crayon-cn">2.5</span><span class="crayon-sy">,</span> <span class="crayon-cn">10</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-sy">[</span><span class="crayon-cn">12.5</span><span class="crayon-sy">,</span> <span class="crayon-o">-</span><span class="crayon-cn">2.5</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-s">'k-'</span><span class="crayon-sy">,</span> <span class="crayon-v">lw</span><span class="crayon-o">=</span><span class="crayon-cn">2</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb8a555426026-9" class="crayon-line"><span class="crayon-v">ax</span><span class="crayon-sy">.</span><span class="crayon-e">set_xlim</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-o">-</span><span class="crayon-cn">5</span><span class="crayon-sy">,</span><span class="crayon-cn">15</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb8a555426026-10" class="crayon-line crayon-striped-line"><span class="crayon-v">ax</span><span class="crayon-sy">.</span><span class="crayon-e">set_ylim</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-o">-</span><span class="crayon-cn">5</span><span class="crayon-sy">,</span><span class="crayon-cn">15</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span><span class="crayon-v">plt</span><span class="crayon-sy">.</span><span class="crayon-e">show</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><img class="aligncenter disappear appear" src="https://www.guru99.com/images/tensorflow/082918_0458_KernelMetho1.png" /></p> <p style="text-align: justify;">Trong h&igrave;nh b&ecirc;n dưới, ch&uacute;ng ta vẽ một tập dữ liệu kh&ocirc;ng thể ph&acirc;n t&aacute;ch tuyến t&iacute;nh. Nếu ch&uacute;ng ta vẽ một đường thẳng, hầu hết c&aacute;c điểm sẽ kh&ocirc;ng được xếp v&agrave;o lớp ch&iacute;nh x&aacute;c.</p> <p style="text-align: justify;">Một c&aacute;ch để giải quyết vấn đề n&agrave;y l&agrave; lấy tập dữ liệu v&agrave; chuyển đổi dữ liệu trong một bản đồ đặc trưng kh&aacute;c. N&oacute; c&oacute; nghĩa l&agrave;, bạn sẽ sử dụng một h&agrave;m để chuyển đổi dữ liệu trong một kế hoạch kh&aacute;c, n&oacute; phải c&oacute; dạng tuyến t&iacute;nh.</p> <div id="urvanov-syntax-highlighter-610feb7c8bb8d703031922" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8d703031922-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8d703031922-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8d703031922-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610feb7c8bb8d703031922-1" class="crayon-line"><span class="crayon-v">x</span> <span class="crayon-o">=</span> <span class="crayon-v">np</span><span class="crayon-sy">.</span><span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span><span class="crayon-cn">2</span><span class="crayon-sy">,</span><span class="crayon-cn">3</span><span class="crayon-sy">,</span><span class="crayon-cn">3</span><span class="crayon-sy">,</span><span class="crayon-cn">6</span><span class="crayon-sy">,</span><span class="crayon-cn">6</span><span class="crayon-sy">,</span><span class="crayon-cn">6</span><span class="crayon-sy">,</span><span class="crayon-cn">9</span><span class="crayon-sy">,</span><span class="crayon-cn">9</span><span class="crayon-sy">,</span><span class="crayon-cn">10</span><span class="crayon-sy">,</span><span class="crayon-cn">11</span><span class="crayon-sy">,</span><span class="crayon-cn">12</span><span class="crayon-sy">,</span><span class="crayon-cn">13</span><span class="crayon-sy">,</span><span class="crayon-cn">16</span><span class="crayon-sy">,</span><span class="crayon-cn">18</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb8d703031922-2" class="crayon-line crayon-striped-line"><span class="crayon-v">y</span> <span class="crayon-o">=</span> <span class="crayon-v">np</span><span class="crayon-sy">.</span><span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">18</span><span class="crayon-sy">,</span><span class="crayon-cn">13</span><span class="crayon-sy">,</span><span class="crayon-cn">9</span><span class="crayon-sy">,</span><span class="crayon-cn">6</span><span class="crayon-sy">,</span><span class="crayon-cn">15</span><span class="crayon-sy">,</span><span class="crayon-cn">11</span><span class="crayon-sy">,</span><span class="crayon-cn">6</span><span class="crayon-sy">,</span><span class="crayon-cn">3</span><span class="crayon-sy">,</span><span class="crayon-cn">5</span><span class="crayon-sy">,</span><span class="crayon-cn">2</span><span class="crayon-sy">,</span><span class="crayon-cn">10</span><span class="crayon-sy">,</span><span class="crayon-cn">5</span><span class="crayon-sy">,</span><span class="crayon-cn">6</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span><span class="crayon-cn">3</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb8d703031922-3" class="crayon-line"><span class="crayon-v">label</span> <span class="crayon-o">=</span> <span class="crayon-v">np</span><span class="crayon-sy">.</span><span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610feb7c8bb8f854061833" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8f854061833-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8f854061833-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb8f854061833-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610feb7c8bb8f854061833-1" class="crayon-line"><span class="crayon-v">fig</span> <span class="crayon-o">=</span> <span class="crayon-v">plt</span><span class="crayon-sy">.</span><span class="crayon-e">figure</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb8f854061833-2" class="crayon-line crayon-striped-line"><span class="crayon-v">plt</span><span class="crayon-sy">.</span><span class="crayon-e">scatter</span><span class="crayon-sy">(</span><span class="crayon-v">x</span><span class="crayon-sy">,</span> <span class="crayon-v">y</span><span class="crayon-sy">,</span> <span class="crayon-v">c</span><span class="crayon-o">=</span><span class="crayon-v">label</span><span class="crayon-sy">,</span> <span class="crayon-v">s</span><span class="crayon-o">=</span><span class="crayon-cn">60</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb8f854061833-3" class="crayon-line"><span class="crayon-v">plt</span><span class="crayon-sy">.</span><span class="crayon-e">show</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><img class="aligncenter size-full wp-image-7949 disappear appear" src="../../wp-content/uploads/2021/01/082918_0458_KernelMetho2.png" sizes="(max-width: 509px) 100vw, 509px" srcset="https://old.tek4.vn/wp-content/uploads/2021/01/082918_0458_KernelMetho2.png 509w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_0458_KernelMetho2-300x198.png 300w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_0458_KernelMetho2-90x60.png 90w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_0458_KernelMetho2-180x120.png 180w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_0458_KernelMetho2-95x64.png 95w" alt="" width="509" height="336" loading="lazy" /></p> <p style="text-align: justify;">Dữ liệu từ h&igrave;nh tr&ecirc;n nằm trong sơ đồ 2D Gaussian Kernel kh&ocirc;ng thể t&aacute;ch rời.Bạn c&oacute; thể cố gắng biến đổi những dữ liệu n&agrave;y theo kh&ocirc;ng gian ba chiều, nghĩa l&agrave; bạn tạo một figure c&oacute; 3 axes.</p> <p style="text-align: justify;">Trong v&iacute; dụ về Gaussian Kernel, ch&uacute;ng ta sẽ &aacute;p dụng &aacute;nh xạ đa thức để đưa dữ liệu sang một chiều 3D. C&ocirc;ng thức để chuyển đổi dữ liệu như sau.</p> <p style="text-align: justify;"><span id="MathJax-Element-1-Frame" class="MathJax" tabindex="0"><span id="MathJax-Span-1" class="math"><span id="MathJax-Span-2" class="mrow"><span id="MathJax-Span-3" class="mi">ϕ</span><span id="MathJax-Span-4" class="mo">(</span><span id="MathJax-Span-5" class="mi">x</span><span id="MathJax-Span-6" class="mo">,</span><span id="MathJax-Span-7" class="mi">y</span><span id="MathJax-Span-8" class="mo">)</span><span id="MathJax-Span-9" class="mo">=</span><span id="MathJax-Span-10" class="mo">(</span><span id="MathJax-Span-11" class="msubsup"><span id="MathJax-Span-12" class="mi">x</span><span id="MathJax-Span-13" class="mn">2</span></span><span id="MathJax-Span-14" class="mo">,</span><span id="MathJax-Span-15" class="msqrt"><span id="MathJax-Span-16" class="mrow"><span id="MathJax-Span-17" class="mo">(</span><span id="MathJax-Span-18" class="mn">2</span><span id="MathJax-Span-19" class="mo">)</span></span>&minus;&minus;&minus;&radic;</span><span id="MathJax-Span-20" class="mi">x</span><span id="MathJax-Span-21" class="mi">y</span><span id="MathJax-Span-22" class="mo">,</span><span id="MathJax-Span-23" class="msubsup"><span id="MathJax-Span-24" class="mi">y</span><span id="MathJax-Span-25" class="mn">2</span></span><span id="MathJax-Span-26" class="mo">)</span></span></span></span></p> <p style="text-align: justify;">H&atilde;y định nghĩa một h&agrave;m trong Gaussian Kernel Python để tạo c&aacute;c bản đồ đặc trưng mới.</p> <p style="text-align: justify;">C&oacute; thể sử dụng numpy để viết code cho c&ocirc;ng thức tr&ecirc;n.</p> <table class="table table-striped aligncenter"> <tbody> <tr> <th>Formula</th> <th>Equivalent Numpy Code</th> </tr> <tr> <td>x</td> <td>x[:,0]**</td> </tr> <tr> <td>y</td> <td>x[:,1]</td> </tr> <tr> <td><span id="MathJax-Element-2-Frame" class="MathJax" tabindex="0"><span id="MathJax-Span-27" class="math"><span id="MathJax-Span-28" class="mrow"><span id="MathJax-Span-29" class="msubsup"><span id="MathJax-Span-30" class="mi">x</span><span id="MathJax-Span-31" class="mn">2</span></span></span></span></span></td> <td>x[:,0]**2</td> </tr> <tr> <td><span id="MathJax-Element-3-Frame" class="MathJax" tabindex="0"><span id="MathJax-Span-32" class="math"><span id="MathJax-Span-33" class="mrow"><span id="MathJax-Span-34" class="msqrt"><span id="MathJax-Span-35" class="mrow"><span id="MathJax-Span-36" class="mo">(</span><span id="MathJax-Span-37" class="mn">2</span><span id="MathJax-Span-38" class="mo">)</span></span>&minus;&minus;&minus;&radic;</span></span></span></span></td> <td>np.sqrt(2)*</td> </tr> <tr> <td>xy</td> <td>x[:,0]*x[:,1]</td> </tr> <tr> <td><span id="MathJax-Element-4-Frame" class="MathJax" tabindex="0"><span id="MathJax-Span-39" class="math"><span id="MathJax-Span-40" class="mrow"><span id="MathJax-Span-41" class="msubsup"><span id="MathJax-Span-42" class="mi">y</span><span id="MathJax-Span-43" class="mn">2</span></span></span></span></span></td> <td>x[:,1]**2</td> </tr> </tbody> </table> <div id="urvanov-syntax-highlighter-610feb7c8bb92419920020" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb92419920020-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb92419920020-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb92419920020-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb92419920020-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb92419920020-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb92419920020-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb92419920020-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb92419920020-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb92419920020-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb92419920020-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb92419920020-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb92419920020-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb92419920020-13">13</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610feb7c8bb92419920020-1" class="crayon-line"><span class="crayon-p">### illustration purpose</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb92419920020-2" class="crayon-line crayon-striped-line"><span class="crayon-e">def </span><span class="crayon-e">mapping</span><span class="crayon-sy">(</span><span class="crayon-v">x</span><span class="crayon-sy">,</span> <span class="crayon-v">y</span><span class="crayon-sy">)</span><span class="crayon-o">:</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb92419920020-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">x</span> <span class="crayon-o">=</span> <span class="crayon-v">np</span><span class="crayon-sy">.</span><span class="crayon-v">c_</span><span class="crayon-sy">[</span><span class="crayon-sy">(</span><span class="crayon-v">x</span><span class="crayon-sy">,</span> <span class="crayon-v">y</span><span class="crayon-sy">)</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb92419920020-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">if</span> <span class="crayon-e">len</span><span class="crayon-sy">(</span><span class="crayon-v">x</span><span class="crayon-sy">)</span> <span class="crayon-o">&amp;</span><span class="crayon-v">gt</span><span class="crayon-sy">;</span> <span class="crayon-cn">2</span><span class="crayon-o">:</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb92419920020-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">x_1</span> <span class="crayon-o">=</span> <span class="crayon-v">x</span><span class="crayon-sy">[</span><span class="crayon-o">:</span><span class="crayon-sy">,</span><span class="crayon-cn">0</span><span class="crayon-sy">]</span><span class="crayon-o">*</span><span class="crayon-o">*</span><span class="crayon-cn">2</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb92419920020-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">x_2</span> <span class="crayon-o">=</span> <span class="crayon-v">np</span><span class="crayon-sy">.</span><span class="crayon-e">sqrt</span><span class="crayon-sy">(</span><span class="crayon-cn">2</span><span class="crayon-sy">)</span><span class="crayon-o">*</span><span class="crayon-v">x</span><span class="crayon-sy">[</span><span class="crayon-o">:</span><span class="crayon-sy">,</span><span class="crayon-cn">0</span><span class="crayon-sy">]</span><span class="crayon-o">*</span><span class="crayon-v">x</span><span class="crayon-sy">[</span><span class="crayon-o">:</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">]</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb92419920020-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">x_3</span> <span class="crayon-o">=</span> <span class="crayon-v">x</span><span class="crayon-sy">[</span><span class="crayon-o">:</span><span class="crayon-sy">,</span><span class="crayon-cn">1</span><span class="crayon-sy">]</span><span class="crayon-o">*</span><span class="crayon-o">*</span><span class="crayon-cn">2</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb92419920020-8" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">else</span><span class="crayon-o">:</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb92419920020-9" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">x_1</span> <span class="crayon-o">=</span> <span class="crayon-v">x</span><span class="crayon-sy">[</span><span class="crayon-cn">0</span><span class="crayon-sy">]</span><span class="crayon-o">*</span><span class="crayon-o">*</span><span class="crayon-cn">2</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb92419920020-10" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">x_2</span> <span class="crayon-o">=</span> <span class="crayon-v">np</span><span class="crayon-sy">.</span><span class="crayon-e">sqrt</span><span class="crayon-sy">(</span><span class="crayon-cn">2</span><span class="crayon-sy">)</span><span class="crayon-o">*</span><span class="crayon-v">x</span><span class="crayon-sy">[</span><span class="crayon-cn">0</span><span class="crayon-sy">]</span><span class="crayon-o">*</span><span class="crayon-v">x</span><span class="crayon-sy">[</span><span class="crayon-cn">1</span><span class="crayon-sy">]</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb92419920020-11" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">x_3</span> <span class="crayon-o">=</span> <span class="crayon-v">x</span><span class="crayon-sy">[</span><span class="crayon-cn">1</span><span class="crayon-sy">]</span><span class="crayon-o">*</span><span class="crayon-o">*</span><span class="crayon-cn">2</span><span class="crayon-h"> &nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb92419920020-12" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp; </span><span class="crayon-v">trans_x</span> <span class="crayon-o">=</span> <span class="crayon-v">np</span><span class="crayon-sy">.</span><span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-v">x_1</span><span class="crayon-sy">,</span> <span class="crayon-v">x_2</span><span class="crayon-sy">,</span> <span class="crayon-v">x_3</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb92419920020-13" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp; </span><span class="crayon-st">return</span> <span class="crayon-v">trans_x</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">&Aacute;nh xạ mới phải c&oacute; 3 chiều với 16 điểm.</p> <div id="urvanov-syntax-highlighter-610feb7c8bb96879074593" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb96879074593-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb96879074593-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610feb7c8bb96879074593-1" class="crayon-line"><span class="crayon-v">x_1</span><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-o">=</span> <span class="crayon-e">mapping</span><span class="crayon-sy">(</span><span class="crayon-v">x</span><span class="crayon-sy">,</span> <span class="crayon-v">y</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb96879074593-2" class="crayon-line crayon-striped-line"><span class="crayon-v">x_1</span><span class="crayon-sy">.</span><span class="crayon-v">shape</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610feb7c8bb97477249593" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb97477249593-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610feb7c8bb97477249593-1" class="crayon-line"><span class="crayon-sy">(</span><span class="crayon-cn">3</span><span class="crayon-sy">,</span> <span class="crayon-cn">16</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">H&atilde;y tạo một biểu đồ mới với 3 axis, x, y v&agrave; z tương ứng:</p> <div id="urvanov-syntax-highlighter-610feb7c8bb99990096243" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb99990096243-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb99990096243-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb99990096243-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb99990096243-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb99990096243-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb99990096243-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb99990096243-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb99990096243-8">8</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610feb7c8bb99990096243-1" class="crayon-line"><span class="crayon-p"># plot</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb99990096243-2" class="crayon-line crayon-striped-line"><span class="crayon-v">fig</span> <span class="crayon-o">=</span> <span class="crayon-v">plt</span><span class="crayon-sy">.</span><span class="crayon-e">figure</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb99990096243-3" class="crayon-line"><span class="crayon-v">ax</span> <span class="crayon-o">=</span> <span class="crayon-v">fig</span><span class="crayon-sy">.</span><span class="crayon-e">add_subplot</span><span class="crayon-sy">(</span><span class="crayon-cn">111</span><span class="crayon-sy">,</span> <span class="crayon-v">projection</span><span class="crayon-o">=</span><span class="crayon-s">'3d'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb99990096243-4" class="crayon-line crayon-striped-line"><span class="crayon-v">ax</span><span class="crayon-sy">.</span><span class="crayon-e">scatter</span><span class="crayon-sy">(</span><span class="crayon-v">x_1</span><span class="crayon-sy">[</span><span class="crayon-cn">0</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-v">x_1</span><span class="crayon-sy">[</span><span class="crayon-cn">1</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-v">x_1</span><span class="crayon-sy">[</span><span class="crayon-cn">2</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-v">c</span><span class="crayon-o">=</span><span class="crayon-v">label</span><span class="crayon-sy">,</span> <span class="crayon-v">s</span><span class="crayon-o">=</span><span class="crayon-cn">60</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb99990096243-5" class="crayon-line"><span class="crayon-v">ax</span><span class="crayon-sy">.</span><span class="crayon-e">view_init</span><span class="crayon-sy">(</span><span class="crayon-cn">30</span><span class="crayon-sy">,</span> <span class="crayon-cn">185</span><span class="crayon-sy">)</span><span class="crayon-v">ax</span><span class="crayon-sy">.</span><span class="crayon-e">set_xlabel</span><span class="crayon-sy">(</span><span class="crayon-s">'X Label'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb99990096243-6" class="crayon-line crayon-striped-line"><span class="crayon-v">ax</span><span class="crayon-sy">.</span><span class="crayon-e">set_ylabel</span><span class="crayon-sy">(</span><span class="crayon-s">'Y Label'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb99990096243-7" class="crayon-line"><span class="crayon-v">ax</span><span class="crayon-sy">.</span><span class="crayon-e">set_zlabel</span><span class="crayon-sy">(</span><span class="crayon-s">'Z Label'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb99990096243-8" class="crayon-line crayon-striped-line"><span class="crayon-v">plt</span><span class="crayon-sy">.</span><span class="crayon-e">show</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><img class="aligncenter size-full wp-image-7956 disappear appear" src="../../wp-content/uploads/2021/01/082918_0458_KernelMetho3.png" sizes="(max-width: 475px) 100vw, 475px" srcset="https://old.tek4.vn/wp-content/uploads/2021/01/082918_0458_KernelMetho3.png 475w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_0458_KernelMetho3-300x200.png 300w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_0458_KernelMetho3-90x60.png 90w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_0458_KernelMetho3-180x120.png 180w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_0458_KernelMetho3-95x64.png 95w" alt="" width="475" height="317" loading="lazy" /></p> <p style="text-align: justify;">Ch&uacute;ng ta thấy c&oacute; sự cải thiện nhưng nếu ta thay đổi hướng của biểu đồ, r&otilde; r&agrave;ng l&agrave; tập dữ liệu hiện c&oacute; thể t&aacute;ch rời.</p> <div id="urvanov-syntax-highlighter-610feb7c8bb9b552307094" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb9b552307094-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb9b552307094-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb9b552307094-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb9b552307094-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb9b552307094-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb9b552307094-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb9b552307094-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610feb7c8bb9b552307094-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610feb7c8bb9b552307094-9">9</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610feb7c8bb9b552307094-1" class="crayon-line"><span class="crayon-p"># plot</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb9b552307094-2" class="crayon-line crayon-striped-line"><span class="crayon-v">fig</span> <span class="crayon-o">=</span> <span class="crayon-v">plt</span><span class="crayon-sy">.</span><span class="crayon-e">figure</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb9b552307094-3" class="crayon-line"><span class="crayon-v">ax</span> <span class="crayon-o">=</span> <span class="crayon-v">fig</span><span class="crayon-sy">.</span><span class="crayon-e">add_subplot</span><span class="crayon-sy">(</span><span class="crayon-cn">111</span><span class="crayon-sy">,</span> <span class="crayon-v">projection</span><span class="crayon-o">=</span><span class="crayon-s">'3d'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb9b552307094-4" class="crayon-line crayon-striped-line"><span class="crayon-v">ax</span><span class="crayon-sy">.</span><span class="crayon-e">scatter</span><span class="crayon-sy">(</span><span class="crayon-v">x_1</span><span class="crayon-sy">[</span><span class="crayon-cn">0</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-v">x_1</span><span class="crayon-sy">[</span><span class="crayon-cn">1</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-v">x_1</span><span class="crayon-sy">[</span><span class="crayon-cn">1</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-v">c</span><span class="crayon-o">=</span><span class="crayon-v">label</span><span class="crayon-sy">,</span> <span class="crayon-v">s</span><span class="crayon-o">=</span><span class="crayon-cn">60</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb9b552307094-5" class="crayon-line"><span class="crayon-v">ax</span><span class="crayon-sy">.</span><span class="crayon-e">view_init</span><span class="crayon-sy">(</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span> <span class="crayon-o">-</span><span class="crayon-cn">180</span><span class="crayon-sy">)</span><span class="crayon-v">ax</span><span class="crayon-sy">.</span><span class="crayon-e">set_ylim</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">150</span><span class="crayon-sy">,</span><span class="crayon-o">-</span><span class="crayon-cn">50</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb9b552307094-6" class="crayon-line crayon-striped-line"><span class="crayon-v">ax</span><span class="crayon-sy">.</span><span class="crayon-e">set_zlim</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-o">-</span><span class="crayon-cn">10000</span><span class="crayon-sy">,</span><span class="crayon-cn">10000</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb9b552307094-7" class="crayon-line"><span class="crayon-v">ax</span><span class="crayon-sy">.</span><span class="crayon-e">set_xlabel</span><span class="crayon-sy">(</span><span class="crayon-s">'X Label'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb9b552307094-8" class="crayon-line crayon-striped-line"><span class="crayon-v">ax</span><span class="crayon-sy">.</span><span class="crayon-e">set_ylabel</span><span class="crayon-sy">(</span><span class="crayon-s">'Y Label'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610feb7c8bb9b552307094-9" class="crayon-line"><span class="crayon-v">ax</span><span class="crayon-sy">.</span><span class="crayon-e">set_zlabel</span><span class="crayon-sy">(</span><span class="crayon-s">'Z Label'</span><span class="crayon-sy">)</span><span class="crayon-v">plt</span><span class="crayon-sy">.</span><span class="crayon-e">show</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><img class="aligncenter size-full wp-image-7957 disappear appear" src="../../wp-content/uploads/2021/01/082918_0458_KernelMetho4.png" sizes="(max-width: 475px) 100vw, 475px" srcset="https://old.tek4.vn/wp-content/uploads/2021/01/082918_0458_KernelMetho4.png 475w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_0458_KernelMetho4-300x200.png 300w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_0458_KernelMetho4-90x60.png 90w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_0458_KernelMetho4-180x120.png 180w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_0458_KernelMetho4-95x64.png 95w" alt="" width="475" height="317" loading="lazy" /></p> <p style="text-align: justify;">Tr&ecirc;n thực tế, ta cần phải chuyển đổi tất cả c&aacute;c điểm dữ liệu, điều n&agrave;y r&otilde; r&agrave;ng l&agrave; kh&ocirc;ng bền vững. Bạn sẽ mất nhiều thời gian v&agrave; m&aacute;y t&iacute;nh của bạn c&oacute; thể hết bộ nhớ.</p> <p style="text-align: justify;">C&aacute;ch phổ biến nhất để khắc phục vấn đề n&agrave;y l&agrave; sử dụng một kernel.</p> <h3 id="ftoc-heading-2" class="ftwp-heading" style="text-align: justify;">Kernel trong học m&aacute;y l&agrave; g&igrave;?</h3> <p style="text-align: justify;">&Yacute; tưởng l&agrave; sử dụng kh&ocirc;ng gian đặc trưng c&oacute; k&iacute;ch thước cao hơn để l&agrave;m cho dữ liệu gần như c&oacute; thể ph&acirc;n t&aacute;ch tuyến t&iacute;nh như thể hiện trong h&igrave;nh tr&ecirc;n.</p> <p style="text-align: justify;">C&oacute; rất nhiều kh&ocirc;ng gian chiều cao hơn để l&agrave;m cho c&aacute;c điểm dữ liệu c&oacute; thể ph&acirc;n t&aacute;ch được. V&iacute; dụ, ch&uacute;ng ta đ&atilde; chỉ ra rằng &aacute;nh xạ đa thức l&agrave; một bước khởi đầu tuyệt vời.</p> <p style="text-align: justify;">Ch&uacute;ng ta cũng đ&atilde; chứng minh rằng với nhiều dữ liệu, việc chuyển đổi n&agrave;y kh&ocirc;ng hiệu quả. Thay v&agrave;o đ&oacute;, bạn c&oacute; thể sử dụng h&agrave;m Kernel trong Học m&aacute;y để sửa đổi dữ liệu m&agrave; kh&ocirc;ng cần thay đổi đặc trưng mới.(&nbsp;Instead, you can use a Kernel function in Machine Learning to modify the data without changing to a new feature plan.&nbsp;)</p> <p style="text-align: justify;"><a href="https://www.guru99.com/kernel-methods-machine-learning.html">Kernel Methods in Machine Learning: Gaussian Kernel (Example) (guru99.com)</a></p> <p style="text-align: justify;">B&agrave;i viết tiếp theo:&nbsp;<a href="../../mang-neural-gioi-thieu-va-vi-du-tu-hoc-tensorflow/" target="_blank" rel="noopener">Giới thiệu mạng neural &ndash;&nbsp;V&iacute; dụ về TensorFlow ANN</a></p>