tek4

Hồi Quy Tuyến Tính Cho Machine learning – Tự Học TensorFLow

by - September. 25, 2021
Kiến thức
<blockquote> <p>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 c&aacute;ch kiểm tra dữ liệu v&agrave; chuẩn bị để tạo một t&aacute;c vụ Linear Regression (hồi quy tuyến t&iacute;nh) đơn giản. Bắt đầu th&ocirc;i!</p> </blockquote> <p>Xem th&ecirc;m b&agrave;i viết trước:&nbsp;<a href="../../linear-regression-voi-tensorflow-tu-hoc-tensorflow/" target="_blank" rel="noopener">Linear Regression với Tensorflow</a></p> <p><img class="aligncenter size-full wp-image-7361 disappear appear" src="../../wp-content/uploads/2021/01/10.png" sizes="(max-width: 1113px) 100vw, 1113px" srcset="https://old.tek4.vn/wp-content/uploads/2021/01/10.png 1113w, https://old.tek4.vn/wp-content/uploads/2021/01/10-300x157.png 300w, https://old.tek4.vn/wp-content/uploads/2021/01/10-1024x535.png 1024w, https://old.tek4.vn/wp-content/uploads/2021/01/10-768x402.png 768w" alt=" Linear Regression cho Machine learning" width="1113" height="582" loading="lazy" /></p> <p>Trong b&agrave;i viết trước, ch&uacute;ng ta đ&atilde; sử dụng tập dữ liệu Boston để ước t&iacute;nh gi&aacute; trung b&igrave;nh của một ng&ocirc;i nh&agrave;. Bộ dữ liệu Boston c&oacute; k&iacute;ch thước nhỏ, chỉ với 506. Tập dữ liệu n&agrave;y được coi l&agrave; chuẩn để thử c&aacute;c thuật to&aacute;n hồi quy tuyến t&iacute;nh mới.</p> <p>Tập dữ liệu bao gồm:</p> <table class="table table-striped aligncenter"> <tbody> <tr> <td>Variable</td> <td>Description</td> </tr> <tr> <td>zn</td> <td>Tỷ lệ đất ở được quy hoạch cho c&aacute;c l&ocirc; tr&ecirc;n 25.000 sq.ft.</td> </tr> <tr> <td>indus</td> <td>Tỷ lệ diện t&iacute;ch kinh doanh kh&ocirc;ng b&aacute;n lẻ tr&ecirc;n mỗi thị trấn.</td> </tr> <tr> <td>nox</td> <td>Nồng độ oxit nitric</td> </tr> <tr> <td>rm</td> <td>Số lượng ph&ograve;ng trung b&igrave;nh tr&ecirc;n một ng&ocirc;i nh&agrave;</td> </tr> <tr> <td>age</td> <td>Tỷ lệ c&aacute;c căn hộ c&oacute; chủ sở hữu được x&acirc;y dựng trước năm 1940</td> </tr> <tr> <td>dis</td> <td>Khoảng c&aacute;ch đến năm trung t&acirc;m việc l&agrave;m Boston</td> </tr> <tr> <td>tax</td> <td>Thuế suất t&agrave;i sản to&agrave;n gi&aacute; trị tr&ecirc;n mỗi 10.000 đ&ocirc; la</td> </tr> <tr> <td>ptratio</td> <td>Tỷ lệ học sinh-gi&aacute;o vi&ecirc;n theo thị trấn</td> </tr> <tr> <td>medv</td> <td>Gi&aacute; trị trung b&igrave;nh của những ng&ocirc;i nh&agrave; c&oacute; chủ sở hữu t&iacute;nh bằng ngh&igrave;n đ&ocirc; la</td> </tr> <tr> <td>crim</td> <td>Tỷ lệ tội phạm b&igrave;nh qu&acirc;n đầu người theo thị trấn</td> </tr> <tr> <td>chas</td> <td>Charles River dummy variable (1 if bounds river; 0 otherwise)</td> </tr> <tr> <td>B</td> <td>Tỷ lệ người da đen theo thị trấn</td> </tr> </tbody> </table> <p>Trong b&agrave;i viết n&agrave;y, ch&uacute;ng ta sẽ ước t&iacute;nh gi&aacute; trung b&igrave;nh bằng c&aacute;ch sử dụng hồi quy tuyến t&iacute;nh, nhưng trọng t&acirc;m l&agrave; một quy tr&igrave;nh cụ thể của học m&aacute;y: &lsquo;chuẩn bị dữ liệu&rsquo;.</p> <p>M&ocirc; h&igrave;nh tổng qu&aacute;t h&oacute;a mẫu trong dữ liệu. Để nắm bắt được một mẫu như vậy, trước ti&ecirc;n bạn cần phải t&igrave;m ra n&oacute;. Một phương ph&aacute;p hay l&agrave; thực hiện ph&acirc;n t&iacute;ch dữ liệu trước khi chạy bất kỳ thuật to&aacute;n học m&aacute;y n&agrave;o.</p> <p><em><strong>Việc lựa chọn c&aacute;c đặc trưng ph&ugrave; hợp tạo n&ecirc;n kh&aacute;c biệt cho sự th&agrave;nh c&ocirc;ng m&ocirc; h&igrave;nh của bạn. H&atilde;y tưởng tượng bạn cố gắng ước t&iacute;nh mức lương của một người, nếu bạn kh&ocirc;ng bao gồm giới t&iacute;nh, bạn sẽ c&oacute; một ước t&iacute;nh k&eacute;m.</strong></em></p> <p>Một c&aacute;ch kh&aacute;c để cải thiện m&ocirc; h&igrave;nh l&agrave; xem x&eacute;t mối tương quan giữa biến độc lập. Trở lại v&iacute; dụ, bạn c&oacute; thể nghĩ về gi&aacute;o dục như một ứng cử vi&ecirc;n xuất sắc để dự đo&aacute;n mức lương nhưng cũng l&agrave; nghề nghiệp. C&ocirc;ng bằng m&agrave; n&oacute;i, nghề nghiệp phụ thuộc v&agrave;o tr&igrave;nh độ học vấn, cụ thể l&agrave; học cao hơn thường dẫn đến nghề tốt hơn. Nếu ch&uacute;ng ta kh&aacute;i qu&aacute;t h&oacute;a &yacute; tưởng n&agrave;y, ch&uacute;ng ta c&oacute; thể n&oacute;i rằng mối tương quan giữa biến phụ thuộc v&agrave; một biến giải th&iacute;ch c&oacute; thể được ph&oacute;ng đại so với một biến giải th&iacute;ch kh&aacute;c.</p> <h3 id="ftoc-heading-1" class="ftwp-heading">T&oacute;m tắt thống k&ecirc;</h3> <p>C&oacute; một số bước bạn c&oacute; thể l&agrave;m theo trước khi tiếp tục với m&ocirc; h&igrave;nh. Như đ&atilde; đề cập trước đ&oacute;, m&ocirc; h&igrave;nh l&agrave; sự tổng qu&aacute;t h&oacute;a của dữ liệu. Phương ph&aacute;p ph&ugrave; hợp nhất l&agrave; hiểu dữ liệu v&agrave; đưa ra dự đo&aacute;n. Nếu bạn kh&ocirc;ng biết dữ liệu của m&igrave;nh, th&igrave; sẽ c&oacute; rất &iacute;t cơ hội để cải thiện m&ocirc; h&igrave;nh của m&igrave;nh.</p> <p>Bước đầu ti&ecirc;n, h&atilde;y tải dữ liệu dưới dạng pandas dataframe v&agrave; tạo tập huấn luyện v&agrave; tập thử nghiệm.</p> <p>Mẹo: Đối với hướng dẫn n&agrave;y, bạn cần c&agrave;i đặt matplotlit v&agrave; seaborn bằng Python.</p> <p>Matplotlib l&agrave; thư viện để tạo đồ thị bằng Python. Seaborn l&agrave; một thư viện trực quan h&oacute;a thống k&ecirc; được x&acirc;y dựng tr&ecirc;n matplotlib. Đoạn code dưới đ&acirc;y nhập c&aacute;c thư viện cần thiết.</p> <div id="urvanov-syntax-highlighter-610fea28b8897028966265" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b8897028966265-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8897028966265-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8897028966265-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8897028966265-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8897028966265-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b8897028966265-1" class="crayon-line"><span class="crayon-e">import </span><span class="crayon-e">pandas </span><span class="crayon-st">as</span> <span class="crayon-e">pd</span></div> <div id="urvanov-syntax-highlighter-610fea28b8897028966265-2" class="crayon-line crayon-striped-line"><span class="crayon-e">from </span><span class="crayon-e">sklearn </span><span class="crayon-e">import </span><span class="crayon-e">datasets</span></div> <div id="urvanov-syntax-highlighter-610fea28b8897028966265-3" class="crayon-line"><span class="crayon-e">import </span><span class="crayon-e">tensorflow </span><span class="crayon-st">as</span> <span class="crayon-e">tf</span></div> <div id="urvanov-syntax-highlighter-610fea28b8897028966265-4" class="crayon-line crayon-striped-line"><span class="crayon-e">from </span><span class="crayon-v">sklearn</span><span class="crayon-sy">.</span><span class="crayon-e">datasets </span><span class="crayon-e">import </span><span class="crayon-e">load_boston</span></div> <div id="urvanov-syntax-highlighter-610fea28b8897028966265-5" class="crayon-line"><span class="crayon-e">import </span><span class="crayon-e">numpy </span><span class="crayon-st">as</span> <span class="crayon-v">np</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Thư viện sklearn bao gồm tập dữ liệu Boston. Bạn c&oacute; thể gọi API của n&oacute; để nhập dữ liệu.</p> <div id="urvanov-syntax-highlighter-610fea28b88a0002603945" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88a0002603945-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88a0002603945-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88a0002603945-1" class="crayon-line"><span class="crayon-v">boston</span> <span class="crayon-o">=</span> <span class="crayon-e">load_boston</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88a0002603945-2" class="crayon-line crayon-striped-line"><span class="crayon-v">df</span> <span class="crayon-o">=</span> <span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">DataFrame</span><span class="crayon-sy">(</span><span class="crayon-v">boston</span><span class="crayon-sy">.</span><span class="crayon-v">data</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>T&ecirc;n của đối tượng được lưu trữ trong đối tượng feature_names trong một mảng.</p> <div id="urvanov-syntax-highlighter-610fea28b88a2851357486" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88a2851357486-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88a2851357486-1" class="crayon-line"><span class="crayon-v">boston</span><span class="crayon-sy">.</span><span class="crayon-v">feature_names</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fea28b88a5297937860" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88a5297937860-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88a5297937860-1" class="crayon-line"><span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-s">'CRIM'</span><span class="crayon-sy">,</span> <span class="crayon-s">'ZN'</span><span class="crayon-sy">,</span> <span class="crayon-s">'INDUS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'CHAS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'NOX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'RM'</span><span class="crayon-sy">,</span> <span class="crayon-s">'AGE'</span><span class="crayon-sy">,</span> <span class="crayon-s">'DIS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'RAD'</span><span class="crayon-sy">,</span><span class="crayon-s">'TAX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'PTRATIO'</span><span class="crayon-sy">,</span> <span class="crayon-s">'B'</span><span class="crayon-sy">,</span> <span class="crayon-s">'LSTAT'</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-v">dtype</span><span class="crayon-o">=</span><span class="crayon-s">'&amp;lt;U7'</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Bạn c&oacute; thể đổi t&ecirc;n c&aacute;c cột.</p> <div id="urvanov-syntax-highlighter-610fea28b88a6271416797" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88a6271416797-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88a6271416797-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88a6271416797-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88a6271416797-1" class="crayon-line"><span class="crayon-v">df</span><span class="crayon-sy">.</span><span class="crayon-v">columns</span> <span class="crayon-o">=</span> <span class="crayon-v">boston</span><span class="crayon-sy">.</span><span class="crayon-e">feature_names</span></div> <div id="urvanov-syntax-highlighter-610fea28b88a6271416797-2" class="crayon-line crayon-striped-line"><span class="crayon-v">df</span><span class="crayon-sy">[</span><span class="crayon-s">'PRICE'</span><span class="crayon-sy">]</span> <span class="crayon-o">=</span> <span class="crayon-v">boston</span><span class="crayon-sy">.</span><span class="crayon-e">target</span></div> <div id="urvanov-syntax-highlighter-610fea28b88a6271416797-3" class="crayon-line"><span class="crayon-v">df</span><span class="crayon-sy">.</span><span class="crayon-e">head</span><span class="crayon-sy">(</span><span class="crayon-cn">2</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p><img class="aligncenter size-full wp-image-7878 disappear appear" src="../../wp-content/uploads/2021/01/082918_1226_LinearRegre2.png" sizes="(max-width: 799px) 100vw, 799px" srcset="https://old.tek4.vn/wp-content/uploads/2021/01/082918_1226_LinearRegre2.png 799w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_1226_LinearRegre2-300x42.png 300w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_1226_LinearRegre2-768x109.png 768w" alt="" width="799" height="113" loading="lazy" /></p> <p>Bạn chuyển đổi biến CHAS th&agrave;nh biến chuỗi v&agrave; gắn nh&atilde;n yes nếu CHAS = 1 v&agrave; no nếu CHAS = 0</p> <div id="urvanov-syntax-highlighter-610fea28b88a8086302556" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88a8086302556-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88a8086302556-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88a8086302556-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88a8086302556-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88a8086302556-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88a8086302556-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88a8086302556-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88a8086302556-8">8</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88a8086302556-1" class="crayon-line"><span class="crayon-v">df</span><span class="crayon-sy">[</span><span class="crayon-s">'CHAS'</span><span class="crayon-sy">]</span> <span class="crayon-o">=</span> <span class="crayon-v">df</span><span class="crayon-sy">[</span><span class="crayon-s">'CHAS'</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-e">map</span><span class="crayon-sy">(</span><span class="crayon-sy">{</span><span class="crayon-cn">1</span><span class="crayon-o">:</span><span class="crayon-s">'yes'</span><span class="crayon-sy">,</span> <span class="crayon-cn">0</span><span class="crayon-o">:</span><span class="crayon-s">'no'</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88a8086302556-2" class="crayon-line crayon-striped-line"><span class="crayon-v">df</span><span class="crayon-sy">[</span><span class="crayon-s">'CHAS'</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-e">head</span><span class="crayon-sy">(</span><span class="crayon-cn">5</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88a8086302556-3" class="crayon-line"><span class="crayon-cn">0</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-i">no</span></div> <div id="urvanov-syntax-highlighter-610fea28b88a8086302556-4" class="crayon-line crayon-striped-line"><span class="crayon-cn">1</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-i">no</span></div> <div id="urvanov-syntax-highlighter-610fea28b88a8086302556-5" class="crayon-line"><span class="crayon-cn">2</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-i">no</span></div> <div id="urvanov-syntax-highlighter-610fea28b88a8086302556-6" class="crayon-line crayon-striped-line"><span class="crayon-cn">3</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-i">no</span></div> <div id="urvanov-syntax-highlighter-610fea28b88a8086302556-7" class="crayon-line"><span class="crayon-cn">4</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-e">no</span></div> <div id="urvanov-syntax-highlighter-610fea28b88a8086302556-8" class="crayon-line crayon-striped-line"><span class="crayon-v">Name</span><span class="crayon-o">:</span> <span class="crayon-v">CHAS</span><span class="crayon-sy">,</span> <span class="crayon-v">dtype</span><span class="crayon-o">:</span> <span class="crayon-t">object</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Với pandas, việc chia nhỏ tập dữ liệu rất đơn giản. Bạn ph&acirc;n chia ngẫu nhi&ecirc;n tập dữ liệu với tập huấn luyện 80 phần trăm v&agrave; tập kiểm tra 20 phần trăm. Pandas c&oacute; h&agrave;m chi ph&iacute; t&iacute;ch hợp để t&aacute;ch một mẫu khung dữ liệu.</p> <p>Tham số đầu ti&ecirc;n frac l&agrave; một gi&aacute; trị từ 0 đến 1. Bạn đặt n&oacute; th&agrave;nh 0,8 để chọn ngẫu nhi&ecirc;n 80 phần trăm khung dữ liệu.</p> <p>Random_state cho ph&eacute;p trả về c&ugrave;ng một khung dữ liệu cho mọi người.</p> <div id="urvanov-syntax-highlighter-610fea28b88aa390868659" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88aa390868659-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88aa390868659-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88aa390868659-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88aa390868659-1" class="crayon-line"><span class="crayon-p">### Create train/test set</span></div> <div id="urvanov-syntax-highlighter-610fea28b88aa390868659-2" class="crayon-line crayon-striped-line"><span class="crayon-v">df_train</span><span class="crayon-o">=</span><span class="crayon-v">df</span><span class="crayon-sy">.</span><span class="crayon-e">sample</span><span class="crayon-sy">(</span><span class="crayon-v">frac</span><span class="crayon-o">=</span><span class="crayon-cn">0.8</span><span class="crayon-sy">,</span><span class="crayon-v">random_state</span><span class="crayon-o">=</span><span class="crayon-cn">200</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88aa390868659-3" class="crayon-line"><span class="crayon-v">df_test</span><span class="crayon-o">=</span><span class="crayon-v">df</span><span class="crayon-sy">.</span><span class="crayon-e">drop</span><span class="crayon-sy">(</span><span class="crayon-v">df_train</span><span class="crayon-sy">.</span><span class="crayon-v">index</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Bạn c&oacute; thể nhận được shape của dữ liệu. N&oacute; phải l&agrave;:</p> <ul> <li>Train set: 506*0.8 = 405</li> <li>Test set: 506*0.2 = 101</li> </ul> <div id="urvanov-syntax-highlighter-610fea28b88ac762997419" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88ac762997419-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88ac762997419-1" class="crayon-line"><span class="crayon-e">print</span><span class="crayon-sy">(</span><span class="crayon-v">df_train</span><span class="crayon-sy">.</span><span class="crayon-v">shape</span><span class="crayon-sy">,</span> <span class="crayon-v">df_test</span><span class="crayon-sy">.</span><span class="crayon-v">shape</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fea28b88ad430236045" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88ad430236045-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88ad430236045-1" class="crayon-line"><span class="crayon-sy">(</span><span class="crayon-cn">405</span><span class="crayon-sy">,</span> <span class="crayon-cn">14</span><span class="crayon-sy">)</span> <span class="crayon-sy">(</span><span class="crayon-cn">101</span><span class="crayon-sy">,</span> <span class="crayon-cn">14</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610fea28b88af835760861" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88af835760861-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88af835760861-1" class="crayon-line"><span class="crayon-v">df_test</span><span class="crayon-sy">.</span><span class="crayon-e">head</span><span class="crayon-sy">(</span><span class="crayon-cn">5</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p><strong>Output</strong></p> <table class="table table-striped"> <tbody> <tr> <td>&nbsp;</td> <td><strong>CRIM</strong></td> <td><strong>ZN</strong></td> <td><strong>INDUS</strong></td> <td><strong>CHAS</strong></td> <td><strong>NOX</strong></td> <td><strong>RM</strong></td> <td><strong>AGE</strong></td> <td><strong>DIS</strong></td> <td><strong>RAD</strong></td> <td><strong>TAX</strong></td> <td><strong>PTRATIO</strong></td> <td><strong>B</strong></td> <td><strong>LSTAT</strong></td> <td><strong>PRICE</strong></td> </tr> <tr> <td><strong>0</strong></td> <td>0.00632</td> <td>18.0</td> <td>2.31</td> <td>no</td> <td>0.538</td> <td>6.575</td> <td>65.2</td> <td>4.0900</td> <td>1.0</td> <td>296.0</td> <td>15.3</td> <td>396.90</td> <td>4.98</td> <td>24.0</td> </tr> <tr> <td><strong>1</strong></td> <td>0.02731</td> <td>0.0</td> <td>7.07</td> <td>no</td> <td>0.469</td> <td>6.421</td> <td>78.9</td> <td>4.9671</td> <td>2.0</td> <td>242.0</td> <td>17.8</td> <td>396.90</td> <td>9.14</td> <td>21.6</td> </tr> <tr> <td><strong>3</strong></td> <td>0.03237</td> <td>0.0</td> <td>2.18</td> <td>no</td> <td>0.458</td> <td>6.998</td> <td>45.8</td> <td>6.0622</td> <td>3.0</td> <td>222.0</td> <td>18.7</td> <td>394.63</td> <td>2.94</td> <td>33.4</td> </tr> <tr> <td><strong>6</strong></td> <td>0.08829</td> <td>12.5</td> <td>7.87</td> <td>no</td> <td>0.524</td> <td>6.012</td> <td>66.6</td> <td>5.5605</td> <td>5.0</td> <td>311.0</td> <td>15.2</td> <td>395.60</td> <td>12.43</td> <td>22.9</td> </tr> <tr> <td><strong>7</strong></td> <td>0.14455</td> <td>12.5</td> <td>7.87</td> <td>no</td> <td>0.524</td> <td>6.172</td> <td>96.1</td> <td>5.9505</td> <td>5.0</td> <td>311.0</td> <td>15.2</td> <td>396.90</td> <td>19.15</td> <td>27.1</td> </tr> </tbody> </table> <p>Dữ liệu lộn xộn: N&oacute; thường kh&ocirc;ng c&acirc;n bằng v&agrave; rắc rối với c&aacute;c gi&aacute; trị ngoại lệ l&agrave;m mất khả năng ph&acirc;n t&iacute;ch v&agrave; đ&agrave;o tạo m&aacute;y học.</p> <p><em><strong>Bước đầu ti&ecirc;n để l&agrave;m sạch tập dữ liệu l&agrave; hiểu vị tr&iacute; cần l&agrave;m sạch.&nbsp;</strong></em>Việc dọn dẹp một tập dữ liệu c&oacute; thể kh&oacute; thực hiện, đặc biệt l&agrave; theo bất kỳ c&aacute;ch tổng qu&aacute;t n&agrave;o.</p> <p>Nh&oacute;m Nghi&ecirc;n cứu của Google đ&atilde; ph&aacute;t triển một c&ocirc;ng cụ cho c&ocirc;ng việc n&agrave;y c&oacute; t&ecirc;n l&agrave;&nbsp;<strong>Facets</strong>&nbsp;gi&uacute;p trực quan h&oacute;a dữ liệu v&agrave; ph&acirc;n chia dữ liệu theo mọi c&aacute;ch xử l&yacute;. Đ&acirc;y l&agrave; một điểm khởi đầu tốt để hiểu c&aacute;ch tr&igrave;nh b&agrave;y tập dữ liệu.</p> <p>Facets cho ph&eacute;p bạn t&igrave;m nơi dữ liệu kh&ocirc;ng giống như c&aacute;ch bạn đang nghĩ.</p> <p>Ngoại trừ ứng dụng web của họ, Google gi&uacute;p bạn dễ d&agrave;ng nh&uacute;ng bộ c&ocirc;ng cụ v&agrave;o Jupyter notebook.</p> <p>C&oacute; hai phần đối với Facets:</p> <ul> <li>Facets Overview</li> </ul> <ul> <li>Facets Deep Dive</li> </ul> <h3 id="ftoc-heading-2" class="ftwp-heading">Facets Overview</h3> <p>Facets Overview cung cấp tổng quan về tập dữ liệu. N&oacute; chia c&aacute;c cột dữ liệu th&agrave;nh c&aacute;c h&agrave;ng th&ocirc;ng tin nổi bật hiển thị:</p> <ol> <li>Tỷ lệ thiếu quan s&aacute;t</li> <li>Gi&aacute; trị tối thiểu v&agrave; tối đa</li> <li>Thống k&ecirc; như gi&aacute; trị trung b&igrave;nh, độ lệch chuẩn.</li> <li>N&oacute; cũng th&ecirc;m một cột hiển thị phần trăm gi&aacute; trị l&agrave; số 0, rất hữu &iacute;ch khi hầu hết c&aacute;c gi&aacute; trị l&agrave; số 0.</li> <li>C&oacute; thể thấy c&aacute;c ph&acirc;n phối n&agrave;y tr&ecirc;n tập dữ liệu thử nghiệm cũng như tập huấn luyện cho từng đặc trưng. N&oacute; c&oacute; nghĩa l&agrave; bạn c&oacute; thể kiểm tra kỹ xem test set c&oacute; ph&acirc;n phối tương tự với dữ liệu đ&agrave;o tạo hay kh&ocirc;ng.</li> </ol> <p>Đ&acirc;y l&agrave; điều tối thiểu phải l&agrave;m trước bất kỳ t&aacute;c vụ học m&aacute;y n&agrave;o. Với c&ocirc;ng cụ n&agrave;y, bạn kh&ocirc;ng bỏ lỡ bước quan trọng n&agrave;y v&agrave; n&oacute; l&agrave;m nổi bật một số bất thường.</p> <h3 id="ftoc-heading-3" class="ftwp-heading">Facets Deep Dive</h3> <p>Facets Deep Dive l&agrave; một c&ocirc;ng cụ th&uacute; vị. N&oacute; cho ph&eacute;p bạn c&oacute; một số r&otilde; r&agrave;ng về bộ dữ liệu của m&igrave;nh v&agrave; ph&oacute;ng to để xem từng phần dữ liệu. N&oacute; c&oacute; nghĩa l&agrave; bạn c&oacute; thể ph&acirc;n loại dữ liệu theo h&agrave;ng v&agrave; cột tr&ecirc;n bất kỳ đặc trưng n&agrave;o của tập dữ liệu.</p> <p>Ch&uacute;ng ta sẽ sử dụng hai c&ocirc;ng cụ n&agrave;y với tập dữ liệu Boston.</p> <p>Lưu &yacute;: Bạn kh&ocirc;ng thể sử dụng &nbsp;Facets Overview v&agrave; Facets Deep Dive c&ugrave;ng một l&uacute;c.</p> <h3 id="ftoc-heading-4" class="ftwp-heading">C&agrave;i đặt Facet</h3> <p>Bạn c&oacute; thể sử dụng ứng dụng web Facet cho hầu hết c&aacute;c ph&acirc;n t&iacute;ch.</p> <p>Trước hết, bạn cần c&agrave;i đặt nbextensions. N&oacute; được thực hiện với code n&agrave;y.</p> <div id="urvanov-syntax-highlighter-610fea28b88b3212812581" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88b3212812581-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88b3212812581-1" class="crayon-line"><span class="crayon-e">pip </span><span class="crayon-e">install </span><span class="crayon-v">jupyter_contrib_nbextensions</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>C&oacute; 2 lựa chọn:</p> <p><strong>T&ugrave;y chọn 1)&nbsp;</strong>Sao ch&eacute;p v&agrave; d&aacute;n code n&agrave;y v&agrave;o terminal (Khuyến nghị)</p> <p>Nếu bạn chưa c&agrave;i đặt Git tr&ecirc;n m&aacute;y của m&igrave;nh, vui l&ograve;ng truy cập&nbsp;<a href="https://git-scm.com/download/win" target="_blank" rel="noopener">URL n&agrave;y</a>&nbsp;v&agrave; l&agrave;m theo hướng dẫn. Sau khi ho&agrave;n tất, bạn c&oacute; thể sử dụng lệnh git trong terminal d&agrave;nh cho người d&ugrave;ng Mac hoặc Anaconda prompt cho người d&ugrave;ng Windows.</p> <div id="urvanov-syntax-highlighter-610fea28b88c3098385025" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88c3098385025-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88c3098385025-1" class="crayon-line"><span class="crayon-e">git </span><span class="crayon-r">clone</span> <span class="crayon-v">https</span><span class="crayon-o">:</span><span class="crayon-c">//github.com/PAIR-code/facets</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p><strong>T&ugrave;y chọn 2)</strong>&nbsp;Truy cập https://github.com/PAIR-code/facets v&agrave; tải xuống c&aacute;c repositories.</p> <p>Bạn c&oacute; thể kiểm tra nơi c&aacute;c &nbsp;Facets được lưu trữ bằng d&ograve;ng lệnh n&agrave;y:</p> <div id="urvanov-syntax-highlighter-610fea28b88c5541673542" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88c5541673542-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88c5541673542-1" class="crayon-line"><span class="crayon-i">echo</span> <span class="crayon-sy">`</span><span class="crayon-v">pwd</span><span class="crayon-sy">`</span><span class="crayon-o">/</span><span class="crayon-sy">`</span><span class="crayon-e">ls </span><span class="crayon-v">facets</span><span class="crayon-sy">`</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>B&acirc;y giờ đ&atilde; định vị được Facets, bạn cần c&agrave;i đặt n&oacute; trong Jupyter Notebook. Đặt thư mục l&agrave;m việc th&agrave;nh đường dẫn chứa facets.</p> <p>Thư mục l&agrave;m việc hiện tại v&agrave; vị tr&iacute; của Facets zip phải giống nhau.</p> <p><img class="aligncenter size-full wp-image-7942 disappear appear" src="../../wp-content/uploads/2021/01/082918_1226_LinearRegre4.png" sizes="(max-width: 500px) 100vw, 500px" srcset="https://old.tek4.vn/wp-content/uploads/2021/01/082918_1226_LinearRegre4.png 500w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_1226_LinearRegre4-300x227.png 300w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_1226_LinearRegre4-45x35.png 45w" alt="" width="500" height="379" loading="lazy" /></p> <p>Trỏ thư mục l&agrave;m việc tới Facet:</p> <div id="urvanov-syntax-highlighter-610fea28b88c7389504963" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88c7389504963-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88c7389504963-1" class="crayon-line"><span class="crayon-e">cd </span><span class="crayon-v">facets</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Để c&agrave;i đặt Facets trong Jupyter, bạn c&oacute; hai t&ugrave;y chọn. Nếu bạn đ&atilde; c&agrave;i đặt Jupyter với Conda cho tất cả người d&ugrave;ng, h&atilde;y sao ch&eacute;p m&atilde; n&agrave;y:</p> <p>C&oacute; thể sử dụng jupyter nbextension install facets-dist/</p> <div id="urvanov-syntax-highlighter-610fea28b88c8374234464" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88c8374234464-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88c8374234464-1" class="crayon-line"><span class="crayon-e">jupyter </span><span class="crayon-e">nbextension </span><span class="crayon-e">install </span><span class="crayon-v">facets</span><span class="crayon-o">-</span><span class="crayon-v">dist</span><span class="crayon-o">/</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Nếu kh&ocirc;ng, h&atilde;y sử dụng:</p> <div id="urvanov-syntax-highlighter-610fea28b88ca181894885" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88ca181894885-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88ca181894885-1" class="crayon-line"><span class="crayon-e">jupyter </span><span class="crayon-e">nbextension </span><span class="crayon-e">install </span><span class="crayon-v">facets</span><span class="crayon-o">-</span><span class="crayon-v">dist</span><span class="crayon-o">/</span> <span class="crayon-o">--</span><span class="crayon-v">user</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Được rồi, tất cả đ&atilde; sẵn s&agrave;ng. H&atilde;y mở Facet Overview.</p> <h3 id="ftoc-heading-5" class="ftwp-heading">Overview</h3> <p>Overview sử dụng tập lệnh Python để t&iacute;nh to&aacute;n số liệu thống k&ecirc;. Bạn cần nhập tập lệnh c&oacute; t&ecirc;n generic_feature_stosystem_generator v&agrave;o Jupyter. Đừng lo lắng; Tập lệnh nằm trong c&aacute;c tệp facets.</p> <p>Bạn cần x&aacute;c định path của n&oacute;. Mở facets, mở tệp facets_overview rồi đến python. Sao ch&eacute;p đường dẫn</p> <p><img class="aligncenter size-full wp-image-7943 disappear appear" src="../../wp-content/uploads/2021/01/082918_1226_LinearRegre5.png" sizes="(max-width: 980px) 100vw, 980px" srcset="https://old.tek4.vn/wp-content/uploads/2021/01/082918_1226_LinearRegre5.png 980w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_1226_LinearRegre5-300x127.png 300w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_1226_LinearRegre5-768x326.png 768w" alt="" width="980" height="416" loading="lazy" /></p> <p>Sau đ&oacute;, quay lại Jupyter v&agrave; viết m&atilde; sau. Thay đổi đường dẫn &lsquo;/Users/Tek4vn/facets/facets_overview/python&rsquo; th&agrave;nh đường dẫn của bạn.</p> <div id="urvanov-syntax-highlighter-610fea28b88cc481288769" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88cc481288769-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88cc481288769-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88cc481288769-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88cc481288769-1" class="crayon-line"><span class="crayon-p"># Add the facets overview python code to the python path# Add t </span></div> <div id="urvanov-syntax-highlighter-610fea28b88cc481288769-2" class="crayon-line crayon-striped-line"><span class="crayon-e">import </span><span class="crayon-e">sys</span></div> <div id="urvanov-syntax-highlighter-610fea28b88cc481288769-3" class="crayon-line"><span class="crayon-v">sys</span><span class="crayon-sy">.</span><span class="crayon-v">path</span><span class="crayon-sy">.</span><span class="crayon-e">append</span><span class="crayon-sy">(</span><span class="crayon-s">'/Users/Tek4vn/facets/facets_overview/python'</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Bạn c&oacute; thể nhập tập lệnh với m&atilde; b&ecirc;n dưới.</p> <div id="urvanov-syntax-highlighter-610fea28b88d0920835777" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88d0920835777-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88d0920835777-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88d0920835777-1" class="crayon-line"><span class="crayon-e">from </span><span class="crayon-e">generic_feature_statistics_generator </span><span class="crayon-e">import </span></div> <div id="urvanov-syntax-highlighter-610fea28b88d0920835777-2" class="crayon-line crayon-striped-line"><span class="crayon-v">GenericFeatureStatisticsGenerator</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Trong windows, m&atilde; tương tự sẽ trở th&agrave;nh</p> <div id="urvanov-syntax-highlighter-610fea28b88d1906559307" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88d1906559307-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88d1906559307-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88d1906559307-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88d1906559307-4">4</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88d1906559307-1" class="crayon-line"><span class="crayon-e">import </span><span class="crayon-e">sys</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d1906559307-2" class="crayon-line crayon-striped-line"><span class="crayon-v">sys</span><span class="crayon-sy">.</span><span class="crayon-v">path</span><span class="crayon-sy">.</span><span class="crayon-e">append</span><span class="crayon-sy">(</span><span class="crayon-i">r</span><span class="crayon-s">"C:\Users\Admin\Anaconda3\facets-master\facets_overview\python"</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d1906559307-3" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea28b88d1906559307-4" class="crayon-line crayon-striped-line"><span class="crayon-e">from </span><span class="crayon-e">generic_feature_statistics_generator </span><span class="crayon-e">import </span><span class="crayon-v">GenericFeatureStatisticsGenerator</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Để t&iacute;nh to&aacute;n thống k&ecirc; đối tượng, bạn cần sử dụng h&agrave;m&nbsp;GenericFeatureStosystemGenerator()&nbsp;v&agrave; sử dụng đối tượng ProtoFromDataFrames. C&oacute; thể chuyển dataframe v&agrave;o từ điển. V&iacute; dụ: nếu ch&uacute;ng ta muốn tạo một thống k&ecirc; t&oacute;m tắt cho train set, ch&uacute;ng ta c&oacute; thể lưu trữ th&ocirc;ng tin trong từ điển v&agrave; sử dụng n&oacute; trong đối tượng ProtoFromDataFrames.</p> <div id="urvanov-syntax-highlighter-610fea28b88d3382633933" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88d3382633933-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88d3382633933-1" class="crayon-line"><span class="crayon-s">'name'</span><span class="crayon-o">:</span> <span class="crayon-s">'train'</span><span class="crayon-sy">,</span> <span class="crayon-s">'table'</span><span class="crayon-o">:</span> <span class="crayon-v">df_train</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Name l&agrave; t&ecirc;n của bảng hiển thị v&agrave; bạn sử dụng t&ecirc;n của bảng m&agrave; bạn muốn t&iacute;nh t&oacute;m tắt. Trong v&iacute; dụ n&agrave;y, bảng chứa dữ liệu l&agrave; df_train.</p> <div id="urvanov-syntax-highlighter-610fea28b88d5909544127" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88d5909544127-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88d5909544127-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88d5909544127-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88d5909544127-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88d5909544127-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88d5909544127-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88d5909544127-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88d5909544127-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88d5909544127-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88d5909544127-10">10</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88d5909544127-1" class="crayon-line"><span class="crayon-p"># Calculate the feature statistics proto from the datasets and stringify it for use in facets overview</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d5909544127-2" class="crayon-line crayon-striped-line"><span class="crayon-e">import </span><span class="crayon-e">base64</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d5909544127-3" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea28b88d5909544127-4" class="crayon-line crayon-striped-line"><span class="crayon-v">gfsg</span> <span class="crayon-o">=</span> <span class="crayon-e">GenericFeatureStatisticsGenerator</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d5909544127-5" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea28b88d5909544127-6" class="crayon-line crayon-striped-line"><span class="crayon-v">proto</span> <span class="crayon-o">=</span> <span class="crayon-v">gfsg</span><span class="crayon-sy">.</span><span class="crayon-e">ProtoFromDataFrames</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-sy">{</span><span class="crayon-s">'name'</span><span class="crayon-o">:</span> <span class="crayon-s">'train'</span><span class="crayon-sy">,</span> <span class="crayon-s">'table'</span><span class="crayon-o">:</span> <span class="crayon-v">df_train</span><span class="crayon-sy">}</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d5909544127-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-sy">{</span><span class="crayon-s">'name'</span><span class="crayon-o">:</span> <span class="crayon-s">'test'</span><span class="crayon-sy">,</span> <span class="crayon-s">'table'</span><span class="crayon-o">:</span> <span class="crayon-v">df_test</span><span class="crayon-sy">}</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d5909544127-8" class="crayon-line crayon-striped-line"></div> <div id="urvanov-syntax-highlighter-610fea28b88d5909544127-9" class="crayon-line"><span class="crayon-p">#proto = gfsg.ProtoFromDataFrames([{'name': 'train', 'table': df_train}])</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d5909544127-10" class="crayon-line crayon-striped-line"><span class="crayon-v">protostr</span> <span class="crayon-o">=</span> <span class="crayon-v">base64</span><span class="crayon-sy">.</span><span class="crayon-e">b64encode</span><span class="crayon-sy">(</span><span class="crayon-v">proto</span><span class="crayon-sy">.</span><span class="crayon-e">SerializeToString</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span><span class="crayon-sy">)</span><span class="crayon-sy">.</span><span class="crayon-e">decode</span><span class="crayon-sy">(</span><span class="crayon-s">"utf-8"</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Cuối c&ugrave;ng, chỉ cần sao ch&eacute;p v&agrave; d&aacute;n đoạn m&atilde; b&ecirc;n dưới.</p> <div id="urvanov-syntax-highlighter-610fea28b88d7675861373" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88d7675861373-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88d7675861373-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88d7675861373-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88d7675861373-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88d7675861373-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88d7675861373-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88d7675861373-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88d7675861373-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88d7675861373-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88d7675861373-10">10</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88d7675861373-1" class="crayon-line"><span class="crayon-p"># Display the facets overview visualization for this data# Displ </span></div> <div id="urvanov-syntax-highlighter-610fea28b88d7675861373-2" class="crayon-line crayon-striped-line"><span class="crayon-e">from </span><span class="crayon-v">IPython</span><span class="crayon-sy">.</span><span class="crayon-v">core</span><span class="crayon-sy">.</span><span class="crayon-e">display </span><span class="crayon-e">import </span><span class="crayon-v">display</span><span class="crayon-sy">,</span> <span class="crayon-e">HTML</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d7675861373-3" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea28b88d7675861373-4" class="crayon-line crayon-striped-line"><span class="crayon-v">HTML_TEMPLATE</span> <span class="crayon-o">=</span> <span class="crayon-s">""</span><span class="crayon-s">"&amp;lt;link rel="</span><span class="crayon-i">import</span><span class="crayon-s">" href="</span><span class="crayon-o">/</span><span class="crayon-v">nbextensions</span><span class="crayon-o">/</span><span class="crayon-v">facets</span><span class="crayon-o">-</span><span class="crayon-v">dist</span><span class="crayon-o">/</span><span class="crayon-v">facets</span><span class="crayon-o">-</span><span class="crayon-v">jupyter</span><span class="crayon-sy">.</span><span class="crayon-i">html</span><span class="crayon-s">" &amp;gt;</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d7675861373-5" class="crayon-line"><span class="crayon-s">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;lt;facets-overview id="</span><span class="crayon-i">elem</span><span class="crayon-s">"&amp;gt;&amp;lt;/facets-overview&amp;gt;</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d7675861373-6" class="crayon-line crayon-striped-line"><span class="crayon-s">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;lt;script&amp;gt;</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d7675861373-7" class="crayon-line"><span class="crayon-s">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.querySelector("</span><span class="crayon-p">#elem").protoInput = "{protostr}";</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d7675861373-8" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-o">&amp;</span><span class="crayon-v">lt</span><span class="crayon-sy">;</span><span class="crayon-o">/</span><span class="crayon-v">script</span><span class="crayon-o">&amp;</span><span class="crayon-v">gt</span><span class="crayon-sy">;</span><span class="crayon-s">""</span>"</div> <div id="urvanov-syntax-highlighter-610fea28b88d7675861373-9" class="crayon-line"><span class="crayon-v">html</span> <span class="crayon-o">=</span> <span class="crayon-v">HTML_TEMPLATE</span><span class="crayon-sy">.</span><span class="crayon-e">format</span><span class="crayon-sy">(</span><span class="crayon-v">protostr</span><span class="crayon-o">=</span><span class="crayon-v">protostr</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d7675861373-10" class="crayon-line crayon-striped-line"><span class="crayon-e">display</span><span class="crayon-sy">(</span><span class="crayon-e">HTML</span><span class="crayon-sy">(</span><span class="crayon-v">html</span><span class="crayon-sy">)</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <h3 id="ftoc-heading-6" class="ftwp-heading">Facets Deep Dive</h3> <p>Để mở Deep Dive, bạn cần chuyển đổi dữ liệu sang định dạng json. Pandas l&agrave; một lựa chọn để l&agrave;m điều đ&oacute;. Bạn c&oacute; thể sử dụng to_json sau tập dữ liệu Pandas.</p> <p>D&ograve;ng m&atilde; đầu ti&ecirc;n xử l&yacute; k&iacute;ch thước của tập dữ liệu.</p> <div id="urvanov-syntax-highlighter-610fea28b88d9934068274" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88d9934068274-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88d9934068274-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88d9934068274-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88d9934068274-1" class="crayon-line"><span class="crayon-v">df</span><span class="crayon-sy">[</span><span class="crayon-s">'Q_PRICE'</span><span class="crayon-sy">]</span> <span class="crayon-o">=</span><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">qcut</span><span class="crayon-sy">(</span><span class="crayon-v">df</span><span class="crayon-sy">[</span><span class="crayon-s">'PRICE'</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-cn">4</span><span class="crayon-sy">,</span> <span class="crayon-v">labels</span><span class="crayon-o">=</span><span class="crayon-sy">[</span><span class="crayon-s">"Lowest"</span><span class="crayon-sy">,</span> <span class="crayon-s">"Low"</span><span class="crayon-sy">,</span> <span class="crayon-s">"Upper"</span><span class="crayon-sy">,</span> <span class="crayon-s">"upper_plus"</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d9934068274-2" class="crayon-line crayon-striped-line"><span class="crayon-v">sprite_size</span> <span class="crayon-o">=</span> <span class="crayon-cn">32</span> <span class="crayon-st">if</span> <span class="crayon-e">len</span><span class="crayon-sy">(</span><span class="crayon-v">df</span><span class="crayon-sy">.</span><span class="crayon-v">index</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">50000</span> <span class="crayon-st">else</span> <span class="crayon-cn">64</span></div> <div id="urvanov-syntax-highlighter-610fea28b88d9934068274-3" class="crayon-line"><span class="crayon-v">jsonstr</span> <span class="crayon-o">=</span> <span class="crayon-v">df</span><span class="crayon-sy">.</span><span class="crayon-e">to_json</span><span class="crayon-sy">(</span><span class="crayon-v">orient</span><span class="crayon-o">=</span><span class="crayon-s">'records'</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Đoạn m&atilde; dưới đ&acirc;y đến từ Google GitHub. Sau khi bạn chạy m&atilde;, bạn sẽ c&oacute; thể thấy điều n&agrave;y:</p> <p><img class="aligncenter size-full wp-image-7947 disappear appear" src="../../wp-content/uploads/2021/01/082918_1226_LinearRegre10.png" sizes="(max-width: 627px) 100vw, 627px" srcset="https://old.tek4.vn/wp-content/uploads/2021/01/082918_1226_LinearRegre10.png 627w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_1226_LinearRegre10-300x178.png 300w" alt="" width="627" height="371" loading="lazy" /></p> <div id="urvanov-syntax-highlighter-610fea28b88da096646097" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88da096646097-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88da096646097-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88da096646097-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88da096646097-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88da096646097-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88da096646097-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88da096646097-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88da096646097-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88da096646097-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88da096646097-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88da096646097-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88da096646097-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88da096646097-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88da096646097-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88da096646097-15">15</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88da096646097-1" class="crayon-line"><span class="crayon-p"># Display thde Dive visualization for this data</span></div> <div id="urvanov-syntax-highlighter-610fea28b88da096646097-2" class="crayon-line crayon-striped-line"><span class="crayon-e">from </span><span class="crayon-v">IPython</span><span class="crayon-sy">.</span><span class="crayon-v">core</span><span class="crayon-sy">.</span><span class="crayon-e">display </span><span class="crayon-e">import </span><span class="crayon-v">display</span><span class="crayon-sy">,</span> <span class="crayon-i">HTML</span></div> <div id="urvanov-syntax-highlighter-610fea28b88da096646097-3" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea28b88da096646097-4" class="crayon-line crayon-striped-line"><span class="crayon-p"># Create Facets template&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fea28b88da096646097-5" class="crayon-line"><span class="crayon-v">HTML_TEMPLATE</span> <span class="crayon-o">=</span> <span class="crayon-s">""</span><span class="crayon-s">"&amp;lt;link rel="</span><span class="crayon-i">import</span><span class="crayon-s">" href="</span><span class="crayon-o">/</span><span class="crayon-v">nbextensions</span><span class="crayon-o">/</span><span class="crayon-v">facets</span><span class="crayon-o">-</span><span class="crayon-v">dist</span><span class="crayon-o">/</span><span class="crayon-v">facets</span><span class="crayon-o">-</span><span class="crayon-v">jupyter</span><span class="crayon-sy">.</span><span class="crayon-i">html</span><span class="crayon-s">"&amp;gt;</span></div> <div id="urvanov-syntax-highlighter-610fea28b88da096646097-6" class="crayon-line crayon-striped-line"><span class="crayon-s">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;lt;facets-dive sprite-image-width="</span><span class="crayon-sy">{</span><span class="crayon-v">sprite_size</span><span class="crayon-sy">}</span><span class="crayon-s">" sprite-image-height="</span><span class="crayon-sy">{</span><span class="crayon-v">sprite_size</span><span class="crayon-sy">}</span><span class="crayon-s">" id="</span><span class="crayon-i">elem</span><span class="crayon-s">" height="</span><span class="crayon-cn">600</span><span class="crayon-s">"&amp;gt;&amp;lt;/facets-dive&amp;gt;</span></div> <div id="urvanov-syntax-highlighter-610fea28b88da096646097-7" class="crayon-line"><span class="crayon-s">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&amp;lt;script&amp;gt;</span></div> <div id="urvanov-syntax-highlighter-610fea28b88da096646097-8" class="crayon-line crayon-striped-line"><span class="crayon-s">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.querySelector("</span><span class="crayon-p">#elem").data = {jsonstr};</span></div> <div id="urvanov-syntax-highlighter-610fea28b88da096646097-9" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-o">&amp;</span><span class="crayon-v">lt</span><span class="crayon-sy">;</span><span class="crayon-o">/</span><span class="crayon-v">script</span><span class="crayon-o">&amp;</span><span class="crayon-v">gt</span><span class="crayon-sy">;</span><span class="crayon-s">""</span>"</div> <div id="urvanov-syntax-highlighter-610fea28b88da096646097-10" class="crayon-line crayon-striped-line"></div> <div id="urvanov-syntax-highlighter-610fea28b88da096646097-11" class="crayon-line"><span class="crayon-p"># Load the json dataset and the sprite_size into the template</span></div> <div id="urvanov-syntax-highlighter-610fea28b88da096646097-12" class="crayon-line crayon-striped-line"><span class="crayon-v">html</span> <span class="crayon-o">=</span> <span class="crayon-v">HTML_TEMPLATE</span><span class="crayon-sy">.</span><span class="crayon-e">format</span><span class="crayon-sy">(</span><span class="crayon-v">jsonstr</span><span class="crayon-o">=</span><span class="crayon-v">jsonstr</span><span class="crayon-sy">,</span> <span class="crayon-v">sprite_size</span><span class="crayon-o">=</span><span class="crayon-v">sprite_size</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88da096646097-13" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea28b88da096646097-14" class="crayon-line crayon-striped-line"><span class="crayon-p"># Display the template</span></div> <div id="urvanov-syntax-highlighter-610fea28b88da096646097-15" class="crayon-line"><span class="crayon-e">display</span><span class="crayon-sy">(</span><span class="crayon-e">HTML</span><span class="crayon-sy">(</span><span class="crayon-v">html</span><span class="crayon-sy">)</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Bạn quan t&acirc;m xem c&oacute; mối li&ecirc;n hệ n&agrave;o giữa tỷ lệ ng&agrave;nh, nồng độ oxit, khoảng c&aacute;ch đến trung t&acirc;m việc l&agrave;m v&agrave; gi&aacute; cả của ng&ocirc;i nh&agrave; hay kh&ocirc;ng.</p> <p>Đối với điều đ&oacute;, trước ti&ecirc;n bạn ph&acirc;n chia dữ liệu theo phạm vi ng&agrave;nh v&agrave; m&agrave;u sắc:</p> <ul> <li>Chọn faceting X v&agrave; chọn INDUS.</li> <li>Chọn Display v&agrave; chọn DIS. N&oacute; sẽ t&ocirc; m&agrave;u c&aacute;c chấm với phần tư của gi&aacute; nh&agrave;</li> </ul> <p>Ở đ&acirc;y, m&agrave;u tối hơn c&oacute; nghĩa l&agrave; khoảng c&aacute;ch đến trung t&acirc;m việc l&agrave;m đầu ti&ecirc;n l&agrave; xa. Cho đến nay, n&oacute; lại hiển thị những g&igrave; bạn biết, tỷ lệ ng&agrave;nh thấp hơn, gi&aacute; cao hơn. B&acirc;y giờ bạn c&oacute; thể xem bảng ph&acirc;n t&iacute;ch theo INDUX, NOX.</p> <ul> <li>Chọn faceting Y v&agrave; chọn NOX.</li> </ul> <p>B&acirc;y giờ bạn c&oacute; thể thấy ng&ocirc;i nh&agrave; xa trung t&acirc;m việc l&agrave;m đầu ti&ecirc;n c&oacute; tỷ trọng ng&agrave;nh thấp nhất v&agrave; do đ&oacute; c&oacute; nồng độ oxit thấp nhất. Nếu bạn chọn hiển thị loại với Q_PRICE v&agrave; thu ph&oacute;ng g&oacute;c dưới b&ecirc;n tr&aacute;i, bạn c&oacute; thể xem loại gi&aacute; đ&oacute;.</p> <p>Bạn c&oacute; một gợi &yacute; kh&aacute;c rằng sự tương t&aacute;c giữa IND, NOX v&agrave; DIS c&oacute; thể l&agrave; những ứng cử vi&ecirc;n tốt để cải thiện m&ocirc; h&igrave;nh.</p> <h3 id="ftoc-heading-7" class="ftwp-heading">TensorFlow</h3> <p>Trong phần n&agrave;y, bạn sẽ ước t&iacute;nh bộ ph&acirc;n loại tuyến t&iacute;nh với TensorFlow estimators API.</p> <p>Bạn sẽ tiến h&agrave;nh như sau:</p> <ul> <li>Chuẩn bị dữ liệu</li> <li>Ước t&iacute;nh m&ocirc; h&igrave;nh điểm chuẩn: Kh&ocirc;ng c&oacute; tương t&aacute;c</li> <li>Ước t&iacute;nh một m&ocirc; h&igrave;nh c&oacute; tương t&aacute;c</li> </ul> <p>H&atilde;y nhớ rằng, mục ti&ecirc;u của học m&aacute;y l&agrave; giảm thiểu lỗi. Trong trường hợp n&agrave;y, m&ocirc; h&igrave;nh c&oacute; sai số b&igrave;nh phương trung b&igrave;nh thấp nhất sẽ thắng. TensorFlow estimators tự động t&iacute;nh to&aacute;n số liệu n&agrave;y.</p> <h4 id="ftoc-heading-8" class="ftwp-heading">Chuẩn bị dữ liệu</h4> <p>Trong hầu hết c&aacute;c trường hợp, bạn cần phải chuyển đổi dữ liệu của m&igrave;nh. Đ&oacute; l&agrave; l&yacute; do v&igrave; sao Facets Overview cần thiết. Từ thống k&ecirc; t&oacute;m tắt, bạn đ&atilde; thấy c&oacute; những ngoại lệ. Những gi&aacute; trị đ&oacute; ảnh hưởng đến c&aacute;c ước t&iacute;nh v&igrave; ch&uacute;ng kh&ocirc;ng giống với số liệu bạn đang ph&acirc;n t&iacute;ch. Những gi&aacute; trị đ&oacute; thường l&agrave;m sai lệch kết quả. V&iacute; dụ, một gi&aacute; trị ngoại lai dương c&oacute; xu hướng đ&aacute;nh gi&aacute; qu&aacute; cao hệ số.</p> <p>Một giải ph&aacute;p tốt để giải quyết vấn đề n&agrave;y l&agrave; chuẩn h&oacute;a biến. huẩn h&oacute;a c&oacute; nghĩa l&agrave; độ lệch chuẩn bằng 1 hoặc 0. Qu&aacute; tr&igrave;nh ti&ecirc;u chuẩn h&oacute;a bao gồm hai bước. Trước hết, n&oacute; trừ đi gi&aacute; trị trung b&igrave;nh của biến. Thứ hai, n&oacute; chia cho phương sai để ph&acirc;n phối c&oacute; phương sai đơn vị.</p> <p>Thư viện sklearn rất hữu &iacute;ch để chuẩn h&oacute;a c&aacute;c biến. Bạn c&oacute; thể sử dụng tiền xử l&yacute; m&ocirc;-đun với quy m&ocirc; đối tượng cho mục đ&iacute;ch n&agrave;y.</p> <p>H&atilde;y sử dụng h&agrave;m b&ecirc;n dưới để chia tỷ lệ tập dữ liệu. Lưu &yacute; rằng kh&ocirc;ng chia tỷ lệ cột nh&atilde;n v&agrave; c&aacute;c biến ph&acirc;n loại.</p> <div id="urvanov-syntax-highlighter-610fea28b88de193023248" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88de193023248-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88de193023248-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88de193023248-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88de193023248-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88de193023248-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88de193023248-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88de193023248-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88de193023248-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88de193023248-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88de193023248-10">10</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88de193023248-1" class="crayon-line"><span class="crayon-e">from </span><span class="crayon-e">sklearn </span><span class="crayon-e">import </span><span class="crayon-e">preprocessing</span></div> <div id="urvanov-syntax-highlighter-610fea28b88de193023248-2" class="crayon-line crayon-striped-line"><span class="crayon-e">def </span><span class="crayon-e">standardize_data</span><span class="crayon-sy">(</span><span class="crayon-v">df</span><span class="crayon-sy">)</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fea28b88de193023248-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">X_scaled</span> <span class="crayon-o">=</span> <span class="crayon-v">preprocessing</span><span class="crayon-sy">.</span><span class="crayon-e">scale</span><span class="crayon-sy">(</span><span class="crayon-v">df</span><span class="crayon-sy">[</span><span class="crayon-sy">[</span><span class="crayon-s">'CRIM'</span><span class="crayon-sy">,</span> <span class="crayon-s">'ZN'</span><span class="crayon-sy">,</span> <span class="crayon-s">'INDUS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'NOX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'RM'</span><span class="crayon-sy">,</span> <span class="crayon-s">'AGE'</span><span class="crayon-sy">,</span> <span class="crayon-s">'DIS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'RAD'</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88de193023248-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-s">'TAX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'PTRATIO'</span><span class="crayon-sy">,</span> <span class="crayon-s">'B'</span><span class="crayon-sy">,</span> <span class="crayon-s">'LSTAT'</span><span class="crayon-sy">]</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88de193023248-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">X_scaled_df</span> <span class="crayon-o">=</span> <span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">DataFrame</span><span class="crayon-sy">(</span><span class="crayon-v">X_scaled</span><span class="crayon-sy">,</span> <span class="crayon-v">columns</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-s">'CRIM'</span><span class="crayon-sy">,</span> <span class="crayon-s">'ZN'</span><span class="crayon-sy">,</span> <span class="crayon-s">'INDUS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'NOX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'RM'</span><span class="crayon-sy">,</span> <span class="crayon-s">'AGE'</span><span class="crayon-sy">,</span> <span class="crayon-s">'DIS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'RAD'</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88de193023248-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-s">'TAX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'PTRATIO'</span><span class="crayon-sy">,</span> <span class="crayon-s">'B'</span><span class="crayon-sy">,</span> <span class="crayon-s">'LSTAT'</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88de193023248-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">df_scale</span> <span class="crayon-o">=</span> <span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">concat</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-v">X_scaled_df</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88de193023248-8" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">df</span><span class="crayon-sy">[</span><span class="crayon-s">'CHAS'</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88de193023248-9" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">df</span><span class="crayon-sy">[</span><span class="crayon-s">'PRICE'</span><span class="crayon-sy">]</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span><span class="crayon-v">axis</span><span class="crayon-o">=</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span> <span class="crayon-v">join</span><span class="crayon-o">=</span><span class="crayon-s">'inner'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88de193023248-10" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">return</span> <span class="crayon-v">df_scale</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Bạn c&oacute; thể sử dụng h&agrave;m để x&acirc;y dựng tập hợp train/test set.</p> <div id="urvanov-syntax-highlighter-610fea28b88e2394833994" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88e2394833994-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88e2394833994-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88e2394833994-1" class="crayon-line"><span class="crayon-v">df_train_scale</span> <span class="crayon-o">=</span> <span class="crayon-e">standardize_data</span><span class="crayon-sy">(</span><span class="crayon-v">df_train</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88e2394833994-2" class="crayon-line crayon-striped-line"><span class="crayon-v">df_test_scale</span> <span class="crayon-o">=</span> <span class="crayon-e">standardize_data</span><span class="crayon-sy">(</span><span class="crayon-v">df_test</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <h4 id="ftoc-heading-9" class="ftwp-heading">Hồi quy cơ bản: Benchmark</h4> <p>Trước hết, bạn đ&agrave;o tạo v&agrave; thử nghiệm một m&ocirc; h&igrave;nh m&agrave; kh&ocirc;ng c&oacute; sự tương t&aacute;c. Mục đ&iacute;ch l&agrave; để xem chỉ số hiệu suất của m&ocirc; h&igrave;nh.</p> <p>C&aacute;ch huấn luyện m&ocirc; h&igrave;nh đ&uacute;ng như hướng dẫn tr&ecirc;n API cấp cao. Bạn sẽ sử dụng c&ocirc;ng cụ TensorFlow estimator LinearRegressor.</p> <p>Bạn cần chọn:</p> <ul> <li>C&aacute;c đặc trưng để đưa v&agrave;o m&ocirc; h&igrave;nh</li> <li>Biến đổi c&aacute;c đặc trưng</li> <li>X&acirc;y dựng bộ hồi quy tuyến t&iacute;nh</li> <li>x&acirc;y dựng h&agrave;m input_fn</li> <li>Đ&agrave;o tạo m&ocirc; h&igrave;nh</li> <li>Kiểm tra m&ocirc; h&igrave;nh</li> </ul> <p>Sử dụng tất cả c&aacute;c biến trong tập dữ liệu để huấn luyện m&ocirc; h&igrave;nh. Tổng cộng, c&oacute; c&aacute;c biến li&ecirc;n tục n&acirc;ng cao v&agrave; một biến ph&acirc;n loại.</p> <div id="urvanov-syntax-highlighter-610fea28b88e6301548380" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88e6301548380-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88e6301548380-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88e6301548380-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88e6301548380-4">4</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88e6301548380-1" class="crayon-line"><span class="crayon-p">## Add features to the bucket: </span></div> <div id="urvanov-syntax-highlighter-610fea28b88e6301548380-2" class="crayon-line crayon-striped-line"><span class="crayon-p">### Define continuous list</span></div> <div id="urvanov-syntax-highlighter-610fea28b88e6301548380-3" class="crayon-line"><span class="crayon-v">CONTI_FEATURES</span><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-s">'CRIM'</span><span class="crayon-sy">,</span> <span class="crayon-s">'ZN'</span><span class="crayon-sy">,</span> <span class="crayon-s">'INDUS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'NOX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'RM'</span><span class="crayon-sy">,</span> <span class="crayon-s">'AGE'</span><span class="crayon-sy">,</span> <span class="crayon-s">'DIS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'RAD'</span><span class="crayon-sy">,</span><span class="crayon-s">'TAX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'PTRATIO'</span><span class="crayon-sy">,</span> <span class="crayon-s">'B'</span><span class="crayon-sy">,</span> <span class="crayon-s">'LSTAT'</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea28b88e6301548380-4" class="crayon-line crayon-striped-line"><span class="crayon-v">CATE_FEATURES</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-s">'CHAS'</span><span class="crayon-sy">]</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Cần chuyển đổi c&aacute;c đặc trưng th&agrave;nh cột số hoặc cột ph&acirc;n loại.</p> <div id="urvanov-syntax-highlighter-610fea28b88e8329745715" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88e8329745715-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88e8329745715-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88e8329745715-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88e8329745715-1" class="crayon-line"><span class="crayon-v">continuous_features</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">feature_column</span><span class="crayon-sy">.</span><span class="crayon-e">numeric_column</span><span class="crayon-sy">(</span><span class="crayon-v">k</span><span class="crayon-sy">)</span> <span class="crayon-st">for</span> <span class="crayon-i">k</span> <span class="crayon-st">in</span> <span class="crayon-v">CONTI_FEATURES</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea28b88e8329745715-2" class="crayon-line crayon-striped-line"><span class="crayon-p">#categorical_features = tf.feature_column.categorical_column_with_hash_bucket(CATE_FEATURES, hash_bucket_size=1000)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88e8329745715-3" class="crayon-line"><span class="crayon-v">categorical_features</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">feature_column</span><span class="crayon-sy">.</span><span class="crayon-e">categorical_column_with_vocabulary_list</span><span class="crayon-sy">(</span><span class="crayon-s">'CHAS'</span><span class="crayon-sy">,</span> <span class="crayon-sy">[</span><span class="crayon-s">'yes'</span><span class="crayon-sy">,</span><span class="crayon-s">'no'</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span><span class="crayon-sy">]</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Tạo m&ocirc; h&igrave;nh tuyến t&iacute;nh với linearRegressor v&agrave; lưu m&ocirc; h&igrave;nh v&agrave;o thư mục train_Boston</p> <div id="urvanov-syntax-highlighter-610fea28b88ea111268750" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88ea111268750-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88ea111268750-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88ea111268750-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88ea111268750-1" class="crayon-line"><span class="crayon-v">model</span> <span class="crayon-o">=</span> <span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">estimator</span><span class="crayon-sy">.</span><span class="crayon-e">LinearRegressor</span><span class="crayon-sy">(</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fea28b88ea111268750-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">model_dir</span><span class="crayon-o">=</span><span class="crayon-s">"train_Boston"</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fea28b88ea111268750-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">feature_columns</span><span class="crayon-o">=</span><span class="crayon-v">categorical_features</span> <span class="crayon-o">+</span> <span class="crayon-v">continuous_features</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fea28b88ec893217378" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88ec893217378-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88ec893217378-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88ec893217378-1" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Using </span><span class="crayon-st">default</span> <span class="crayon-v">config</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b88ec893217378-2" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Using </span><span class="crayon-v">config</span><span class="crayon-o">:</span> <span class="crayon-sy">{</span><span class="crayon-s">'_model_dir'</span><span class="crayon-o">:</span> <span class="crayon-s">'train_Boston'</span><span class="crayon-sy">,</span> <span class="crayon-s">'_tf_random_seed'</span><span class="crayon-o">:</span> <span class="crayon-v">None</span><span class="crayon-sy">,</span> <span class="crayon-s">'_save_summary_steps'</span><span class="crayon-o">:</span> <span class="crayon-cn">100</span><span class="crayon-sy">,</span> <span class="crayon-s">'_save_checkpoints_steps'</span><span class="crayon-o">:</span> <span class="crayon-v">None</span><span class="crayon-sy">,</span> <span class="crayon-s">'_save_checkpoints_secs'</span><span class="crayon-o">:</span> <span class="crayon-cn">600</span><span class="crayon-sy">,</span> <span class="crayon-s">'_session_config'</span><span class="crayon-o">:</span> <span class="crayon-v">None</span><span class="crayon-sy">,</span> <span class="crayon-s">'_keep_checkpoint_max'</span><span class="crayon-o">:</span> <span class="crayon-cn">5</span><span class="crayon-sy">,</span> <span class="crayon-s">'_keep_checkpoint_every_n_hours'</span><span class="crayon-o">:</span> <span class="crayon-cn">10000</span><span class="crayon-sy">,</span> <span class="crayon-s">'_log_step_count_steps'</span><span class="crayon-o">:</span> <span class="crayon-cn">100</span><span class="crayon-sy">,</span> <span class="crayon-s">'_train_distribute'</span><span class="crayon-o">:</span> <span class="crayon-v">None</span><span class="crayon-sy">,</span> <span class="crayon-s">'_service'</span><span class="crayon-o">:</span> <span class="crayon-v">None</span><span class="crayon-sy">,</span> <span class="crayon-s">'_cluster_spec'</span><span class="crayon-o">:</span> <span class="crayon-o">&amp;</span><span class="crayon-v">lt</span><span class="crayon-sy">;</span><span class="crayon-v">tensorflow</span><span class="crayon-sy">.</span><span class="crayon-v">python</span><span class="crayon-sy">.</span><span class="crayon-v">training</span><span class="crayon-sy">.</span><span class="crayon-v">server_lib</span><span class="crayon-sy">.</span><span class="crayon-e">ClusterSpec </span><span class="crayon-t">object</span> <span class="crayon-i">at</span> <span class="crayon-cn">0x1a19e76ac8</span><span class="crayon-o">&amp;</span><span class="crayon-v">gt</span><span class="crayon-sy">;</span><span class="crayon-sy">,</span> <span class="crayon-s">'_task_type'</span><span class="crayon-o">:</span> <span class="crayon-s">'worker'</span><span class="crayon-sy">,</span> <span class="crayon-s">'_task_id'</span><span class="crayon-o">:</span> <span class="crayon-cn">0</span><span class="crayon-sy">,</span> <span class="crayon-s">'_global_id_in_cluster'</span><span class="crayon-o">:</span> <span class="crayon-cn">0</span><span class="crayon-sy">,</span> <span class="crayon-s">'_master'</span><span class="crayon-o">:</span> <span class="crayon-s">''</span><span class="crayon-sy">,</span> <span class="crayon-s">'_evaluation_master'</span><span class="crayon-o">:</span> <span class="crayon-s">''</span><span class="crayon-sy">,</span> <span class="crayon-s">'_is_chief'</span><span class="crayon-o">:</span> <span class="crayon-t">True</span><span class="crayon-sy">,</span> <span class="crayon-s">'_num_ps_replicas'</span><span class="crayon-o">:</span> <span class="crayon-cn">0</span><span class="crayon-sy">,</span> <span class="crayon-s">'_num_worker_replicas'</span><span class="crayon-o">:</span> <span class="crayon-cn">1</span><span class="crayon-sy">}</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Mỗi cột trong dữ liệu huấn luyện hoặc kiểm tra được chuyển đổi th&agrave;nh một Tensor với h&agrave;m get_input_fn</p> <div id="urvanov-syntax-highlighter-610fea28b88ee692235060" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88ee692235060-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88ee692235060-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88ee692235060-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88ee692235060-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88ee692235060-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88ee692235060-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88ee692235060-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88ee692235060-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88ee692235060-9">9</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88ee692235060-1" class="crayon-line"><span class="crayon-v">FEATURES</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-s">'CRIM'</span><span class="crayon-sy">,</span> <span class="crayon-s">'ZN'</span><span class="crayon-sy">,</span> <span class="crayon-s">'INDUS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'NOX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'RM'</span><span class="crayon-sy">,</span> <span class="crayon-s">'AGE'</span><span class="crayon-sy">,</span> <span class="crayon-s">'DIS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'RAD'</span><span class="crayon-sy">,</span><span class="crayon-s">'TAX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'PTRATIO'</span><span class="crayon-sy">,</span> <span class="crayon-s">'B'</span><span class="crayon-sy">,</span> <span class="crayon-s">'LSTAT'</span><span class="crayon-sy">,</span> <span class="crayon-s">'CHAS'</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea28b88ee692235060-2" class="crayon-line crayon-striped-line"><span class="crayon-v">LABEL</span><span class="crayon-o">=</span> <span class="crayon-s">'PRICE'</span></div> <div id="urvanov-syntax-highlighter-610fea28b88ee692235060-3" class="crayon-line"><span class="crayon-e">def </span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">data_set</span><span class="crayon-sy">,</span> <span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">None</span><span class="crayon-sy">,</span> <span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span> <span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">True</span><span class="crayon-sy">)</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fea28b88ee692235060-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">return</span> <span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">estimator</span><span class="crayon-sy">.</span><span class="crayon-v">inputs</span><span class="crayon-sy">.</span><span class="crayon-e">pandas_input_fn</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea28b88ee692235060-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">x</span><span class="crayon-o">=</span><span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">DataFrame</span><span class="crayon-sy">(</span><span class="crayon-sy">{</span><span class="crayon-v">k</span><span class="crayon-o">:</span> <span class="crayon-v">data_set</span><span class="crayon-sy">[</span><span class="crayon-v">k</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-e">values </span><span class="crayon-st">for</span> <span class="crayon-i">k</span> <span class="crayon-st">in</span> <span class="crayon-v">FEATURES</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88ee692235060-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">y</span> <span class="crayon-o">=</span> <span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">Series</span><span class="crayon-sy">(</span><span class="crayon-v">data_set</span><span class="crayon-sy">[</span><span class="crayon-v">LABEL</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-v">values</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88ee692235060-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">batch_size</span><span class="crayon-o">=</span><span class="crayon-v">n_batch</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fea28b88ee692235060-8" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">num_epochs</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88ee692235060-9" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-v">shuffle</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Ước t&iacute;nh m&ocirc; h&igrave;nh tr&ecirc;n train data.</p> <div id="urvanov-syntax-highlighter-610fea28b88ef246264334" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88ef246264334-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88ef246264334-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88ef246264334-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88ef246264334-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88ef246264334-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88ef246264334-1" class="crayon-line"><span class="crayon-v">model</span><span class="crayon-sy">.</span><span class="crayon-e">train</span><span class="crayon-sy">(</span><span class="crayon-v">input_fn</span><span class="crayon-o">=</span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">df_train_scale</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88ef246264334-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">None</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88ef246264334-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88ef246264334-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">False</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88ef246264334-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">steps</span><span class="crayon-o">=</span><span class="crayon-cn">1000</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88f1013463450-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-20">20</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-21">21</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-22">22</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-23">23</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-24">24</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-25">25</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-26">26</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-27">27</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-28">28</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-29">29</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-30">30</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f1013463450-31">31</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-1" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Calling </span><span class="crayon-v">model_fn</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-2" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Done </span><span class="crayon-e">calling </span><span class="crayon-v">model_fn</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-3" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Create </span><span class="crayon-v">CheckpointSaverHook</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-4" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Graph </span><span class="crayon-e">was </span><span class="crayon-v">finalized</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-5" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Running </span><span class="crayon-v">local_init_op</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-6" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Done </span><span class="crayon-e">running </span><span class="crayon-v">local_init_op</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-7" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Saving </span><span class="crayon-e">checkpoints </span><span class="crayon-st">for</span> <span class="crayon-cn">1</span> <span class="crayon-e">into </span><span class="crayon-v">train_Boston</span><span class="crayon-o">/</span><span class="crayon-v">model</span><span class="crayon-sy">.</span><span class="crayon-v">ckpt</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-8" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">56417.703</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">1</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-9" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">144.457</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-10" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">76982.734</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">101</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.697</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-11" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">258.392</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-12" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">21246.334</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">201</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.383</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-13" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">227.998</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-14" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">30534.78</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">301</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.439</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-15" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">210.739</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-16" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">36794.5</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">401</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.477</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-17" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">234.237</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-18" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">8562.981</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">501</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.425</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-19" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">238.1</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-20" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">34465.08</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">601</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.420</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-21" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">237.934</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-22" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">12241.709</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">701</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.420</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-23" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">220.687</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-24" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">11019.228</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">801</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.453</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-25" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">232.702</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-26" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">24049.678</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">901</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.432</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-27" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Saving </span><span class="crayon-e">checkpoints </span><span class="crayon-st">for</span> <span class="crayon-cn">1000</span> <span class="crayon-e">into </span><span class="crayon-v">train_Boston</span><span class="crayon-o">/</span><span class="crayon-v">model</span><span class="crayon-sy">.</span><span class="crayon-v">ckpt</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-28" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Loss </span><span class="crayon-st">for</span> <span class="crayon-m">final</span> <span class="crayon-v">step</span><span class="crayon-o">:</span> <span class="crayon-cn">23228.568.</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-29" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-30" class="crayon-line crayon-striped-line"></div> <div id="urvanov-syntax-highlighter-610fea28b88f1013463450-31" class="crayon-line"><span class="crayon-o">&amp;</span><span class="crayon-v">lt</span><span class="crayon-sy">;</span><span class="crayon-v">tensorflow</span><span class="crayon-sy">.</span><span class="crayon-v">python</span><span class="crayon-sy">.</span><span class="crayon-v">estimator</span><span class="crayon-sy">.</span><span class="crayon-v">canned</span><span class="crayon-sy">.</span><span class="crayon-v">linear</span><span class="crayon-sy">.</span><span class="crayon-e">LinearRegressor </span><span class="crayon-i">at</span> <span class="crayon-cn">0x1a19e76320</span><span class="crayon-o">&amp;</span><span class="crayon-v">gt</span><span class="crayon-sy">;</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Cuối c&ugrave;ng, ước t&iacute;nh hiệu suất của m&ocirc; h&igrave;nh tr&ecirc;n bộ thử nghiệm</p> <div id="urvanov-syntax-highlighter-610fea28b88f6086409212" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88f6086409212-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f6086409212-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f6086409212-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f6086409212-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f6086409212-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88f6086409212-1" class="crayon-line"><span class="crayon-v">model</span><span class="crayon-sy">.</span><span class="crayon-e">evaluate</span><span class="crayon-sy">(</span><span class="crayon-v">input_fn</span><span class="crayon-o">=</span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">df_test_scale</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f6086409212-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f6086409212-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f6086409212-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">False</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f6086409212-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">steps</span><span class="crayon-o">=</span><span class="crayon-cn">1000</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fea28b88f7808916135" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88f7808916135-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f7808916135-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f7808916135-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f7808916135-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f7808916135-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f7808916135-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f7808916135-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f7808916135-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f7808916135-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f7808916135-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88f7808916135-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88f7808916135-12">12</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88f7808916135-1" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Calling </span><span class="crayon-v">model_fn</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f7808916135-2" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Done </span><span class="crayon-e">calling </span><span class="crayon-v">model_fn</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f7808916135-3" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Starting </span><span class="crayon-e">evaluation </span><span class="crayon-i">at</span> <span class="crayon-cn">2018</span><span class="crayon-o">-</span><span class="crayon-cn">05</span><span class="crayon-o">-</span><span class="crayon-cn">29</span><span class="crayon-o">-</span><span class="crayon-cn">02</span><span class="crayon-o">:</span><span class="crayon-cn">40</span><span class="crayon-o">:</span><span class="crayon-cn">43</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f7808916135-4" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Graph </span><span class="crayon-e">was </span><span class="crayon-v">finalized</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f7808916135-5" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Restoring </span><span class="crayon-e">parameters </span><span class="crayon-e">from </span><span class="crayon-v">train_Boston</span><span class="crayon-o">/</span><span class="crayon-v">model</span><span class="crayon-sy">.</span><span class="crayon-v">ckpt</span><span class="crayon-o">-</span><span class="crayon-cn">1000</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f7808916135-6" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Running </span><span class="crayon-v">local_init_op</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f7808916135-7" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Done </span><span class="crayon-e">running </span><span class="crayon-v">local_init_op</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f7808916135-8" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Finished </span><span class="crayon-e">evaluation </span><span class="crayon-i">at</span> <span class="crayon-cn">2018</span><span class="crayon-o">-</span><span class="crayon-cn">05</span><span class="crayon-o">-</span><span class="crayon-cn">29</span><span class="crayon-o">-</span><span class="crayon-cn">02</span><span class="crayon-o">:</span><span class="crayon-cn">40</span><span class="crayon-o">:</span><span class="crayon-cn">43</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f7808916135-9" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Saving </span><span class="crayon-e">dict </span><span class="crayon-st">for</span> <span class="crayon-m">global</span> <span class="crayon-i">step</span> <span class="crayon-cn">1000</span><span class="crayon-o">:</span> <span class="crayon-v">average_loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">86.89361</span><span class="crayon-sy">,</span> <span class="crayon-v">global_step</span> <span class="crayon-o">=</span> <span class="crayon-cn">1000</span><span class="crayon-sy">,</span> <span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">1650.9785</span></div> <div id="urvanov-syntax-highlighter-610fea28b88f7808916135-10" class="crayon-line crayon-striped-line"></div> <div id="urvanov-syntax-highlighter-610fea28b88f7808916135-11" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea28b88f7808916135-12" class="crayon-line crayon-striped-line"><span class="crayon-sy">{</span><span class="crayon-s">'average_loss'</span><span class="crayon-o">:</span> <span class="crayon-cn">86.89361</span><span class="crayon-sy">,</span> <span class="crayon-s">'global_step'</span><span class="crayon-o">:</span> <span class="crayon-cn">1000</span><span class="crayon-sy">,</span> <span class="crayon-s">'loss'</span><span class="crayon-o">:</span> <span class="crayon-cn">1650.9785</span><span class="crayon-sy">}</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Sự mất m&aacute;t của m&ocirc; h&igrave;nh l&agrave; 1650.</p> <h4 id="ftoc-heading-10" class="ftwp-heading">Cải thiện m&ocirc; h&igrave;nh</h4> <p>Đ&atilde; đến l&uacute;c xem liệu c&oacute; thể cải thiện m&ocirc; h&igrave;nh dự đo&aacute;n m&ocirc; h&igrave;nh hay kh&ocirc;ng.</p> <p>Bạn cần th&ecirc;m hai cột mới v&agrave;o mỗi tập dữ liệu: huấn luyện + kiểm tra. Sau khi c&aacute;c biến mới được tạo, bạn c&oacute; thể nối ch&uacute;ng với tập dữ liệu huấn luyện v&agrave; tập dữ liệu kiểm tra.</p> <p>Trước hết, bạn cần tạo một biến mới cho sự tương t&aacute;c giữa INDUS v&agrave; NOX. H&agrave;m b&ecirc;n dưới trả về hai khung dữ liệu, huấn luyện v&agrave; kiểm tra, với sự tương t&aacute;c giữa var_1 v&agrave; var_2, trong trường hợp của bạn l&agrave; INDUS v&agrave; NOX.</p> <div id="urvanov-syntax-highlighter-610fea28b88fa779156427" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88fa779156427-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88fa779156427-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88fa779156427-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88fa779156427-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88fa779156427-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88fa779156427-6">6</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88fa779156427-1" class="crayon-line"><span class="crayon-e">def </span><span class="crayon-e">interaction_term</span><span class="crayon-sy">(</span><span class="crayon-v">var_1</span><span class="crayon-sy">,</span> <span class="crayon-v">var_2</span><span class="crayon-sy">,</span> <span class="crayon-v">name</span><span class="crayon-sy">)</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fea28b88fa779156427-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">t_train</span> <span class="crayon-o">=</span> <span class="crayon-v">df_train_scale</span><span class="crayon-sy">[</span><span class="crayon-v">var_1</span><span class="crayon-sy">]</span><span class="crayon-o">*</span><span class="crayon-v">df_train_scale</span><span class="crayon-sy">[</span><span class="crayon-v">var_2</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea28b88fa779156427-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">train</span> <span class="crayon-o">=</span> <span class="crayon-v">t_train</span><span class="crayon-sy">.</span><span class="crayon-e">rename</span><span class="crayon-sy">(</span><span class="crayon-v">name</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88fa779156427-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">t_test</span> <span class="crayon-o">=</span> <span class="crayon-v">df_test_scale</span><span class="crayon-sy">[</span><span class="crayon-v">var_1</span><span class="crayon-sy">]</span><span class="crayon-o">*</span><span class="crayon-v">df_test_scale</span><span class="crayon-sy">[</span><span class="crayon-v">var_2</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea28b88fa779156427-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">test</span> <span class="crayon-o">=</span> <span class="crayon-v">t_test</span><span class="crayon-sy">.</span><span class="crayon-e">rename</span><span class="crayon-sy">(</span><span class="crayon-v">name</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88fa779156427-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">return</span> <span class="crayon-v">train</span><span class="crayon-sy">,</span> <span class="crayon-v">test</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Lưu trữ hai cột mới</p> <div id="urvanov-syntax-highlighter-610fea28b88fc573544808" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88fc573544808-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88fc573544808-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88fc573544808-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88fc573544808-1" class="crayon-line"><span class="crayon-v">interation_ind_ns_train</span><span class="crayon-sy">,</span> <span class="crayon-v">interation_ind_ns_test</span><span class="crayon-o">=</span> <span class="crayon-e">interaction_term</span><span class="crayon-sy">(</span><span class="crayon-s">'INDUS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'NOX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'INDUS_NOS'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88fc573544808-2" class="crayon-line crayon-striped-line"><span class="crayon-v">interation_ind_ns_train</span><span class="crayon-sy">.</span><span class="crayon-e">shape</span></div> <div id="urvanov-syntax-highlighter-610fea28b88fc573544808-3" class="crayon-line"><span class="crayon-sy">(</span><span class="crayon-cn">325</span><span class="crayon-sy">,</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Tiếp theo:</p> <div id="urvanov-syntax-highlighter-610fea28b88fd969861591" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b88fd969861591-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88fd969861591-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88fd969861591-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88fd969861591-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88fd969861591-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b88fd969861591-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b88fd969861591-7">7</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b88fd969861591-1" class="crayon-line"><span class="crayon-e">def </span><span class="crayon-e">triple_interaction_term</span><span class="crayon-sy">(</span><span class="crayon-v">var_1</span><span class="crayon-sy">,</span> <span class="crayon-v">var_2</span><span class="crayon-sy">,</span><span class="crayon-v">var_3</span><span class="crayon-sy">,</span> <span class="crayon-v">name</span><span class="crayon-sy">)</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fea28b88fd969861591-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">t_train</span> <span class="crayon-o">=</span> <span class="crayon-v">df_train_scale</span><span class="crayon-sy">[</span><span class="crayon-v">var_1</span><span class="crayon-sy">]</span><span class="crayon-o">*</span><span class="crayon-v">df_train_scale</span><span class="crayon-sy">[</span><span class="crayon-v">var_2</span><span class="crayon-sy">]</span><span class="crayon-o">*</span><span class="crayon-v">df_train_scale</span><span class="crayon-sy">[</span><span class="crayon-v">var_3</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea28b88fd969861591-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">train</span> <span class="crayon-o">=</span> <span class="crayon-v">t_train</span><span class="crayon-sy">.</span><span class="crayon-e">rename</span><span class="crayon-sy">(</span><span class="crayon-v">name</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88fd969861591-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">t_test</span> <span class="crayon-o">=</span> <span class="crayon-v">df_test_scale</span><span class="crayon-sy">[</span><span class="crayon-v">var_1</span><span class="crayon-sy">]</span><span class="crayon-o">*</span><span class="crayon-v">df_test_scale</span><span class="crayon-sy">[</span><span class="crayon-v">var_2</span><span class="crayon-sy">]</span><span class="crayon-o">*</span><span class="crayon-v">df_test_scale</span><span class="crayon-sy">[</span><span class="crayon-v">var_3</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea28b88fd969861591-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">test</span> <span class="crayon-o">=</span> <span class="crayon-v">t_test</span><span class="crayon-sy">.</span><span class="crayon-e">rename</span><span class="crayon-sy">(</span><span class="crayon-v">name</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b88fd969861591-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">return</span> <span class="crayon-v">train</span><span class="crayon-sy">,</span> <span class="crayon-e">test</span></div> <div id="urvanov-syntax-highlighter-610fea28b88fd969861591-7" class="crayon-line"><span class="crayon-v">interation_ind_ns_dis_train</span><span class="crayon-sy">,</span> <span class="crayon-v">interation_ind_ns_dis_test</span><span class="crayon-o">=</span> <span class="crayon-e">triple_interaction_term</span><span class="crayon-sy">(</span><span class="crayon-s">'INDUS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'NOX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'DIS'</span><span class="crayon-sy">,</span><span class="crayon-s">'INDUS_NOS_DIS'</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>B&acirc;y giờ bạn đ&atilde; c&oacute; tất cả c&aacute;c cột cần thiết, bạn c&oacute; thể th&ecirc;m ch&uacute;ng để đ&agrave;o tạo v&agrave; kiểm tra tập dữ liệu. Đặt t&ecirc;n cho hai khung dữ liệu mới n&agrave;y:</p> <ul> <li>df_train_new</li> <li>df_test_new</li> </ul> <div id="urvanov-syntax-highlighter-610fea28b8901942424899" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b8901942424899-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8901942424899-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8901942424899-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8901942424899-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8901942424899-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8901942424899-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8901942424899-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8901942424899-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8901942424899-9">9</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b8901942424899-1" class="crayon-line"><span class="crayon-v">df_train_new</span> <span class="crayon-o">=</span> <span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">concat</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-v">df_train_scale</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b8901942424899-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">interation_ind_ns_train</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b8901942424899-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">interation_ind_ns_dis_train</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b8901942424899-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">axis</span><span class="crayon-o">=</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span> <span class="crayon-v">join</span><span class="crayon-o">=</span><span class="crayon-s">'inner'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b8901942424899-5" class="crayon-line"><span class="crayon-v">df_test_new</span> <span class="crayon-o">=</span> <span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">concat</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-v">df_test_scale</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b8901942424899-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">interation_ind_ns_test</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b8901942424899-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">interation_ind_ns_dis_test</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b8901942424899-8" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">axis</span><span class="crayon-o">=</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span> <span class="crayon-v">join</span><span class="crayon-o">=</span><span class="crayon-s">'inner'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b8901942424899-9" class="crayon-line"><span class="crayon-v">df_train_new</span><span class="crayon-sy">.</span><span class="crayon-e">head</span><span class="crayon-sy">(</span><span class="crayon-cn">5</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p><strong>Output</strong></p> <p><img class="aligncenter size-full wp-image-7948 disappear appear" src="../../wp-content/uploads/2021/01/082918_1226_LinearRegre11.png" sizes="(max-width: 995px) 100vw, 995px" srcset="https://old.tek4.vn/wp-content/uploads/2021/01/082918_1226_LinearRegre11.png 995w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_1226_LinearRegre11-300x50.png 300w, https://old.tek4.vn/wp-content/uploads/2021/01/082918_1226_LinearRegre11-768x127.png 768w" alt="" width="995" height="165" loading="lazy" /></p> <div id="urvanov-syntax-highlighter-610fea28b8903458004418" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b8903458004418-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8903458004418-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8903458004418-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8903458004418-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8903458004418-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8903458004418-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8903458004418-7">7</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b8903458004418-1" class="crayon-line"><span class="crayon-v">CONTI_FEATURES_NEW</span><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-s">'CRIM'</span><span class="crayon-sy">,</span> <span class="crayon-s">'ZN'</span><span class="crayon-sy">,</span> <span class="crayon-s">'INDUS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'NOX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'RM'</span><span class="crayon-sy">,</span> <span class="crayon-s">'AGE'</span><span class="crayon-sy">,</span> <span class="crayon-s">'DIS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'RAD'</span><span class="crayon-sy">,</span><span class="crayon-s">'TAX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'PTRATIO'</span><span class="crayon-sy">,</span> <span class="crayon-s">'B'</span><span class="crayon-sy">,</span> <span class="crayon-s">'LSTAT'</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b8903458004418-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-s">'INDUS_NOS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'INDUS_NOS_DIS'</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea28b8903458004418-3" class="crayon-line"><span class="crayon-p">### Define categorical list</span></div> <div id="urvanov-syntax-highlighter-610fea28b8903458004418-4" class="crayon-line crayon-striped-line"><span class="crayon-v">continuous_features_new</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">feature_column</span><span class="crayon-sy">.</span><span class="crayon-e">numeric_column</span><span class="crayon-sy">(</span><span class="crayon-v">k</span><span class="crayon-sy">)</span> <span class="crayon-st">for</span> <span class="crayon-i">k</span> <span class="crayon-st">in</span> <span class="crayon-v">CONTI_FEATURES_NEW</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea28b8903458004418-5" class="crayon-line"><span class="crayon-v">model</span> <span class="crayon-o">=</span> <span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">estimator</span><span class="crayon-sy">.</span><span class="crayon-e">LinearRegressor</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea28b8903458004418-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">model_dir</span><span class="crayon-o">=</span><span class="crayon-s">"train_Boston_1"</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b8903458004418-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">feature_columns</span><span class="crayon-o">=</span> <span class="crayon-v">categorical_features</span> <span class="crayon-o">+</span> <span class="crayon-v">continuous_features_new</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fea28b8905151595616" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b8905151595616-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8905151595616-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b8905151595616-1" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Using </span><span class="crayon-st">default</span> <span class="crayon-v">config</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b8905151595616-2" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Using </span><span class="crayon-v">config</span><span class="crayon-o">:</span> <span class="crayon-sy">{</span><span class="crayon-s">'_model_dir'</span><span class="crayon-o">:</span> <span class="crayon-s">'train_Boston_1'</span><span class="crayon-sy">,</span> <span class="crayon-s">'_tf_random_seed'</span><span class="crayon-o">:</span> <span class="crayon-v">None</span><span class="crayon-sy">,</span> <span class="crayon-s">'_save_summary_steps'</span><span class="crayon-o">:</span> <span class="crayon-cn">100</span><span class="crayon-sy">,</span> <span class="crayon-s">'_save_checkpoints_steps'</span><span class="crayon-o">:</span> <span class="crayon-v">None</span><span class="crayon-sy">,</span> <span class="crayon-s">'_save_checkpoints_secs'</span><span class="crayon-o">:</span> <span class="crayon-cn">600</span><span class="crayon-sy">,</span> <span class="crayon-s">'_session_config'</span><span class="crayon-o">:</span> <span class="crayon-v">None</span><span class="crayon-sy">,</span> <span class="crayon-s">'_keep_checkpoint_max'</span><span class="crayon-o">:</span> <span class="crayon-cn">5</span><span class="crayon-sy">,</span> <span class="crayon-s">'_keep_checkpoint_every_n_hours'</span><span class="crayon-o">:</span> <span class="crayon-cn">10000</span><span class="crayon-sy">,</span> <span class="crayon-s">'_log_step_count_steps'</span><span class="crayon-o">:</span> <span class="crayon-cn">100</span><span class="crayon-sy">,</span> <span class="crayon-s">'_train_distribute'</span><span class="crayon-o">:</span> <span class="crayon-v">None</span><span class="crayon-sy">,</span> <span class="crayon-s">'_service'</span><span class="crayon-o">:</span> <span class="crayon-v">None</span><span class="crayon-sy">,</span> <span class="crayon-s">'_cluster_spec'</span><span class="crayon-o">:</span> <span class="crayon-o">&amp;</span><span class="crayon-v">lt</span><span class="crayon-sy">;</span><span class="crayon-v">tensorflow</span><span class="crayon-sy">.</span><span class="crayon-v">python</span><span class="crayon-sy">.</span><span class="crayon-v">training</span><span class="crayon-sy">.</span><span class="crayon-v">server_lib</span><span class="crayon-sy">.</span><span class="crayon-e">ClusterSpec </span><span class="crayon-t">object</span> <span class="crayon-i">at</span> <span class="crayon-cn">0x1a1a5d5860</span><span class="crayon-o">&amp;</span><span class="crayon-v">gt</span><span class="crayon-sy">;</span><span class="crayon-sy">,</span> <span class="crayon-s">'_task_type'</span><span class="crayon-o">:</span> <span class="crayon-s">'worker'</span><span class="crayon-sy">,</span> <span class="crayon-s">'_task_id'</span><span class="crayon-o">:</span> <span class="crayon-cn">0</span><span class="crayon-sy">,</span> <span class="crayon-s">'_global_id_in_cluster'</span><span class="crayon-o">:</span> <span class="crayon-cn">0</span><span class="crayon-sy">,</span> <span class="crayon-s">'_master'</span><span class="crayon-o">:</span> <span class="crayon-s">''</span><span class="crayon-sy">,</span> <span class="crayon-s">'_evaluation_master'</span><span class="crayon-o">:</span> <span class="crayon-s">''</span><span class="crayon-sy">,</span> <span class="crayon-s">'_is_chief'</span><span class="crayon-o">:</span> <span class="crayon-t">True</span><span class="crayon-sy">,</span> <span class="crayon-s">'_num_ps_replicas'</span><span class="crayon-o">:</span> <span class="crayon-cn">0</span><span class="crayon-sy">,</span> <span class="crayon-s">'_num_worker_replicas'</span><span class="crayon-o">:</span> <span class="crayon-cn">1</span><span class="crayon-sy">}</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>CODE</p> <div id="urvanov-syntax-highlighter-610fea28b8907528063262" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b8907528063262-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8907528063262-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8907528063262-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8907528063262-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8907528063262-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8907528063262-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8907528063262-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8907528063262-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8907528063262-9">9</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b8907528063262-1" class="crayon-line"><span class="crayon-v">FEATURES</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-s">'CRIM'</span><span class="crayon-sy">,</span> <span class="crayon-s">'ZN'</span><span class="crayon-sy">,</span> <span class="crayon-s">'INDUS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'NOX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'RM'</span><span class="crayon-sy">,</span> <span class="crayon-s">'AGE'</span><span class="crayon-sy">,</span> <span class="crayon-s">'DIS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'RAD'</span><span class="crayon-sy">,</span><span class="crayon-s">'TAX'</span><span class="crayon-sy">,</span> <span class="crayon-s">'PTRATIO'</span><span class="crayon-sy">,</span> <span class="crayon-s">'B'</span><span class="crayon-sy">,</span> <span class="crayon-s">'LSTAT'</span><span class="crayon-sy">,</span><span class="crayon-s">'INDUS_NOS'</span><span class="crayon-sy">,</span> <span class="crayon-s">'INDUS_NOS_DIS'</span><span class="crayon-sy">,</span><span class="crayon-s">'CHAS'</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea28b8907528063262-2" class="crayon-line crayon-striped-line"><span class="crayon-v">LABEL</span><span class="crayon-o">=</span> <span class="crayon-s">'PRICE'</span></div> <div id="urvanov-syntax-highlighter-610fea28b8907528063262-3" class="crayon-line"><span class="crayon-e">def </span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">data_set</span><span class="crayon-sy">,</span> <span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">None</span><span class="crayon-sy">,</span> <span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span> <span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">True</span><span class="crayon-sy">)</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fea28b8907528063262-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">return</span> <span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">estimator</span><span class="crayon-sy">.</span><span class="crayon-v">inputs</span><span class="crayon-sy">.</span><span class="crayon-e">pandas_input_fn</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea28b8907528063262-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">x</span><span class="crayon-o">=</span><span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">DataFrame</span><span class="crayon-sy">(</span><span class="crayon-sy">{</span><span class="crayon-v">k</span><span class="crayon-o">:</span> <span class="crayon-v">data_set</span><span class="crayon-sy">[</span><span class="crayon-v">k</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-e">values </span><span class="crayon-st">for</span> <span class="crayon-i">k</span> <span class="crayon-st">in</span> <span class="crayon-v">FEATURES</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b8907528063262-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">y</span> <span class="crayon-o">=</span> <span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">Series</span><span class="crayon-sy">(</span><span class="crayon-v">data_set</span><span class="crayon-sy">[</span><span class="crayon-v">LABEL</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-v">values</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b8907528063262-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">batch_size</span><span class="crayon-o">=</span><span class="crayon-v">n_batch</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fea28b8907528063262-8" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">num_epochs</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b8907528063262-9" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-v">shuffle</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610fea28b8909219641731" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b8909219641731-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8909219641731-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8909219641731-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8909219641731-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8909219641731-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b8909219641731-1" class="crayon-line"><span class="crayon-v">model</span><span class="crayon-sy">.</span><span class="crayon-e">train</span><span class="crayon-sy">(</span><span class="crayon-v">input_fn</span><span class="crayon-o">=</span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">df_train_new</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b8909219641731-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">None</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b8909219641731-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b8909219641731-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">False</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b8909219641731-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">steps</span><span class="crayon-o">=</span><span class="crayon-cn">1000</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fea28b890a862250051" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b890a862250051-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-20">20</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-21">21</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-22">22</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-23">23</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-24">24</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-25">25</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-26">26</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-27">27</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-28">28</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-29">29</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-30">30</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890a862250051-31">31</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-1" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Calling </span><span class="crayon-v">model_fn</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-2" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Done </span><span class="crayon-e">calling </span><span class="crayon-v">model_fn</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-3" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Create </span><span class="crayon-v">CheckpointSaverHook</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-4" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Graph </span><span class="crayon-e">was </span><span class="crayon-v">finalized</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-5" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Running </span><span class="crayon-v">local_init_op</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-6" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Done </span><span class="crayon-e">running </span><span class="crayon-v">local_init_op</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-7" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Saving </span><span class="crayon-e">checkpoints </span><span class="crayon-st">for</span> <span class="crayon-cn">1</span> <span class="crayon-e">into </span><span class="crayon-v">train_Boston_1</span><span class="crayon-o">/</span><span class="crayon-v">model</span><span class="crayon-sy">.</span><span class="crayon-v">ckpt</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-8" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">56417.703</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">1</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-9" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">124.844</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-10" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">65522.3</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">101</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.803</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-11" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">182.704</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-12" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">15384.148</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">201</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.549</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-13" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">208.189</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-14" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">22020.305</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">301</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.482</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-15" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">213.855</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-16" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">28208.812</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">401</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.468</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-17" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">209.758</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-18" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">7606.877</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">501</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.473</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-19" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">196.618</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-20" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">26679.76</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">601</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.514</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-21" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">196.472</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-22" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">11377.163</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">701</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.504</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-23" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">172.82</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-24" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">8592.07</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">801</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.578</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-25" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">global_step</span><span class="crayon-o">/</span><span class="crayon-v">sec</span><span class="crayon-o">:</span> <span class="crayon-cn">168.916</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-26" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">19878.56</span><span class="crayon-sy">,</span> <span class="crayon-v">step</span> <span class="crayon-o">=</span> <span class="crayon-cn">901</span> <span class="crayon-sy">(</span><span class="crayon-cn">0.592</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-27" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Saving </span><span class="crayon-e">checkpoints </span><span class="crayon-st">for</span> <span class="crayon-cn">1000</span> <span class="crayon-e">into </span><span class="crayon-v">train_Boston_1</span><span class="crayon-o">/</span><span class="crayon-v">model</span><span class="crayon-sy">.</span><span class="crayon-v">ckpt</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-28" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Loss </span><span class="crayon-st">for</span> <span class="crayon-m">final</span> <span class="crayon-v">step</span><span class="crayon-o">:</span> <span class="crayon-cn">19598.387.</span></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-29" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-30" class="crayon-line crayon-striped-line"></div> <div id="urvanov-syntax-highlighter-610fea28b890a862250051-31" class="crayon-line"><span class="crayon-o">&amp;</span><span class="crayon-v">lt</span><span class="crayon-sy">;</span><span class="crayon-v">tensorflow</span><span class="crayon-sy">.</span><span class="crayon-v">python</span><span class="crayon-sy">.</span><span class="crayon-v">estimator</span><span class="crayon-sy">.</span><span class="crayon-v">canned</span><span class="crayon-sy">.</span><span class="crayon-v">linear</span><span class="crayon-sy">.</span><span class="crayon-e">LinearRegressor </span><span class="crayon-i">at</span> <span class="crayon-cn">0x1a1a5d5e10</span><span class="crayon-o">&amp;</span><span class="crayon-v">gt</span><span class="crayon-sy">;</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610fea28b890d306497576" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b890d306497576-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890d306497576-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890d306497576-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b890d306497576-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b890d306497576-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b890d306497576-1" class="crayon-line"><span class="crayon-v">model</span><span class="crayon-sy">.</span><span class="crayon-e">evaluate</span><span class="crayon-sy">(</span><span class="crayon-v">input_fn</span><span class="crayon-o">=</span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">df_test_new</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b890d306497576-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b890d306497576-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b890d306497576-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">False</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea28b890d306497576-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">steps</span><span class="crayon-o">=</span><span class="crayon-cn">1000</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fea28b8910339325231" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" 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-610fea28b8910339325231-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8910339325231-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8910339325231-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8910339325231-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8910339325231-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8910339325231-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8910339325231-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8910339325231-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8910339325231-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8910339325231-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea28b8910339325231-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea28b8910339325231-12">12</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea28b8910339325231-1" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Calling </span><span class="crayon-v">model_fn</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b8910339325231-2" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Done </span><span class="crayon-e">calling </span><span class="crayon-v">model_fn</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b8910339325231-3" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Starting </span><span class="crayon-e">evaluation </span><span class="crayon-i">at</span> <span class="crayon-cn">2018</span><span class="crayon-o">-</span><span class="crayon-cn">05</span><span class="crayon-o">-</span><span class="crayon-cn">29</span><span class="crayon-o">-</span><span class="crayon-cn">02</span><span class="crayon-o">:</span><span class="crayon-cn">41</span><span class="crayon-o">:</span><span class="crayon-cn">14</span></div> <div id="urvanov-syntax-highlighter-610fea28b8910339325231-4" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Graph </span><span class="crayon-e">was </span><span class="crayon-v">finalized</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b8910339325231-5" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Restoring </span><span class="crayon-e">parameters </span><span class="crayon-e">from </span><span class="crayon-v">train_Boston_1</span><span class="crayon-o">/</span><span class="crayon-v">model</span><span class="crayon-sy">.</span><span class="crayon-v">ckpt</span><span class="crayon-o">-</span><span class="crayon-cn">1000</span></div> <div id="urvanov-syntax-highlighter-610fea28b8910339325231-6" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Running </span><span class="crayon-v">local_init_op</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b8910339325231-7" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Done </span><span class="crayon-e">running </span><span class="crayon-v">local_init_op</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea28b8910339325231-8" class="crayon-line crayon-striped-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Finished </span><span class="crayon-e">evaluation </span><span class="crayon-i">at</span> <span class="crayon-cn">2018</span><span class="crayon-o">-</span><span class="crayon-cn">05</span><span class="crayon-o">-</span><span class="crayon-cn">29</span><span class="crayon-o">-</span><span class="crayon-cn">02</span><span class="crayon-o">:</span><span class="crayon-cn">41</span><span class="crayon-o">:</span><span class="crayon-cn">14</span></div> <div id="urvanov-syntax-highlighter-610fea28b8910339325231-9" class="crayon-line"><span class="crayon-v">INFO</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Saving </span><span class="crayon-e">dict </span><span class="crayon-st">for</span> <span class="crayon-m">global</span> <span class="crayon-i">step</span> <span class="crayon-cn">1000</span><span class="crayon-o">:</span> <span class="crayon-v">average_loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">79.78876</span><span class="crayon-sy">,</span> <span class="crayon-v">global_step</span> <span class="crayon-o">=</span> <span class="crayon-cn">1000</span><span class="crayon-sy">,</span> <span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">1515.9863</span></div> <div id="urvanov-syntax-highlighter-610fea28b8910339325231-10" class="crayon-line crayon-striped-line"></div> <div id="urvanov-syntax-highlighter-610fea28b8910339325231-11" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea28b8910339325231-12" class="crayon-line crayon-striped-line"><span class="crayon-sy">{</span><span class="crayon-s">'average_loss'</span><span class="crayon-o">:</span> <span class="crayon-cn">79.78876</span><span class="crayon-sy">,</span> <span class="crayon-s">'global_step'</span><span class="crayon-o">:</span> <span class="crayon-cn">1000</span><span class="crayon-sy">,</span> <span class="crayon-s">'loss'</span><span class="crayon-o">:</span> <span class="crayon-cn">1515.9863</span><span class="crayon-sy">}</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p>Mức lỗi mới l&agrave; 1515. Chỉ cần th&ecirc;m hai biến mới, bạn đ&atilde; c&oacute; thể giảm tổn thất. N&oacute; c&oacute; nghĩa l&agrave; bạn c&oacute; thể đưa ra dự đo&aacute;n tốt hơn so với m&ocirc; h&igrave;nh ban đầu.</p> <p>B&agrave;i viết tiếp theo:&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>