tek4

Linear Regression Với TensorFlow – Tự Học TensorFlow

by - September. 21, 2021
Kiến thức
<blockquote> <p style="text-align: justify;">Ch&agrave;o mừng c&aacute;c bạn quay trở lại với loạt b&agrave;i&nbsp;<a href="../../tu-hoc-tensorflow-deep-learning-cho-nguoi-moi-bat-dau/" target="_blank" rel="noopener">Tự Học Tensorflow</a>&nbsp;của&nbsp;<a href="../../" target="_blank" rel="noopener">tek4.vn</a>. B&agrave;i viết n&agrave;y sẽ giới thiệu đến c&aacute;c bạn về Linear Regression với v&iacute; dụ sử dụng Tensorflow. Bắt đầu th&ocirc;i!</p> </blockquote> <p style="text-align: justify;">Xem th&ecirc;m b&agrave;i viết trước:&nbsp;<a href="../../import-data-csv-dung-pandas-tu-hoc-tensorflow/" target="_blank" rel="noopener">Import data CSV d&ugrave;ng Pandas</a></p> <p style="text-align: justify;"><img class="aligncenter size-full wp-image-7359 disappear appear" src="../../wp-content/uploads/2021/01/9.png" sizes="(max-width: 1111px) 100vw, 1111px" srcset="https://old.tek4.vn/wp-content/uploads/2021/01/9.png 1111w, https://old.tek4.vn/wp-content/uploads/2021/01/9-300x157.png 300w, https://old.tek4.vn/wp-content/uploads/2021/01/9-1024x537.png 1024w, https://old.tek4.vn/wp-content/uploads/2021/01/9-768x403.png 768w" alt="Linear Regression" width="1111" height="583" loading="lazy" /></p> <p style="text-align: justify;">TensorFlow cung cấp c&aacute;c c&ocirc;ng cụ để c&oacute; to&agrave;n quyền kiểm so&aacute;t c&aacute;c t&iacute;nh to&aacute;n. Điều n&agrave;y được thực hiện với API cấp thấp. Tr&ecirc;n hết, TensorFlow được trang bị một loạt c&aacute;c API để thực hiện nhiều thuật to&aacute;n học m&aacute;y. Đ&acirc;y l&agrave; API cấp cao. TensorFlow gọi ch&uacute;ng l&agrave; c&ocirc;ng cụ ước t&iacute;nh.</p> <ul style="text-align: justify;"> <li>API cấp thấp: X&acirc;y dựng kiến ​​tr&uacute;c, tối ưu h&oacute;a m&ocirc; h&igrave;nh từ đầu. N&oacute; kh&aacute; phức tạp cho người mới bắt đầu.</li> <li>API cấp cao: X&aacute;c định thuật to&aacute;n. N&oacute; dễ d&agrave;ng hơn cho người mới bắt đầu. TensorFlow cung cấp toolbox gọi l&agrave;&nbsp;<strong>estimator</strong>&nbsp;để x&acirc;y dựng, đ&agrave;o tạo, đ&aacute;nh gi&aacute; v&agrave; đưa ra dự đo&aacute;n.</li> </ul> <p style="text-align: justify;">B&agrave;i viết n&agrave;y chỉ sử dụng c&aacute;c&nbsp;<strong>estimators.&nbsp;</strong>N&oacute; c&oacute; c&aacute;c ph&eacute;p t&iacute;nh nhanh hơn v&agrave; dễ thực hiện hơn. Phần đầu ti&ecirc;n của b&agrave;i viết giải th&iacute;ch c&aacute;ch sử dụng tr&igrave;nh tối ưu h&oacute;a gradient descent để đ&agrave;o tạo linear regression. Trong phần thứ hai, sẽ sử dụng tập dữ liệu Boston để dự đo&aacute;n gi&aacute; của một ng&ocirc;i nh&agrave; bằng c&aacute;ch sử dụng TensorFlow estimator.</p> <p style="text-align: justify;"><a href="https://drive.google.com/file/d/1ziG5Ib0BziJJZCRsuvAbjXmAPNFM86cG/view?usp=sharing" target="_blank" rel="noopener">Tải xuống Boston DataSet</a></p> <h3 id="ftoc-heading-1" class="ftwp-heading" style="text-align: justify;">C&aacute;ch huấn luyện m&ocirc; h&igrave;nh linear regression với TensorFlow</h3> <p style="text-align: justify;">Ch&uacute;ng ta sẽ sử dụng tập dữ liệu Boston, chia tập dữ liệu th&agrave;nh 3 bộ như sau:</p> <table class="table table-striped aligncenter"> <tbody> <tr> <th>dataset</th> <th>objective</th> <th>shape</th> </tr> <tr> <td>Training</td> <td>Huấn luyện m&ocirc; h&igrave;nh v&agrave; lấy c&aacute;c trọng số</td> <td>400, 10</td> </tr> <tr> <td>Evaluation</td> <td>Đ&aacute;nh gi&aacute; hiệu suất của m&ocirc; h&igrave;nh tr&ecirc;n dữ liệu kh&ocirc;ng nh&igrave;n thấy</td> <td>100, 10</td> </tr> <tr> <td>Predict</td> <td>Sử dụng m&ocirc; h&igrave;nh để dự đo&aacute;n gi&aacute; trị ng&ocirc;i nh&agrave; tr&ecirc;n dữ liệu mới</td> <td>6, 10</td> </tr> </tbody> </table> <p style="text-align: justify;">Mục ti&ecirc;u l&agrave; sử dụng c&aacute;c đặc trưng của tập dữ liệu để dự đo&aacute;n gi&aacute; trị của ng&ocirc;i nh&agrave;.<br />Tiếp theo, ch&uacute;ng ta sẽ học c&aacute;ch sử dụng TensorFlow với ba c&aacute;ch kh&aacute;c nhau để import dữ liệu:</p> <ul style="text-align: justify;"> <li>Với Pandas</li> <li>Với Numpy</li> <li>Chỉ d&ugrave;ng TF</li> </ul> <p style="text-align: justify;"><strong>Lưu &yacute; rằng, tất cả c&aacute;c c&aacute;ch đều cung cấp kết quả giống nhau.</strong></p> <p style="text-align: justify;">Ch&uacute;ng ta sẽ học c&aacute;ch sử dụng API cấp cao để x&acirc;y dựng, đ&agrave;o tạo đ&aacute;nh gi&aacute; m&ocirc; h&igrave;nh hồi quy tuyến t&iacute;nh. Nếu bạn đang sử dụng API cấp thấp, bạn phải x&aacute;c định bằng tay:</p> <ul style="text-align: justify;"> <li>Loss function (h&agrave;m mất m&aacute;t)</li> <li>Tối ưu h&oacute;a: Gradient descent</li> <li>Ph&eacute;p nh&acirc;n ma trận</li> <li>Graph v&agrave; tensor</li> </ul> <p style="text-align: justify;">Điều n&agrave;y rất phức tạp cho người mới bắt đầu.</p> <h4 id="ftoc-heading-2" class="ftwp-heading" style="text-align: justify;">Pandas</h4> <p style="text-align: justify;">Import c&aacute;c thư viện cần thiết để huấn luyện m&ocirc; h&igrave;nh</p> <div id="urvanov-syntax-highlighter-610fe9e043d66703330264" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d66703330264-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d66703330264-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d66703330264-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d66703330264-4">4</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d66703330264-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-610fe9e043d66703330264-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-610fe9e043d66703330264-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-610fe9e043d66703330264-4" class="crayon-line crayon-striped-line"><span class="crayon-e">import </span><span class="crayon-v">itertools</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Bước 1)</strong>&nbsp;Import dữ liệu với Pandas</p> <p style="text-align: justify;">X&aacute;c định t&ecirc;n cột v&agrave; lưu trữ n&oacute; trong COLUMNS. C&oacute; thể sử dụng&nbsp;pd.read_csv()&nbsp;để import dữ liệu.</p> <div id="urvanov-syntax-highlighter-610fe9e043d71550757309" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d71550757309-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d71550757309-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d71550757309-1" class="crayon-line"><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></div> <div id="urvanov-syntax-highlighter-610fe9e043d71550757309-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-s">"dis"</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">"medv"</span><span class="crayon-sy">]</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610fe9e043d74237466189" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d74237466189-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d74237466189-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d74237466189-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d74237466189-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d74237466189-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d74237466189-1" class="crayon-line"><span class="crayon-v">training_set</span> <span class="crayon-o">=</span> <span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">read_csv</span><span class="crayon-sy">(</span><span class="crayon-s">"E:/boston_train.csv"</span><span class="crayon-sy">,</span> <span class="crayon-v">skipinitialspace</span><span class="crayon-o">=</span><span class="crayon-t">True</span><span class="crayon-sy">,</span><span class="crayon-v">skiprows</span><span class="crayon-o">=</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span> <span class="crayon-v">names</span><span class="crayon-o">=</span><span class="crayon-v">COLUMNS</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d74237466189-2" class="crayon-line crayon-striped-line"></div> <div id="urvanov-syntax-highlighter-610fe9e043d74237466189-3" class="crayon-line"><span class="crayon-v">test_set</span> <span class="crayon-o">=</span> <span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">read_csv</span><span class="crayon-sy">(</span><span class="crayon-s">"E:/boston_test.csv"</span><span class="crayon-sy">,</span> <span class="crayon-v">skipinitialspace</span><span class="crayon-o">=</span><span class="crayon-t">True</span><span class="crayon-sy">,</span><span class="crayon-v">skiprows</span><span class="crayon-o">=</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span> <span class="crayon-v">names</span><span class="crayon-o">=</span><span class="crayon-v">COLUMNS</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d74237466189-4" class="crayon-line crayon-striped-line"></div> <div id="urvanov-syntax-highlighter-610fe9e043d74237466189-5" class="crayon-line"><span class="crayon-v">prediction_set</span> <span class="crayon-o">=</span> <span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">read_csv</span><span class="crayon-sy">(</span><span class="crayon-s">"E:/boston_predict.csv"</span><span class="crayon-sy">,</span> <span class="crayon-v">skipinitialspace</span><span class="crayon-o">=</span><span class="crayon-t">True</span><span class="crayon-sy">,</span><span class="crayon-v">skiprows</span><span class="crayon-o">=</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span> <span class="crayon-v">names</span><span class="crayon-o">=</span><span class="crayon-v">COLUMNS</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Bạn c&oacute; thể in shape của dữ liệu.</p> <div id="urvanov-syntax-highlighter-610fe9e043d76084246892" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d76084246892-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d76084246892-1" class="crayon-line"><span class="crayon-e">print</span><span class="crayon-sy">(</span><span class="crayon-v">training_set</span><span class="crayon-sy">.</span><span class="crayon-v">shape</span><span class="crayon-sy">,</span> <span class="crayon-v">test_set</span><span class="crayon-sy">.</span><span class="crayon-v">shape</span><span class="crayon-sy">,</span> <span class="crayon-v">prediction_set</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 style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043d78836510016" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d78836510016-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d78836510016-1" class="crayon-line"><span class="crayon-sy">(</span><span class="crayon-cn">400</span><span class="crayon-sy">,</span> <span class="crayon-cn">10</span><span class="crayon-sy">)</span> <span class="crayon-sy">(</span><span class="crayon-cn">100</span><span class="crayon-sy">,</span> <span class="crayon-cn">10</span><span class="crayon-sy">)</span> <span class="crayon-sy">(</span><span class="crayon-cn">6</span><span class="crayon-sy">,</span> <span class="crayon-cn">10</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Lưu &yacute; rằng nh&atilde;n, tức l&agrave; y của bạn, được bao gồm trong tập dữ liệu. V&igrave; vậy, bạn cần x&aacute;c định hai danh s&aacute;ch kh&aacute;c nhau. Một chỉ chứa c&aacute;c đặc trưng v&agrave; một chỉ c&oacute; t&ecirc;n của nh&atilde;n. Hai danh s&aacute;ch n&agrave;y sẽ cho c&ocirc;ng cụ ước t&iacute;nh của bạn biết c&aacute;c đặc trưng trong tập dữ liệu l&agrave; g&igrave; v&agrave; t&ecirc;n cột l&agrave; nh&atilde;n n&agrave;o.</p> <p style="text-align: justify;">N&oacute; được thực hiện với code dưới đ&acirc;y.</p> <div id="urvanov-syntax-highlighter-610fe9e043d7a176603721" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d7a176603721-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d7a176603721-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d7a176603721-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d7a176603721-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></div> <div id="urvanov-syntax-highlighter-610fe9e043d7a176603721-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; </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">"tax"</span><span class="crayon-sy">,</span> <span class="crayon-s">"ptratio"</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d7a176603721-3" class="crayon-line"><span class="crayon-v">LABEL</span> <span class="crayon-o">=</span> <span class="crayon-s">"medv"</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Bước 2)</strong>&nbsp;Chuyển đổi dữ liệu</p> <p style="text-align: justify;">Bạn cần chuyển đổi c&aacute;c biến số ở định dạng th&iacute;ch hợp. Tensorflow cung cấp một phương thức để chuyển đổi biến li&ecirc;n tục:&nbsp;tf.feature_column.numeric_column().</p> <p style="text-align: justify;">Trong bước trước, bạn đ&atilde; x&aacute;c định một danh s&aacute;ch c&aacute;c đặc trưng muốn đưa v&agrave;o m&ocirc; h&igrave;nh. B&acirc;y giờ bạn c&oacute; thể sử dụng danh s&aacute;ch n&agrave;y để chuyển đổi ch&uacute;ng th&agrave;nh dữ liệu số. Nếu bạn muốn loại trừ c&aacute;c đặc trưng trong m&ocirc; h&igrave;nh của m&igrave;nh, vui l&ograve;ng bỏ một hoặc nhiều biến trong danh s&aacute;ch FEATURES trước khi bạn tạo feature_cols.</p> <div id="urvanov-syntax-highlighter-610fe9e043d7c717680643" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d7c717680643-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d7c717680643-1" class="crayon-line"><span class="crayon-v">feature_cols</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">FEATURES</span><span class="crayon-sy">]</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Bước 3)</strong>&nbsp;X&aacute;c định estimator</p> <p style="text-align: justify;">Tensorflow hiện cung cấp 6 estimator được x&acirc;y dựng trước, bao gồm 3 c&ocirc;ng cụ ph&acirc;n loại v&agrave; 3 c&ocirc;ng cụ hồi quy:</p> <ul style="text-align: justify;"> <li>Hồi quy <ul> <li>DNNRegressor</li> <li>LinearRegressor</li> <li>DNNLineaCombinedRegressor</li> </ul> </li> <li>Ph&acirc;n loại <ul> <li>DNNClassifier</li> <li>LinearClassifier</li> <li>DNNLineaCombinedClassifier</li> </ul> </li> </ul> <p style="text-align: justify;">Trong b&agrave;i n&agrave;y, ch&uacute;ng ta sẽ sử dụng Linear Regressor. Để truy cập h&agrave;m n&agrave;y, bạn cần sử dụng tf.estimator.</p> <p style="text-align: justify;">H&agrave;m cần hai đối số:</p> <ul style="text-align: justify;"> <li>Feature_columns: Chứa c&aacute;c biến để đưa v&agrave;o m&ocirc; h&igrave;nh</li> <li>Model_dir: đường dẫn để lưu trữ đồ thị, lưu c&aacute;c tham số m&ocirc; h&igrave;nh, v.v.</li> </ul> <p style="text-align: justify;">Tensorflow sẽ tự động tạo một tệp c&oacute; t&ecirc;n l&agrave; train trong thư mục l&agrave;m việc của bạn. Bạn cần sử dụng đường dẫn n&agrave;y để truy cập Tensorboard.</p> <div id="urvanov-syntax-highlighter-610fe9e043d7e657415816" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d7e657415816-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d7e657415816-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d7e657415816-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d7e657415816-1" class="crayon-line"><span class="crayon-v">estimator</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-610fe9e043d7e657415816-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">feature_columns</span><span class="crayon-o">=</span><span class="crayon-v">feature_cols</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fe9e043d7e657415816-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">model_dir</span><span class="crayon-o">=</span><span class="crayon-s">"train"</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043d81646666446" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d81646666446-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d81646666446-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d81646666446-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-610fe9e043d81646666446-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'</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">0x1a215dc550</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 style="text-align: justify;">Phần kh&oacute; khăn với TensorFlow l&agrave; c&aacute;ch cung cấp m&ocirc; h&igrave;nh. Tensorflow được thiết kế để hoạt động với t&iacute;nh to&aacute;n song song v&agrave; tập dữ liệu rất lớn. Do hạn chế của t&agrave;i nguy&ecirc;n m&aacute;y, kh&ocirc;ng thể cung cấp cho m&ocirc; h&igrave;nh với tất cả dữ liệu c&ugrave;ng một l&uacute;c. V&igrave; vậy, cần phải cung cấp một batch dữ liệu mỗi lần. Lưu &yacute; rằng, ch&uacute;ng ta đang n&oacute;i về tập dữ liệu khổng lồ với h&agrave;ng triệu bản ghi trở l&ecirc;n. Nếu kh&ocirc;ng th&ecirc;m theo batch, ch&uacute;ng ta c&oacute; thể gặp lỗi về bộ nhớ.</p> <p style="text-align: justify;">V&iacute; dụ: Nếu dữ liệu của bạn l&agrave; 100 v&agrave; bạn x&aacute;c định batch size l&agrave; 10, điều đ&oacute; c&oacute; nghĩa l&agrave; m&ocirc; h&igrave;nh sẽ thấy 10&nbsp; dữ liệu cho mỗi lần lặp (10 * 10).</p> <p style="text-align: justify;">Khi m&ocirc; h&igrave;nh đ&atilde; xem tất cả dữ liệu, n&oacute; sẽ kết th&uacute;c một epoch. epoch x&aacute;c định số lần bạn muốn m&ocirc; h&igrave;nh xem dữ liệu. Tốt hơn l&agrave; đặt bước n&agrave;y th&agrave;nh kh&ocirc;ng v&agrave; để m&ocirc; h&igrave;nh thực hiện số lần lặp lại. Tốt hơn l&agrave; đặt bước n&agrave;y th&agrave;nh 0 v&agrave; để m&ocirc; h&igrave;nh thực hiện số lần lặp lại.</p> <p style="text-align: justify;">Th&ocirc;ng tin thứ 2 cần biết đ&oacute; l&agrave; cần x&aacute;o trộn dữ liệu trước mỗi lần lặp. Trong qu&aacute; tr&igrave;nh đ&agrave;o tạo, điều quan trọng l&agrave; x&aacute;o trộn dữ liệu để m&ocirc; h&igrave;nh kh&ocirc;ng học được mẫu cụ thể của tập dữ liệu. Nếu m&ocirc; h&igrave;nh t&igrave;m hiểu chi tiết về m&ocirc; h&igrave;nh cơ bản của dữ liệu, n&oacute; sẽ gặp kh&oacute; khăn trong việc tổng qu&aacute;t h&oacute;a dự đo&aacute;n cho dữ liệu kh&ocirc;ng nh&igrave;n thấy. Điều n&agrave;y được gọi l&agrave; qu&aacute; khớp (overfitting). M&ocirc; h&igrave;nh hoạt động tốt tr&ecirc;n dữ liệu đ&agrave;o tạo nhưng kh&ocirc;ng thể dự đo&aacute;n ch&iacute;nh x&aacute;c đối với dữ liệu kh&ocirc;ng nh&igrave;n thấy.</p> <p style="text-align: justify;">TensorFlow l&agrave;m cho hai bước n&agrave;y dễ d&agrave;ng thực hiện. Khi dữ liệu đi đến pipeline, n&oacute; biết n&oacute; cần bao nhi&ecirc;u quan s&aacute;t (batch) v&agrave; liệu n&oacute; c&oacute; phải x&aacute;o trộn dữ liệu hay kh&ocirc;ng.</p> <p style="text-align: justify;">Để hướng dẫn Tensorflow c&aacute;ch cung cấp m&ocirc; h&igrave;nh, bạn c&oacute; thể sử dụng pandas_input_fn. Đối tượng n&agrave;y cần 5 tham số:</p> <ul style="text-align: justify;"> <li>x: Đặc trưng của dữ liệu</li> <li>y: Nh&atilde;n của dữ liệu</li> <li>batch_size: k&iacute;ch thước batch. Theo mặc định l&agrave; 128.</li> <li>num_epoch: Số epoch, theo mặc định l&agrave; 1.</li> <li>shuffle: X&aacute;o trộn hoặc kh&ocirc;ng trộn dữ liệu. Theo mặc định l&agrave; none.</li> </ul> <p style="text-align: justify;">Cần phải feed model nhiều lần để x&aacute;c định một h&agrave;m lặp lại qu&aacute; tr&igrave;nh n&agrave;y. get_input_fn.</p> <div id="urvanov-syntax-highlighter-610fe9e043d84872440184" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d84872440184-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d84872440184-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d84872440184-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d84872440184-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d84872440184-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d84872440184-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d84872440184-7">7</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d84872440184-1" 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><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d84872440184-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&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><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fe9e043d84872440184-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&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><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fe9e043d84872440184-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&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><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fe9e043d84872440184-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&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;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d84872440184-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&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">num_epochs</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fe9e043d84872440184-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&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 style="text-align: justify;">Phương ph&aacute;p th&ocirc;ng thường để đ&aacute;nh gi&aacute; hiệu suất của một m&ocirc; h&igrave;nh l&agrave;:</p> <ul style="text-align: justify;"> <li>Đ&agrave;o tạo m&ocirc; h&igrave;nh</li> <li>Đ&aacute;nh gi&aacute; m&ocirc; h&igrave;nh trong một tập dữ liệu kh&aacute;c</li> <li>Đưa ra dự đo&aacute;n</li> </ul> <p style="text-align: justify;">C&ocirc;ng cụ Tensorflow estimator cung cấp ba chức năng kh&aacute;c nhau để thực hiện ba bước n&agrave;y một c&aacute;ch dễ d&agrave;ng.</p> <p style="text-align: justify;"><strong>Bước 4):</strong>&nbsp;Huấn luyện m&ocirc; h&igrave;nh</p> <p style="text-align: justify;">Bạn c&oacute; thể sử dụng estimator để đ&aacute;nh gi&aacute; m&ocirc; h&igrave;nh.</p> <p style="text-align: justify;">Train estimator cần c&oacute; input_fn v&agrave; một số bước. Bạn c&oacute; thể sử dụng h&agrave;m đ&atilde; tạo ở tr&ecirc;n để cung cấp m&ocirc; h&igrave;nh. Sau đ&oacute;, hướng dẫn m&ocirc; h&igrave;nh lặp lại 1000 lần. Lưu &yacute; rằng, kh&ocirc;ng chỉ định số epoch, h&atilde;y để m&ocirc; h&igrave;nh lặp lại 1000 lần. Nếu bạn đặt số epoch th&agrave;nh 1, th&igrave; m&ocirc; h&igrave;nh sẽ lặp lại 4 lần: C&oacute; 400 bản ghi trong tập huấn luyện v&agrave; batch size l&agrave; 128.</p> <ol style="text-align: justify;"> <li>128 h&agrave;ng</li> <li>128 h&agrave;ng</li> <li>128 h&agrave;ng</li> <li>16 h&agrave;ng</li> </ol> <p style="text-align: justify;">Do đ&oacute;, việc đặt số epoch th&agrave;nh 0 v&agrave; x&aacute;c định số lần lặp lại dễ d&agrave;ng hơn như thể hiện trong v&iacute; dụ ph&acirc;n loại TensorFlow b&ecirc;n dưới.</p> <div id="urvanov-syntax-highlighter-610fe9e043d87396993599" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d87396993599-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d87396993599-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d87396993599-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d87396993599-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d87396993599-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d87396993599-1" class="crayon-line"><span class="crayon-v">estimator</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">training_set</span><span class="crayon-sy">,</span><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></div> <div id="urvanov-syntax-highlighter-610fe9e043d87396993599-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;&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><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></div> <div id="urvanov-syntax-highlighter-610fe9e043d87396993599-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;&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><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></div> <div id="urvanov-syntax-highlighter-610fe9e043d87396993599-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;&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><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></div> <div id="urvanov-syntax-highlighter-610fe9e043d87396993599-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;&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 style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-20">20</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-21">21</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-22">22</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-23">23</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-24">24</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-25">25</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-26">26</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-27">27</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d89157615736-28">28</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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-610fe9e043d89157615736-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-610fe9e043d89157615736-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-610fe9e043d89157615736-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-610fe9e043d89157615736-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-610fe9e043d89157615736-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-610fe9e043d89157615736-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</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-610fe9e043d89157615736-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">83729.64</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-610fe9e043d89157615736-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">238.616</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">13909.657</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.420</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">314.293</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">12881.449</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.320</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">303.863</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">12391.541</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.327</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">308.782</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">12050.5625</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.326</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">244.969</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">11766.134</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.407</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">155.966</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">11509.922</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.641</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">263.256</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">11272.889</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.379</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">254.112</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">11051.9795</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.396</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">292.405</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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">10845.855</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.341</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d89157615736-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</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-610fe9e043d89157615736-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">5925.9873.</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Bạn c&oacute; thể kiểm tra Tensorboard theo lệnh sau:</p> <div id="urvanov-syntax-highlighter-610fe9e043d8b599654170" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d8b599654170-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d8b599654170-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d8b599654170-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d8b599654170-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d8b599654170-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d8b599654170-1" class="crayon-line"><span class="crayon-e">activate </span><span class="crayon-v">hello</span><span class="crayon-o">-</span><span class="crayon-i">tf</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d8b599654170-2" class="crayon-line crayon-striped-line"><span class="crayon-p"># For MacOS</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d8b599654170-3" class="crayon-line"><span class="crayon-v">tensorboard</span> <span class="crayon-o">--</span><span class="crayon-v">logdir</span><span class="crayon-o">=</span><span class="crayon-sy">.</span><span class="crayon-o">/</span><span class="crayon-i">train</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d8b599654170-4" class="crayon-line crayon-striped-line"><span class="crayon-p"># For Windows</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d8b599654170-5" class="crayon-line"><span class="crayon-v">tensorboard</span> <span class="crayon-o">--</span><span class="crayon-v">logdir</span><span class="crayon-o">=</span><span class="crayon-v">train</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Bước 5)</strong>&nbsp;Đ&aacute;nh gi&aacute; m&ocirc; h&igrave;nh</p> <p style="text-align: justify;">Bạn c&oacute; thể đ&aacute;nh gi&aacute; sự ph&ugrave; hợp m&ocirc; h&igrave;nh của m&igrave;nh tr&ecirc;n bộ thử nghiệm với code b&ecirc;n dưới:</p> <div id="urvanov-syntax-highlighter-610fe9e043d8d337958849" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d8d337958849-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d8d337958849-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d8d337958849-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d8d337958849-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d8d337958849-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d8d337958849-1" class="crayon-line"><span class="crayon-v">ev</span> <span class="crayon-o">=</span> <span class="crayon-v">estimator</span><span class="crayon-sy">.</span><span class="crayon-e">evaluate</span><span class="crayon-sy">(</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d8d337958849-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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">test_set</span><span class="crayon-sy">,</span><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></div> <div id="urvanov-syntax-highlighter-610fe9e043d8d337958849-3" class="crayon-line"><span class="crayon-h">&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><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></div> <div id="urvanov-syntax-highlighter-610fe9e043d8d337958849-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&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><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></div> <div id="urvanov-syntax-highlighter-610fe9e043d8d337958849-5" class="crayon-line"><span class="crayon-h">&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> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043d8f515222098" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d8f515222098-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d8f515222098-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d8f515222098-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d8f515222098-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d8f515222098-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d8f515222098-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d8f515222098-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d8f515222098-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d8f515222098-9">9</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d8f515222098-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-610fe9e043d8f515222098-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-610fe9e043d8f515222098-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">13</span><span class="crayon-o">-</span><span class="crayon-cn">01</span><span class="crayon-o">:</span><span class="crayon-cn">43</span><span class="crayon-o">:</span><span class="crayon-cn">13</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d8f515222098-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-610fe9e043d8f515222098-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</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-610fe9e043d8f515222098-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-610fe9e043d8f515222098-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-610fe9e043d8f515222098-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">13</span><span class="crayon-o">-</span><span class="crayon-cn">01</span><span class="crayon-o">:</span><span class="crayon-cn">43</span><span class="crayon-o">:</span><span class="crayon-cn">13</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d8f515222098-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">32.15896</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">3215.896</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Kiểm tra loss bằng code sau:</p> <div id="urvanov-syntax-highlighter-610fe9e043d91831543743" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d91831543743-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d91831543743-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d91831543743-1" class="crayon-line"><span class="crayon-v">loss_score</span> <span class="crayon-o">=</span> <span class="crayon-v">ev</span><span class="crayon-sy">[</span><span class="crayon-s">"loss"</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d91831543743-2" class="crayon-line crayon-striped-line"><span class="crayon-e">print</span><span class="crayon-sy">(</span><span class="crayon-s">"Loss: {0:f}"</span><span class="crayon-sy">.</span><span class="crayon-e">format</span><span class="crayon-sy">(</span><span class="crayon-v">loss_score</span><span class="crayon-sy">)</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043d93627468373" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d93627468373-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d93627468373-1" class="crayon-line"><span class="crayon-v">Loss</span><span class="crayon-o">:</span> <span class="crayon-cn">3215.895996</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">M&ocirc; h&igrave;nh c&oacute; loss l&agrave; 3215. Bạn c&oacute; thể kiểm tra thống k&ecirc; t&oacute;m tắt để biết mức độ lớn của loss.</p> <div id="urvanov-syntax-highlighter-610fe9e043d94237960343" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d94237960343-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d94237960343-1" class="crayon-line"><span class="crayon-v">training_set</span><span class="crayon-sy">[</span><span class="crayon-s">'medv'</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-e">describe</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043d96395587157" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d96395587157-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d96395587157-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d96395587157-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d96395587157-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d96395587157-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d96395587157-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d96395587157-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d96395587157-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d96395587157-9">9</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d96395587157-1" class="crayon-line"><span class="crayon-i">count</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-cn">400.000000</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d96395587157-2" class="crayon-line crayon-striped-line"><span class="crayon-i">mean</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-cn">22.625500</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d96395587157-3" class="crayon-line"><span class="crayon-i">std</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-cn">9.572593</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d96395587157-4" class="crayon-line crayon-striped-line"><span class="crayon-i">min</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-cn">5.000000</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d96395587157-5" class="crayon-line"><span class="crayon-cn">25</span><span class="crayon-o">%</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-cn">16.600000</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d96395587157-6" class="crayon-line crayon-striped-line"><span class="crayon-cn">50</span><span class="crayon-o">%</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-cn">21.400000</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d96395587157-7" class="crayon-line"><span class="crayon-cn">75</span><span class="crayon-o">%</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-cn">25.025000</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d96395587157-8" class="crayon-line crayon-striped-line"><span class="crayon-i">max</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-cn">50.000000</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d96395587157-9" class="crayon-line"><span class="crayon-v">Name</span><span class="crayon-o">:</span> <span class="crayon-v">medv</span><span class="crayon-sy">,</span> <span class="crayon-v">dtype</span><span class="crayon-o">:</span> <span class="crayon-v">float64</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Từ bảng thống k&ecirc; tổng hợp ở tr&ecirc;n, bạn biết rằng gi&aacute; trung b&igrave;nh cho một căn nh&agrave; l&agrave; 22 ngh&igrave;n, gi&aacute; tối thiểu l&agrave; 9 ngh&igrave;n v&agrave; tối đa l&agrave; 50 ngh&igrave;n.</p> <p style="text-align: justify;"><strong>Bước 6)</strong>&nbsp;Đưa ra dự đo&aacute;n</p> <p style="text-align: justify;">Cuối c&ugrave;ng, bạn c&oacute; thể sử dụng c&ocirc;ng cụ dự đo&aacute;n TensorFlow để ước t&iacute;nh gi&aacute; trị của 6 ng&ocirc;i nh&agrave; ở Boston.</p> <div id="urvanov-syntax-highlighter-610fe9e043d98863358869" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d98863358869-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d98863358869-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d98863358869-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d98863358869-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d98863358869-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d98863358869-1" class="crayon-line"><span class="crayon-v">y</span> <span class="crayon-o">=</span> <span class="crayon-v">estimator</span><span class="crayon-sy">.</span><span class="crayon-e">predict</span><span class="crayon-sy">(</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d98863358869-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </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">prediction_set</span><span class="crayon-sy">,</span><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></div> <div id="urvanov-syntax-highlighter-610fe9e043d98863358869-3" class="crayon-line"><span class="crayon-h">&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><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></div> <div id="urvanov-syntax-highlighter-610fe9e043d98863358869-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&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><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></div> <div id="urvanov-syntax-highlighter-610fe9e043d98863358869-5" class="crayon-line"><span class="crayon-h">&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> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Để in c&aacute;c gi&aacute; trị ước t&iacute;nh, bạn c&oacute; thể sử dụng code n&agrave;y:</p> <div id="urvanov-syntax-highlighter-610fe9e043d99416126131" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d99416126131-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d99416126131-1" class="crayon-line"><span class="crayon-v">predictions</span> <span class="crayon-o">=</span> <span class="crayon-e">list</span><span class="crayon-sy">(</span><span class="crayon-v">p</span><span class="crayon-sy">[</span><span class="crayon-s">"predictions"</span><span class="crayon-sy">]</span> <span class="crayon-st">for</span> <span class="crayon-i">p</span> <span class="crayon-st">in</span> <span class="crayon-v">itertools</span><span class="crayon-sy">.</span><span class="crayon-e">islice</span><span class="crayon-sy">(</span><span class="crayon-v">y</span><span class="crayon-sy">,</span> <span class="crayon-cn">6</span><span class="crayon-sy">)</span><span class="crayon-sy">)</span><span class="crayon-e">print</span><span class="crayon-sy">(</span><span class="crayon-s">"Predictions: {}"</span><span class="crayon-sy">.</span><span class="crayon-e">format</span><span class="crayon-sy">(</span><span class="crayon-e">str</span><span class="crayon-sy">(</span><span class="crayon-v">predictions</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 style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043d9b584169181" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d9b584169181-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d9b584169181-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d9b584169181-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d9b584169181-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d9b584169181-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d9b584169181-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d9b584169181-7">7</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d9b584169181-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-610fe9e043d9b584169181-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-610fe9e043d9b584169181-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">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-610fe9e043d9b584169181-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">Restoring </span><span class="crayon-e">parameters </span><span class="crayon-e">from </span><span class="crayon-v">train</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-610fe9e043d9b584169181-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-610fe9e043d9b584169181-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-610fe9e043d9b584169181-7" class="crayon-line"><span class="crayon-v">Predictions</span><span class="crayon-o">:</span> <span class="crayon-sy">[</span><span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">32.297546</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">18.96125</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">27.270979</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">29.299236</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">16.436684</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">21.460876</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">]</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">M&ocirc; h&igrave;nh dự b&aacute;o c&aacute;c gi&aacute; trị sau:</p> <table class="table table-striped aligncenter"> <tbody> <tr> <th>House</th> <th>Prediction</th> <td>&nbsp;</td> </tr> <tr> <td>1</td> <td>32.29</td> <td>&nbsp;</td> </tr> <tr> <td>2</td> <td>18.96</td> <td>&nbsp;</td> </tr> <tr> <td>3</td> <td>27.27</td> <td>&nbsp;</td> </tr> <tr> <td>4</td> <td>29.29</td> <td>&nbsp;</td> </tr> <tr> <td>5</td> <td>16.43</td> <td>&nbsp;</td> </tr> <tr> <td>7</td> <td>21.46</td> <td>&nbsp;</td> </tr> </tbody> </table> <h3 id="ftoc-heading-3" class="ftwp-heading" style="text-align: justify;">Numpy Solution</h3> <p style="text-align: justify;">Phần n&agrave;y giải th&iacute;ch c&aacute;ch huấn luyện m&ocirc; h&igrave;nh bằng c&aacute;ch sử dụng c&ocirc;ng cụ ước t&iacute;nh phức tạp để cung cấp dữ liệu. Phương ph&aacute;p n&agrave;y cũng giống như phương ph&aacute;p m&agrave; bạn sẽ sử dụng ước t&iacute;nh numpy_input_fn.</p> <p style="text-align: justify;">training_set_n = pd.read_csv(&ldquo;E:/boston_train.csv&rdquo;).values</p> <p style="text-align: justify;">test_set_n = pd.read_csv(&ldquo;E:/boston_test.csv&rdquo;).values</p> <p style="text-align: justify;">prediction_set_n = pd.read_csv(&ldquo;E:/boston_predict.csv&rdquo;).values</p> <p style="text-align: justify;"><strong>Bước 1)</strong>&nbsp;Nhập dữ liệu</p> <p style="text-align: justify;">Trước hết, bạn cần ph&acirc;n biệt c&aacute;c biến đặc trưng với nh&atilde;n. Bạn cần l&agrave;m điều n&agrave;y để c&oacute; dữ liệu đ&agrave;o tạo v&agrave; đ&aacute;nh gi&aacute;. Việc x&aacute;c định một h&agrave;m để chia nhỏ dữ liệu sẽ nhanh hơn.</p> <div id="urvanov-syntax-highlighter-610fe9e043d9e294249634" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d9e294249634-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d9e294249634-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043d9e294249634-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043d9e294249634-4">4</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043d9e294249634-1" class="crayon-line"><span class="crayon-e">def </span><span class="crayon-e">prepare_data</span><span class="crayon-sy">(</span><span class="crayon-v">df</span><span class="crayon-sy">)</span><span class="crayon-o">:</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fe9e043d9e294249634-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">X_train</span> <span class="crayon-o">=</span> <span class="crayon-v">df</span><span class="crayon-sy">[</span><span class="crayon-o">:</span><span class="crayon-sy">,</span> <span class="crayon-o">:</span><span class="crayon-o">-</span><span class="crayon-cn">3</span><span class="crayon-sy">]</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d9e294249634-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">y_train</span> <span class="crayon-o">=</span> <span class="crayon-v">df</span><span class="crayon-sy">[</span><span class="crayon-o">:</span><span class="crayon-sy">,</span><span class="crayon-o">-</span><span class="crayon-cn">3</span><span class="crayon-sy">]</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043d9e294249634-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">return</span> <span class="crayon-v">X_train</span><span class="crayon-sy">,</span> <span class="crayon-v">y_train</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Bạn c&oacute; thể sử dụng h&agrave;m t&aacute;ch nh&atilde;n khỏi c&aacute;c đặc trưng của tập dữ liệu huấn luyện / đ&aacute;nh gi&aacute;</p> <div id="urvanov-syntax-highlighter-610fe9e043da0564948100" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043da0564948100-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043da0564948100-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043da0564948100-1" class="crayon-line"><span class="crayon-v">X_train</span><span class="crayon-sy">,</span> <span class="crayon-v">y_train</span> <span class="crayon-o">=</span> <span class="crayon-e">prepare_data</span><span class="crayon-sy">(</span><span class="crayon-v">training_set_n</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043da0564948100-2" class="crayon-line crayon-striped-line"><span class="crayon-v">X_test</span><span class="crayon-sy">,</span> <span class="crayon-v">y_test</span> <span class="crayon-o">=</span> <span class="crayon-e">prepare_data</span><span class="crayon-sy">(</span><span class="crayon-v">test_set_n</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Bạn cần loại trừ cột cuối c&ugrave;ng của tập dữ liệu dự đo&aacute;n v&igrave; n&oacute; chỉ chứa NaN</p> <div id="urvanov-syntax-highlighter-610fe9e043da1022034873" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043da1022034873-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043da1022034873-1" class="crayon-line"><span class="crayon-v">x_predict</span> <span class="crayon-o">=</span> <span class="crayon-v">prediction_set_n</span><span class="crayon-sy">[</span><span class="crayon-o">:</span><span class="crayon-sy">,</span> <span class="crayon-o">:</span><span class="crayon-o">-</span><span class="crayon-cn">2</span><span class="crayon-sy">]</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">X&aacute;c nhận shape của mảng.</p> <div id="urvanov-syntax-highlighter-610fe9e043da3072331974" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043da3072331974-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043da3072331974-1" class="crayon-line"><span class="crayon-e">print</span><span class="crayon-sy">(</span><span class="crayon-v">X_train</span><span class="crayon-sy">.</span><span class="crayon-v">shape</span><span class="crayon-sy">,</span> <span class="crayon-v">y_train</span><span class="crayon-sy">.</span><span class="crayon-v">shape</span><span class="crayon-sy">,</span> <span class="crayon-v">x_predict</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 style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043da5914549971" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043da5914549971-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043da5914549971-1" class="crayon-line"><span class="crayon-sy">(</span><span class="crayon-cn">400</span><span class="crayon-sy">,</span> <span class="crayon-cn">9</span><span class="crayon-sy">)</span> <span class="crayon-sy">(</span><span class="crayon-cn">400</span><span class="crayon-sy">,</span><span class="crayon-sy">)</span> <span class="crayon-sy">(</span><span class="crayon-cn">6</span><span class="crayon-sy">,</span> <span class="crayon-cn">9</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Bạn c&oacute; thể x&acirc;y dựng c&aacute;c cột đặc trưng như sau:</p> <div id="urvanov-syntax-highlighter-610fe9e043da6822600330" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043da6822600330-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043da6822600330-1" class="crayon-line"><span class="crayon-v">feature_columns</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</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-s">'x'</span><span class="crayon-sy">,</span> <span class="crayon-v">shape</span><span class="crayon-o">=</span><span class="crayon-v">X_train</span><span class="crayon-sy">.</span><span class="crayon-v">shape</span><span class="crayon-sy">[</span><span class="crayon-cn">1</span><span class="crayon-o">:</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 style="text-align: justify;">C&ocirc;ng cụ ước t&iacute;nh được định nghĩa như trước đ&acirc;y, bạn hướng dẫn c&aacute;c cột đặc trưng v&agrave; nơi lưu biểu đồ.</p> <div id="urvanov-syntax-highlighter-610fe9e043da8537504970" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043da8537504970-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043da8537504970-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043da8537504970-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043da8537504970-1" class="crayon-line"><span class="crayon-v">estimator</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-610fe9e043da8537504970-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">feature_columns</span><span class="crayon-o">=</span><span class="crayon-v">feature_columns</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043da8537504970-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">model_dir</span><span class="crayon-o">=</span><span class="crayon-s">"train1"</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043daa486175865" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043daa486175865-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043daa486175865-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043daa486175865-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-610fe9e043daa486175865-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">'train1'</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">0x1a218d8f28</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 style="text-align: justify;">Bạn c&oacute; thể sử dụng c&ocirc;ng cụ ước lượng numpy để cung cấp dữ liệu v&agrave;o m&ocirc; h&igrave;nh v&agrave; sau đ&oacute; huấn luyện m&ocirc; h&igrave;nh. Lưu &yacute; rằng, ch&uacute;ng t&ocirc;i x&aacute;c định h&agrave;m input_fn trước để dễ đọc.</p> <div id="urvanov-syntax-highlighter-610fe9e043dac519128740" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dac519128740-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dac519128740-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dac519128740-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dac519128740-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dac519128740-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dac519128740-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dac519128740-7">7</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dac519128740-1" class="crayon-line"><span class="crayon-p"># Train the estimatortrain_input = tf.estimator.inputs.numpy_input_fn(&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fe9e043dac519128740-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">x</span><span class="crayon-o">=</span><span class="crayon-sy">{</span><span class="crayon-s">"x"</span><span class="crayon-o">:</span> <span class="crayon-v">X_train</span><span class="crayon-sy">}</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dac519128740-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">y</span><span class="crayon-o">=</span><span class="crayon-v">y_train</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dac519128740-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">batch_size</span><span class="crayon-o">=</span><span class="crayon-cn">128</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dac519128740-5" class="crayon-line"><span class="crayon-h">&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-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dac519128740-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&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-610fe9e043dac519128740-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">estimator</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-v">train_input</span><span class="crayon-sy">,</span><span class="crayon-v">steps</span><span class="crayon-o">=</span><span class="crayon-cn">5000</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-20">20</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-21">21</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-22">22</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-23">23</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-24">24</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-25">25</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-26">26</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-27">27</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-28">28</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-29">29</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dae622142094-30">30</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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-610fe9e043dae622142094-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-610fe9e043dae622142094-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-610fe9e043dae622142094-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-610fe9e043dae622142094-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-610fe9e043dae622142094-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-610fe9e043dae622142094-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">train1</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-610fe9e043dae622142094-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">83729.64</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-610fe9e043dae622142094-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">490.057</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">13909.656</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.206</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">788.986</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">12881.45</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.126</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">736.339</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">12391.541</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.136</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">383.305</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">12050.561</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.260</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">859.832</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">11766.133</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.117</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">804.394</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">11509.918</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.125</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">753.059</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">11272.891</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.134</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">402.165</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">11051.979</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.248</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">344.022</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">10845.854</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.288</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-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">train1</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-610fe9e043dae622142094-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">5925.985.</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-29" class="crayon-line"><span class="crayon-v">Out</span><span class="crayon-sy">[</span><span class="crayon-cn">23</span><span class="crayon-sy">]</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dae622142094-30" class="crayon-line crayon-striped-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">0x1a1b6ea860</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 style="text-align: justify;">Lặp lại bước tương tự với một c&ocirc;ng cụ ước t&iacute;nh kh&aacute;c để đ&aacute;nh gi&aacute; m&ocirc; h&igrave;nh của m&igrave;nh</p> <div id="urvanov-syntax-highlighter-610fe9e043dbe162447986" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dbe162447986-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dbe162447986-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dbe162447986-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dbe162447986-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dbe162447986-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dbe162447986-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dbe162447986-7">7</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dbe162447986-1" class="crayon-line"><span class="crayon-v">eval_input</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-v">inputs</span><span class="crayon-sy">.</span><span class="crayon-e">numpy_input_fn</span><span class="crayon-sy">(</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dbe162447986-2" class="crayon-line crayon-striped-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-sy">{</span><span class="crayon-s">"x"</span><span class="crayon-o">:</span> <span class="crayon-v">X_test</span><span class="crayon-sy">}</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dbe162447986-3" class="crayon-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">y_test</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dbe162447986-4" class="crayon-line crayon-striped-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-t">False</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dbe162447986-5" 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-cn">128</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dbe162447986-6" 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-cn">1</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dbe162447986-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp; </span><span class="crayon-v">estimator</span><span class="crayon-sy">.</span><span class="crayon-e">evaluate</span><span class="crayon-sy">(</span><span class="crayon-v">eval_input</span><span class="crayon-sy">,</span><span class="crayon-v">steps</span><span class="crayon-o">=</span><span class="crayon-v">None</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043dc4406422313" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dc4406422313-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dc4406422313-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dc4406422313-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dc4406422313-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dc4406422313-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dc4406422313-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dc4406422313-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dc4406422313-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dc4406422313-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dc4406422313-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dc4406422313-11">11</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dc4406422313-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-610fe9e043dc4406422313-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-610fe9e043dc4406422313-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">13</span><span class="crayon-o">-</span><span class="crayon-cn">01</span><span class="crayon-o">:</span><span class="crayon-cn">44</span><span class="crayon-o">:</span><span class="crayon-cn">00</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dc4406422313-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-610fe9e043dc4406422313-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">train1</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-610fe9e043dc4406422313-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-610fe9e043dc4406422313-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-610fe9e043dc4406422313-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">13</span><span class="crayon-o">-</span><span class="crayon-cn">01</span><span class="crayon-o">:</span><span class="crayon-cn">44</span><span class="crayon-o">:</span><span class="crayon-cn">00</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dc4406422313-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">32.158947</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">3215.8945</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dc4406422313-10" class="crayon-line crayon-striped-line"><span class="crayon-v">Out</span><span class="crayon-sy">[</span><span class="crayon-cn">24</span><span class="crayon-sy">]</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dc4406422313-11" class="crayon-line"><span class="crayon-sy">{</span><span class="crayon-s">'average_loss'</span><span class="crayon-o">:</span> <span class="crayon-cn">32.158947</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">3215.8945</span><span class="crayon-sy">}</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Cuối c&ugrave;ng, bạn c&oacute; thể t&iacute;nh to&aacute;n dự đo&aacute;n. N&oacute; phải tương tự như pandas.</p> <div id="urvanov-syntax-highlighter-610fe9e043dc6322294593" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dc6322294593-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dc6322294593-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dc6322294593-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dc6322294593-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dc6322294593-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dc6322294593-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dc6322294593-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dc6322294593-8">8</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dc6322294593-1" class="crayon-line"><span class="crayon-v">test_input</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-v">inputs</span><span class="crayon-sy">.</span><span class="crayon-e">numpy_input_fn</span><span class="crayon-sy">(</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dc6322294593-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">x</span><span class="crayon-o">=</span><span class="crayon-sy">{</span><span class="crayon-s">"x"</span><span class="crayon-o">:</span> <span class="crayon-v">x_predict</span><span class="crayon-sy">}</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dc6322294593-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">batch_size</span><span class="crayon-o">=</span><span class="crayon-cn">128</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dc6322294593-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&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><span class="crayon-h">&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fe9e043dc6322294593-5" class="crayon-line"><span class="crayon-h">&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></div> <div id="urvanov-syntax-highlighter-610fe9e043dc6322294593-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">y</span> <span class="crayon-o">=</span> <span class="crayon-v">estimator</span><span class="crayon-sy">.</span><span class="crayon-e">predict</span><span class="crayon-sy">(</span><span class="crayon-v">test_input</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dc6322294593-7" class="crayon-line"><span class="crayon-v">predictions</span> <span class="crayon-o">=</span> <span class="crayon-e">list</span><span class="crayon-sy">(</span><span class="crayon-v">p</span><span class="crayon-sy">[</span><span class="crayon-s">"predictions"</span><span class="crayon-sy">]</span> <span class="crayon-st">for</span> <span class="crayon-i">p</span> <span class="crayon-st">in</span> <span class="crayon-v">itertools</span><span class="crayon-sy">.</span><span class="crayon-e">islice</span><span class="crayon-sy">(</span><span class="crayon-v">y</span><span class="crayon-sy">,</span> <span class="crayon-cn">6</span><span class="crayon-sy">)</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dc6322294593-8" class="crayon-line crayon-striped-line"><span class="crayon-e">print</span><span class="crayon-sy">(</span><span class="crayon-s">"Predictions: {}"</span><span class="crayon-sy">.</span><span class="crayon-e">format</span><span class="crayon-sy">(</span><span class="crayon-e">str</span><span class="crayon-sy">(</span><span class="crayon-v">predictions</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 style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043dc8515295429" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dc8515295429-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dc8515295429-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dc8515295429-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dc8515295429-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dc8515295429-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dc8515295429-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dc8515295429-7">7</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dc8515295429-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-610fe9e043dc8515295429-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-610fe9e043dc8515295429-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">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-610fe9e043dc8515295429-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">Restoring </span><span class="crayon-e">parameters </span><span class="crayon-e">from </span><span class="crayon-v">train1</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-610fe9e043dc8515295429-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-610fe9e043dc8515295429-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-610fe9e043dc8515295429-7" class="crayon-line"><span class="crayon-v">Predictions</span><span class="crayon-o">:</span> <span class="crayon-sy">[</span><span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">32.297546</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">18.961248</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">27.270979</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">29.299242</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">16.43668</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">21.460878</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">]</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <h3 id="ftoc-heading-4" class="ftwp-heading" style="text-align: justify;">Tensorflow solution</h3> <p style="text-align: justify;">Phần cuối c&ugrave;ng d&agrave;nh ri&ecirc;ng cho giải ph&aacute;p TensorFlow. Phương ph&aacute;p n&agrave;y phức tạp hơn phương ph&aacute;p kia.</p> <p style="text-align: justify;">Lưu &yacute; rằng nếu bạn sử dụng Jupyter notebook, bạn cần Khởi động lại v&agrave; dọn dẹp kernel để chạy phi&ecirc;n n&agrave;y.</p> <p style="text-align: justify;">TensorFlow đ&atilde; x&acirc;y dựng một c&ocirc;ng cụ tuyệt vời để truyền dữ liệu v&agrave;o pipeline. Trong phần n&agrave;y, bạn sẽ tự x&acirc;y dựng h&agrave;m input_fn.</p> <p style="text-align: justify;"><strong>Bước 1)</strong>&nbsp;X&aacute;c định đường dẫn v&agrave; định dạng của dữ liệu</p> <p style="text-align: justify;">Trước hết, bạn khai b&aacute;o hai biến với đường dẫn của tệp csv. Lưu &yacute; rằng, bạn c&oacute; hai tệp, một cho tập huấn luyện v&agrave; một cho tập thử nghiệm.</p> <div id="urvanov-syntax-highlighter-610fe9e043dca980619833" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dca980619833-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dca980619833-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dca980619833-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dca980619833-1" 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-610fe9e043dca980619833-2" class="crayon-line crayon-striped-line"><span class="crayon-v">df_train</span> <span class="crayon-o">=</span> <span class="crayon-s">"E:/boston_train.csv"</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dca980619833-3" class="crayon-line"><span class="crayon-v">df_eval</span> <span class="crayon-o">=</span> <span class="crayon-s">"E:/boston_test.csv"</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Sau đ&oacute;, bạn cần x&aacute;c định c&aacute;c cột bạn muốn sử dụng từ tệp csv. Ch&uacute;ng ta sẽ sử dụng tất cả. Sau đ&oacute;, bạn cần khai b&aacute;o kiểu của biến.</p> <p style="text-align: justify;">Biến số float được x&aacute;c định bởi [0.]</p> <div id="urvanov-syntax-highlighter-610fe9e043dcc165213221" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dcc165213221-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dcc165213221-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dcc165213221-1" class="crayon-line"><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></div> <div id="urvanov-syntax-highlighter-610fe9e043dcc165213221-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;</span><span class="crayon-s">"dis"</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">"medv"</span><span class="crayon-sy">]</span><span class="crayon-v">RECORDS_ALL</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-sy">[</span><span class="crayon-cn">0.0</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-sy">[</span><span class="crayon-cn">0.0</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-sy">[</span><span class="crayon-cn">0.0</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-sy">[</span><span class="crayon-cn">0.0</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span><span class="crayon-sy">[</span><span class="crayon-cn">0.0</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span><span class="crayon-sy">[</span><span class="crayon-cn">0.0</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span><span class="crayon-sy">[</span><span class="crayon-cn">0.0</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span><span class="crayon-sy">[</span><span class="crayon-cn">0.0</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span><span class="crayon-sy">[</span><span class="crayon-cn">0.0</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span><span class="crayon-sy">[</span><span class="crayon-cn">0.0</span><span class="crayon-sy">]</span><span class="crayon-sy">]</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Bước 2)</strong>&nbsp;X&aacute;c định h&agrave;m input_fn</p> <p style="text-align: justify;">H&agrave;m c&oacute; thể được chia th&agrave;nh ba phần:</p> <ol style="text-align: justify;"> <li>Import dữ liệu</li> <li>Tạo tr&igrave;nh lặp</li> <li>Sử dụng dữ liệu</li> </ol> <p style="text-align: justify;">Dưới đ&acirc;y l&agrave; code tổng qu&aacute;t để x&aacute;c định h&agrave;m. Code sẽ được giải th&iacute;ch sau:</p> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dd0404369720-20">20</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-1" class="crayon-line"><span class="crayon-e">def </span><span class="crayon-e">input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">data_file</span><span class="crayon-sy">,</span> <span class="crayon-v">batch_size</span><span class="crayon-sy">,</span> <span class="crayon-v">num_epoch</span> <span class="crayon-o">=</span> <span class="crayon-v">None</span><span class="crayon-sy">)</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-p"># Step 1 </span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-e">def </span><span class="crayon-e">parse_csv</span><span class="crayon-sy">(</span><span class="crayon-v">value</span><span class="crayon-sy">)</span><span class="crayon-o">:</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">columns</span> <span class="crayon-o">=</span> <span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-e">decode_csv</span><span class="crayon-sy">(</span><span class="crayon-v">value</span><span class="crayon-sy">,</span> <span class="crayon-v">record_defaults</span><span class="crayon-o">=</span> <span class="crayon-v">RECORDS_ALL</span><span class="crayon-sy">)</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">features</span> <span class="crayon-o">=</span> <span class="crayon-e">dict</span><span class="crayon-sy">(</span><span class="crayon-e">zip</span><span class="crayon-sy">(</span><span class="crayon-v">COLUMNS</span><span class="crayon-sy">,</span> <span class="crayon-v">columns</span><span class="crayon-sy">)</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-p">#labels = features.pop('median_house_value')&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">labels</span> <span class="crayon-o">=</span><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-v">features</span><span class="crayon-sy">.</span><span class="crayon-e">pop</span><span class="crayon-sy">(</span><span class="crayon-s">'medv'</span><span class="crayon-sy">)</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-8" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">return</span> <span class="crayon-v">features</span><span class="crayon-sy">,</span> <span class="crayon-i">labels</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-9" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-10" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-p"># Extract lines from input files using the </span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-11" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-e">Dataset </span><span class="crayon-v">API</span><span class="crayon-sy">.</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">dataset</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">data</span><span class="crayon-sy">.</span><span class="crayon-e">TextLineDataset</span><span class="crayon-sy">(</span><span class="crayon-v">data_file</span><span class="crayon-sy">)</span> <span class="crayon-p"># Read text file&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-12" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-sy">.</span><span class="crayon-e">skip</span><span class="crayon-sy">(</span><span class="crayon-cn">1</span><span class="crayon-sy">)</span> <span class="crayon-p"># Skip header row&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-13" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-sy">.</span><span class="crayon-e">map</span><span class="crayon-sy">(</span><span class="crayon-v">parse_csv</span><span class="crayon-sy">)</span><span class="crayon-sy">)</span><span class="crayon-h"> &nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-14" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-15" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">dataset</span> <span class="crayon-o">=</span> <span class="crayon-v">dataset</span><span class="crayon-sy">.</span><span class="crayon-e">repeat</span><span class="crayon-sy">(</span><span class="crayon-v">num_epoch</span><span class="crayon-sy">)</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-16" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">dataset</span> <span class="crayon-o">=</span> <span class="crayon-v">dataset</span><span class="crayon-sy">.</span><span class="crayon-e">batch</span><span class="crayon-sy">(</span><span class="crayon-v">batch_size</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-17" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-p"># Step 3&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-18" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">iterator</span> <span class="crayon-o">=</span> <span class="crayon-v">dataset</span><span class="crayon-sy">.</span><span class="crayon-e">make_one_shot_iterator</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-19" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">features</span><span class="crayon-sy">,</span> <span class="crayon-v">labels</span> <span class="crayon-o">=</span> <span class="crayon-v">iterator</span><span class="crayon-sy">.</span><span class="crayon-e">get_next</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd0404369720-20" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">return</span> <span class="crayon-v">features</span><span class="crayon-sy">,</span> <span class="crayon-v">labels</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Import dữ liệu&nbsp;</strong></p> <p style="text-align: justify;">Đối với tệp csv, phương thức tập dữ liệu đọc từng d&ograve;ng một. Để x&acirc;y dựng tập dữ liệu, bạn cần sử dụng đối tượng TextLineDataset. Tập dữ liệu của bạn c&oacute; ti&ecirc;u đề v&igrave; vậy bạn cần sử dụng skip(1) để bỏ qua d&ograve;ng đầu ti&ecirc;n. Tại thời điểm n&agrave;y, bạn chỉ đọc dữ liệu v&agrave; loại trừ ti&ecirc;u đề trong đường dẫn. Để feed m&ocirc; h&igrave;nh, bạn cần t&aacute;ch c&aacute;c đặc trưng khỏi nh&atilde;n. Phương ph&aacute;p được sử dụng để &aacute;p dụng bất kỳ chuyển đổi n&agrave;o đối với dữ liệu l&agrave; map.</p> <p style="text-align: justify;">Phương thức n&agrave;y gọi một h&agrave;m m&agrave; bạn sẽ tạo để hướng dẫn c&aacute;ch chuyển đổi dữ liệu. T&oacute;m lại, bạn cần chuyển dữ liệu v&agrave;o đối tượng TextLineDataset, loại trừ ti&ecirc;u đề v&agrave; &aacute;p dụng một ph&eacute;p chuyển đổi được hướng dẫn bởi một h&agrave;m.</p> <ul style="text-align: justify;"> <li>tf.data.TextLineDataset(data_file):&nbsp; D&ograve;ng n&agrave;y đọc tệp csv</li> <li>.skip(1) : bỏ qua ti&ecirc;u đề</li> <li>.map(parse_csv)): ph&acirc;n t&iacute;ch c&uacute; ph&aacute;p c&aacute;c bản ghi th&agrave;nh c&aacute;c tensor. Bạn cần x&aacute;c định một h&agrave;m để hướng dẫn đối tượng map. Bạn c&oacute; thể gọi h&agrave;m n&agrave;y l&agrave; parse_csv.</li> </ul> <p style="text-align: justify;">H&agrave;m n&agrave;y ph&acirc;n t&iacute;ch c&uacute; ph&aacute;p tệp csv bằng phương thức tf.decode_csv v&agrave; khai b&aacute;o c&aacute;c đặc trưng v&agrave; nh&atilde;n. C&aacute;c đặc trưng c&oacute; thể được khai b&aacute;o như một từ điển hoặc một tuple. Ch&uacute;ng ta sử dụng từ điển v&igrave; n&oacute; thuận tiện hơn.</p> <ul style="text-align: justify;"> <li>tf.decode_csv(value, record_defaults= RECORDS_ALL): phương thức decode_csv sử dụng đầu ra của TextLineDataset để đọc tệp csv. Record_defaults hướng dẫn TensorFlow về loại cột.</li> <li>dict(zip(_CSV_COLUMNS, columns)): Điền v&agrave;o từ điển với tất cả c&aacute;c cột được tr&iacute;ch xuất trong qu&aacute; tr&igrave;nh xử l&yacute; dữ liệu n&agrave;y</li> <li>features.pop(&lsquo;median_house_value&rsquo;): Loại trừ biến mục ti&ecirc;u khỏi biến đặc trưng v&agrave; tạo biến nh&atilde;n</li> </ul> <p style="text-align: justify;">Dataset cần c&aacute;c phần tử kh&aacute;c để cấp dữ liệu cho Tensors một c&aacute;ch lặp lại. Thật vậy, bạn cần th&ecirc;m phương thức lặp lại để cho ph&eacute;p tập dữ liệu tiếp tục v&ocirc; thời hạn cung cấp cho m&ocirc; h&igrave;nh. Nếu bạn kh&ocirc;ng th&ecirc;m phương thức, m&ocirc; h&igrave;nh sẽ chỉ lặp lại một lần v&agrave; sau đ&oacute; tạo ra lỗi v&igrave; kh&ocirc;ng c&oacute; th&ecirc;m dữ liệu n&agrave;o được cung cấp trong đường dẫn.</p> <p style="text-align: justify;">Sau đ&oacute;, bạn c&oacute; thể kiểm so&aacute;t batch size bằng phương thức batch. N&oacute; c&oacute; nghĩa l&agrave; bạn cho tập dữ liệu biết c&oacute; bao nhi&ecirc;u dữ liệu bạn muốn chuyển trong đường dẫn cho mỗi lần lặp. Nếu bạn đặt batch size lớn, m&ocirc; h&igrave;nh sẽ chậm.</p> <p style="text-align: justify;"><strong>Bước 3)&nbsp;</strong>Tạo tr&igrave;nh lặp</p> <p style="text-align: justify;">B&acirc;y giờ bạn đ&atilde; sẵn s&agrave;ng cho bước thứ ba: tạo một tr&igrave;nh lặp để trả về c&aacute;c phần tử trong tập dữ liệu. C&aacute;ch đơn giản nhất để tạo to&aacute;n tử l&agrave; với phương thức make_one_shot_iterator.</p> <p style="text-align: justify;">Sau đ&oacute;, bạn c&oacute; thể tạo c&aacute;c đặc trưng v&agrave; nh&atilde;n từ tr&igrave;nh lặp.</p> <p style="text-align: justify;"><strong>Bước 4)&nbsp;</strong>Sử dụng dữ liệu</p> <p style="text-align: justify;">Bạn c&oacute; thể kiểm tra điều g&igrave; xảy ra với h&agrave;m input_fn. Cần gọi h&agrave;m trong một phi&ecirc;n để sử dụng dữ liệu. H&atilde;y thử với batch size bằng 1.</p> <p style="text-align: justify;">Lưu &yacute; rằng, n&oacute; in c&aacute;c đặc trưng trong từ điển v&agrave; nh&atilde;n dưới dạng một mảng.</p> <p style="text-align: justify;">N&oacute; sẽ hiển thị d&ograve;ng đầu ti&ecirc;n của tệp csv. Bạn c&oacute; thể thử chạy code n&agrave;y nhiều lần với batch size kh&aacute;c nhau.</p> <div id="urvanov-syntax-highlighter-610fe9e043dd4188224020" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dd4188224020-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dd4188224020-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dd4188224020-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dd4188224020-4">4</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dd4188224020-1" class="crayon-line"><span class="crayon-v">next_batch</span> <span class="crayon-o">=</span> <span class="crayon-e">input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">df_train</span><span class="crayon-sy">,</span> <span class="crayon-v">batch_size</span> <span class="crayon-o">=</span> <span class="crayon-cn">1</span><span class="crayon-sy">,</span> <span class="crayon-v">num_epoch</span> <span class="crayon-o">=</span> <span class="crayon-v">None</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd4188224020-2" class="crayon-line crayon-striped-line"><span class="crayon-e">with </span><span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-e">Session</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span> <span class="crayon-st">as</span> <span class="crayon-v">sess</span><span class="crayon-o">:</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd4188224020-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">first_batch</span><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-o">=</span> <span class="crayon-v">sess</span><span class="crayon-sy">.</span><span class="crayon-e">run</span><span class="crayon-sy">(</span><span class="crayon-v">next_batch</span><span class="crayon-sy">)</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dd4188224020-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-e">print</span><span class="crayon-sy">(</span><span class="crayon-v">first_batch</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043dd8703851190" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dd8703851190-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dd8703851190-1" class="crayon-line"><span class="crayon-sy">(</span><span class="crayon-sy">{</span><span class="crayon-s">'crim'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">2.3004</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-s">'zn'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">0.</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-v">dtype</span><span class="crayon-o">=</span><span class="crayon-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-s">'indus'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">19.58</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-s">'nox'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">0.605</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-s">'rm'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">6.319</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-s">'age'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">96.1</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-s">'dis'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">2.1</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-s">'tax'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">403.</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span> <span class="crayon-s">'ptratio'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">14.7</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">}</span><span class="crayon-sy">,</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">23.8</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Bước 4)</strong>&nbsp;X&aacute;c định cột đặc trưng</p> <p style="text-align: justify;">Bạn cần x&aacute;c định c&aacute;c cột số như sau:</p> <div id="urvanov-syntax-highlighter-610fe9e043dda774812428" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dda774812428-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dda774812428-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dda774812428-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dda774812428-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dda774812428-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dda774812428-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dda774812428-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dda774812428-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dda774812428-9">9</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dda774812428-1" class="crayon-line"><span class="crayon-v">X1</span><span class="crayon-o">=</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-s">'crim'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dda774812428-2" class="crayon-line crayon-striped-line"><span class="crayon-v">X2</span><span class="crayon-o">=</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-s">'zn'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dda774812428-3" class="crayon-line"><span class="crayon-v">X3</span><span class="crayon-o">=</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-s">'indus'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dda774812428-4" class="crayon-line crayon-striped-line"><span class="crayon-v">X4</span><span class="crayon-o">=</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-s">'nox'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dda774812428-5" class="crayon-line"><span class="crayon-v">X5</span><span class="crayon-o">=</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-s">'rm'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dda774812428-6" class="crayon-line crayon-striped-line"><span class="crayon-v">X6</span><span class="crayon-o">=</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-s">'age'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dda774812428-7" class="crayon-line"><span class="crayon-v">X7</span><span class="crayon-o">=</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-s">'dis'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dda774812428-8" class="crayon-line crayon-striped-line"><span class="crayon-v">X8</span><span class="crayon-o">=</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-s">'tax'</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dda774812428-9" class="crayon-line"><span class="crayon-v">X9</span><span class="crayon-o">=</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-s">'ptratio'</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Lưu &yacute; rằng bạn cần kết hợp tất cả c&aacute;c biến trong một nh&oacute;m</p> <div id="urvanov-syntax-highlighter-610fe9e043ddc089310749" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043ddc089310749-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043ddc089310749-1" class="crayon-line"><span class="crayon-v">base_columns</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-v">X1</span><span class="crayon-sy">,</span> <span class="crayon-v">X2</span><span class="crayon-sy">,</span> <span class="crayon-v">X3</span><span class="crayon-sy">,</span><span class="crayon-v">X4</span><span class="crayon-sy">,</span> <span class="crayon-v">X5</span><span class="crayon-sy">,</span> <span class="crayon-v">X6</span><span class="crayon-sy">,</span><span class="crayon-v">X7</span><span class="crayon-sy">,</span> <span class="crayon-v">X8</span><span class="crayon-sy">,</span> <span class="crayon-v">X9</span><span class="crayon-sy">]</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Bước 5)</strong>&nbsp;X&acirc;y dựng m&ocirc; h&igrave;nh</p> <p style="text-align: justify;">Bạn c&oacute; thể đ&agrave;o tạo m&ocirc; h&igrave;nh bằng c&ocirc;ng cụ ước lượng LinearRegressor.</p> <div id="urvanov-syntax-highlighter-610fe9e043dde660757755" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dde660757755-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dde660757755-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-v">feature_columns</span><span class="crayon-o">=</span><span class="crayon-v">base_columns</span><span class="crayon-sy">,</span> <span class="crayon-v">model_dir</span><span class="crayon-o">=</span><span class="crayon-s">'train3'</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043de0167401568" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de0167401568-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043de0167401568-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> <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">'train3'</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">0x1820a010f0</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 style="text-align: justify;">Bạn cần sử dụng một h&agrave;m lambda để cho ph&eacute;p viết đối số trong h&agrave;m inpu_fn. Nếu bạn kh&ocirc;ng sử dụng h&agrave;m lambda, bạn kh&ocirc;ng thể huấn luyện m&ocirc; h&igrave;nh.</p> <div id="urvanov-syntax-highlighter-610fe9e043de2927339723" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de2927339723-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de2927339723-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043de2927339723-1" class="crayon-line"><span class="crayon-p"># Train the estimatormodel.train(steps =1000,&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de2927339723-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">input_fn</span><span class="crayon-o">=</span> <span class="crayon-v">lambda</span> <span class="crayon-o">:</span> <span class="crayon-e">input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">df_train</span><span class="crayon-sy">,</span><span class="crayon-v">batch_size</span><span class="crayon-o">=</span><span class="crayon-cn">128</span><span class="crayon-sy">,</span> <span class="crayon-v">num_epoch</span> <span class="crayon-o">=</span> <span class="crayon-v">None</span><span class="crayon-sy">)</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-20">20</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-21">21</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-22">22</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-23">23</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-24">24</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-25">25</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-26">26</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-27">27</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-28">28</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-29">29</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de5291325408-30">30</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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-610fe9e043de5291325408-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-610fe9e043de5291325408-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-610fe9e043de5291325408-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-610fe9e043de5291325408-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-610fe9e043de5291325408-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-610fe9e043de5291325408-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">train3</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-610fe9e043de5291325408-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">83729.64</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-610fe9e043de5291325408-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">72.5646</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">13909.657</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">1.380</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">101.355</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">12881.449</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.986</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">109.293</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">12391.541</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.915</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">102.235</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">12050.5625</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.978</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">104.656</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">11766.134</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.956</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">106.697</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">11509.922</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.938</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">118.454</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">11272.889</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.844</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">114.947</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">11051.9795</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.870</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">111.484</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">10845.855</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.897</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-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">train3</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-610fe9e043de5291325408-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">5925.9873.</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-29" class="crayon-line"><span class="crayon-v">Out</span><span class="crayon-sy">[</span><span class="crayon-cn">8</span><span class="crayon-sy">]</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de5291325408-30" class="crayon-line crayon-striped-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">0x18225eb8d0</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 style="text-align: justify;">Bạn c&oacute; thể đ&aacute;nh gi&aacute; sự ph&ugrave; hợp của m&ocirc; h&igrave;nh của bạn tr&ecirc;n bộ thử nghiệm với code b&ecirc;n dưới:</p> <div id="urvanov-syntax-highlighter-610fe9e043de8433283274" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de8433283274-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043de8433283274-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043de8433283274-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043de8433283274-1" class="crayon-line"><span class="crayon-v">results</span> <span class="crayon-o">=</span> <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">steps</span> <span class="crayon-o">=</span><span class="crayon-v">None</span><span class="crayon-sy">,</span><span class="crayon-v">input_fn</span><span class="crayon-o">=</span><span class="crayon-v">lambda</span><span class="crayon-o">:</span> <span class="crayon-e">input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">df_eval</span><span class="crayon-sy">,</span> <span class="crayon-v">batch_size</span> <span class="crayon-o">=</span><span class="crayon-cn">128</span><span class="crayon-sy">,</span> <span class="crayon-v">num_epoch</span> <span class="crayon-o">=</span> <span class="crayon-cn">1</span><span class="crayon-sy">)</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043de8433283274-2" class="crayon-line crayon-striped-line"><span class="crayon-st">for</span> <span class="crayon-e">key </span><span class="crayon-st">in</span> <span class="crayon-v">results</span><span class="crayon-o">:</span><span class="crayon-h">&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fe9e043de8433283274-3" class="crayon-line"><span class="crayon-e">print</span><span class="crayon-sy">(</span><span class="crayon-s">"&nbsp;&nbsp; {}, was: {}"</span><span class="crayon-sy">.</span><span class="crayon-e">format</span><span class="crayon-sy">(</span><span class="crayon-v">key</span><span class="crayon-sy">,</span> <span class="crayon-v">results</span><span class="crayon-sy">[</span><span class="crayon-v">key</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 style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043dea024077279" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dea024077279-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dea024077279-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dea024077279-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dea024077279-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dea024077279-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dea024077279-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dea024077279-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dea024077279-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dea024077279-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dea024077279-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dea024077279-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dea024077279-12">12</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dea024077279-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-610fe9e043dea024077279-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-610fe9e043dea024077279-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">13</span><span class="crayon-o">-</span><span class="crayon-cn">02</span><span class="crayon-o">:</span><span class="crayon-cn">06</span><span class="crayon-o">:</span><span class="crayon-cn">02</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dea024077279-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-610fe9e043dea024077279-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">train3</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-610fe9e043dea024077279-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-610fe9e043dea024077279-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-610fe9e043dea024077279-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">13</span><span class="crayon-o">-</span><span class="crayon-cn">02</span><span class="crayon-o">:</span><span class="crayon-cn">06</span><span class="crayon-o">:</span><span class="crayon-cn">02</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dea024077279-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">32.15896</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">3215.896</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dea024077279-10" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp; </span><span class="crayon-v">average_loss</span><span class="crayon-sy">,</span> <span class="crayon-v">was</span><span class="crayon-o">:</span> <span class="crayon-cn">32.158958435058594</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dea024077279-11" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp; </span><span class="crayon-v">loss</span><span class="crayon-sy">,</span> <span class="crayon-v">was</span><span class="crayon-o">:</span> <span class="crayon-cn">3215.89599609375</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dea024077279-12" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp; </span><span class="crayon-v">global_step</span><span class="crayon-sy">,</span> <span class="crayon-v">was</span><span class="crayon-o">:</span> <span class="crayon-cn">1000</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Bước cuối c&ugrave;ng l&agrave; dự đo&aacute;n gi&aacute; trị dựa tr&ecirc;n gi&aacute; trị của ma trận của c&aacute;c đặc trưng. Bạn c&oacute; thể viết 1 từ điển với c&aacute;c gi&aacute; trị bạn muốn dự đo&aacute;n. M&ocirc; h&igrave;nh của bạn c&oacute; 9 đặc trưng n&ecirc;n bạn cần cung cấp gi&aacute; trị cho mỗi đặc trưng. M&ocirc; h&igrave;nh sẽ cung cấp một dự đo&aacute;n cho mỗi người trong số họ.</p> <p style="text-align: justify;">Trong đoạn code b&ecirc;n dưới, ch&uacute;ng ta viết c&aacute;c gi&aacute; trị của từng đặc trưng c&oacute; trong tệp df_predict csv.</p> <p style="text-align: justify;">Bạn cần viết một h&agrave;m input_fn mới v&igrave; kh&ocirc;ng c&oacute; nh&atilde;n n&agrave;o trong tập dữ liệu. C&oacute; thể sử dụng API from_tensor from the Dataset.</p> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dec319126100-16">16</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-1" class="crayon-line"><span class="crayon-v">prediction_input</span> <span class="crayon-o">=</span> <span class="crayon-sy">{</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-s">'crim'</span><span class="crayon-o">:</span> <span class="crayon-sy">[</span><span class="crayon-cn">0.03359</span><span class="crayon-sy">,</span><span class="crayon-cn">5.09017</span><span class="crayon-sy">,</span><span class="crayon-cn">0.12650</span><span class="crayon-sy">,</span><span class="crayon-cn">0.05515</span><span class="crayon-sy">,</span><span class="crayon-cn">8.15174</span><span class="crayon-sy">,</span><span class="crayon-cn">0.24522</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-s">'zn'</span><span class="crayon-o">:</span> <span class="crayon-sy">[</span><span class="crayon-cn">75.0</span><span class="crayon-sy">,</span><span class="crayon-cn">0.0</span><span class="crayon-sy">,</span><span class="crayon-cn">25.0</span><span class="crayon-sy">,</span><span class="crayon-cn">33.0</span><span class="crayon-sy">,</span><span class="crayon-cn">0.0</span><span class="crayon-sy">,</span><span class="crayon-cn">0.0</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-s">'indus'</span><span class="crayon-o">:</span> <span class="crayon-sy">[</span><span class="crayon-cn">2.95</span><span class="crayon-sy">,</span><span class="crayon-cn">18.10</span><span class="crayon-sy">,</span><span class="crayon-cn">5.13</span><span class="crayon-sy">,</span><span class="crayon-cn">2.18</span><span class="crayon-sy">,</span><span class="crayon-cn">18.10</span><span class="crayon-sy">,</span><span class="crayon-cn">9.90</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-s">'nox'</span><span class="crayon-o">:</span> <span class="crayon-sy">[</span><span class="crayon-cn">0.428</span><span class="crayon-sy">,</span><span class="crayon-cn">0.713</span><span class="crayon-sy">,</span><span class="crayon-cn">0.453</span><span class="crayon-sy">,</span><span class="crayon-cn">0.472</span><span class="crayon-sy">,</span><span class="crayon-cn">0.700</span><span class="crayon-sy">,</span><span class="crayon-cn">0.544</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-s">'rm'</span><span class="crayon-o">:</span> <span class="crayon-sy">[</span><span class="crayon-cn">7.024</span><span class="crayon-sy">,</span><span class="crayon-cn">6.297</span><span class="crayon-sy">,</span><span class="crayon-cn">6.762</span><span class="crayon-sy">,</span><span class="crayon-cn">7.236</span><span class="crayon-sy">,</span><span class="crayon-cn">5.390</span><span class="crayon-sy">,</span><span class="crayon-cn">5.782</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-s">'age'</span><span class="crayon-o">:</span> <span class="crayon-sy">[</span><span class="crayon-cn">15.8</span><span class="crayon-sy">,</span><span class="crayon-cn">91.8</span><span class="crayon-sy">,</span><span class="crayon-cn">43.4</span><span class="crayon-sy">,</span><span class="crayon-cn">41.1</span><span class="crayon-sy">,</span><span class="crayon-cn">98.9</span><span class="crayon-sy">,</span><span class="crayon-cn">71.7</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-8" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-s">'dis'</span><span class="crayon-o">:</span> <span class="crayon-sy">[</span><span class="crayon-cn">5.4011</span><span class="crayon-sy">,</span><span class="crayon-cn">2.3682</span><span class="crayon-sy">,</span><span class="crayon-cn">7.9809</span><span class="crayon-sy">,</span><span class="crayon-cn">4.0220</span><span class="crayon-sy">,</span><span class="crayon-cn">1.7281</span><span class="crayon-sy">,</span><span class="crayon-cn">4.0317</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-9" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-s">'tax'</span><span class="crayon-o">:</span> <span class="crayon-sy">[</span><span class="crayon-cn">252</span><span class="crayon-sy">,</span><span class="crayon-cn">666</span><span class="crayon-sy">,</span><span class="crayon-cn">284</span><span class="crayon-sy">,</span><span class="crayon-cn">222</span><span class="crayon-sy">,</span><span class="crayon-cn">666</span><span class="crayon-sy">,</span><span class="crayon-cn">304</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-10" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-s">'ptratio'</span><span class="crayon-o">:</span> <span class="crayon-sy">[</span><span class="crayon-cn">18.3</span><span class="crayon-sy">,</span><span class="crayon-cn">20.2</span><span class="crayon-sy">,</span><span class="crayon-cn">19.7</span><span class="crayon-sy">,</span><span class="crayon-cn">18.4</span><span class="crayon-sy">,</span><span class="crayon-cn">20.2</span><span class="crayon-sy">,</span><span class="crayon-cn">18.4</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-11" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-sy">}</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-12" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-e">def </span><span class="crayon-e">test_input_fn</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span><span class="crayon-o">:</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-13" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">dataset</span> <span class="crayon-o">=</span> <span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">data</span><span class="crayon-sy">.</span><span class="crayon-v">Dataset</span><span class="crayon-sy">.</span><span class="crayon-e">from_tensors</span><span class="crayon-sy">(</span><span class="crayon-v">prediction_input</span><span class="crayon-sy">)</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-14" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-st">return</span> <span class="crayon-i">dataset</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-15" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fe9e043dec319126100-16" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-p"># Predict all our prediction_inputpred_results = model.predict(input_fn=test_input_fn)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Cuối c&ugrave;ng, bạn in c&aacute;c dự đo&aacute;n.</p> <div id="urvanov-syntax-highlighter-610fe9e043dee293807087" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043dee293807087-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043dee293807087-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043dee293807087-1" class="crayon-line"><span class="crayon-st">for</span> <span class="crayon-e">pred </span><span class="crayon-st">in</span> <span class="crayon-e">enumerate</span><span class="crayon-sy">(</span><span class="crayon-v">pred_results</span><span class="crayon-sy">)</span><span class="crayon-o">:</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fe9e043dee293807087-2" class="crayon-line crayon-striped-line"><span class="crayon-e">print</span><span class="crayon-sy">(</span><span class="crayon-v">pred</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fe9e043df2283583077" class="urvanov-syntax-highlighter-syntax crayon-theme-classic urvanov-syntax-highlighter-font-monaco urvanov-syntax-highlighter-os-pc print-yes notranslate" style="text-align: justify;" data-settings=" minimize scroll-mouseover"> <div class="urvanov-syntax-highlighter-plain-wrap">&nbsp;</div> <div class="urvanov-syntax-highlighter-main"> <table class="crayon-table"> <tbody> <tr class="urvanov-syntax-highlighter-row"> <td class="crayon-nums " data-settings="show"> <div class="urvanov-syntax-highlighter-nums-content"> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043df2283583077-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043df2283583077-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043df2283583077-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043df2283583077-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043df2283583077-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043df2283583077-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043df2283583077-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043df2283583077-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043df2283583077-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043df2283583077-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043df2283583077-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043df2283583077-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fe9e043df2283583077-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fe9e043df2283583077-14">14</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fe9e043df2283583077-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-610fe9e043df2283583077-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-610fe9e043df2283583077-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">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-610fe9e043df2283583077-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">Restoring </span><span class="crayon-e">parameters </span><span class="crayon-e">from </span><span class="crayon-v">train3</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-610fe9e043df2283583077-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-610fe9e043df2283583077-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-610fe9e043df2283583077-7" class="crayon-line"><span class="crayon-sy">(</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span> <span class="crayon-sy">{</span><span class="crayon-s">'predictions'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">32.297546</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043df2283583077-8" class="crayon-line crayon-striped-line"><span class="crayon-sy">(</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span> <span class="crayon-sy">{</span><span class="crayon-s">'predictions'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">18.96125</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043df2283583077-9" class="crayon-line"><span class="crayon-sy">(</span><span class="crayon-cn">2</span><span class="crayon-sy">,</span> <span class="crayon-sy">{</span><span class="crayon-s">'predictions'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">27.270979</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043df2283583077-10" class="crayon-line crayon-striped-line"><span class="crayon-sy">(</span><span class="crayon-cn">3</span><span class="crayon-sy">,</span> <span class="crayon-sy">{</span><span class="crayon-s">'predictions'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">29.299236</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043df2283583077-11" class="crayon-line"><span class="crayon-sy">(</span><span class="crayon-cn">4</span><span class="crayon-sy">,</span> <span class="crayon-sy">{</span><span class="crayon-s">'predictions'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">16.436684</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043df2283583077-12" class="crayon-line crayon-striped-line"><span class="crayon-sy">(</span><span class="crayon-cn">5</span><span class="crayon-sy">,</span> <span class="crayon-sy">{</span><span class="crayon-s">'predictions'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">21.460876</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fe9e043df2283583077-13" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fe9e043df2283583077-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-e">Calling </span><span class="crayon-v">model_fn</span><span class="crayon-sy">.</span> <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> <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> <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">train3</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">5000</span> <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> <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> <span class="crayon-sy">(</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span> <span class="crayon-sy">{</span><span class="crayon-s">'predictions'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">35.60663</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span> <span class="crayon-sy">(</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span> <span class="crayon-sy">{</span><span class="crayon-s">'predictions'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">22.298521</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span> <span class="crayon-sy">(</span><span class="crayon-cn">2</span><span class="crayon-sy">,</span> <span class="crayon-sy">{</span><span class="crayon-s">'predictions'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">25.74533</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span> <span class="crayon-sy">(</span><span class="crayon-cn">3</span><span class="crayon-sy">,</span> <span class="crayon-sy">{</span><span class="crayon-s">'predictions'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">35.126694</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">}</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-sy">{</span><span class="crayon-s">'predictions'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">17.94416</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span> <span class="crayon-sy">(</span><span class="crayon-cn">5</span><span class="crayon-sy">,</span> <span class="crayon-sy">{</span><span class="crayon-s">'predictions'</span><span class="crayon-o">:</span> <span class="crayon-t">array</span><span class="crayon-sy">(</span><span class="crayon-sy">[</span><span class="crayon-cn">22.606628</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-v">float32</span><span class="crayon-sy">)</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <h3 id="ftoc-heading-5" class="ftwp-heading" style="text-align: justify;">Kết Luận</h3> <p style="text-align: justify;">Để đ&agrave;o tạo một model, bạn cần:</p> <ul style="text-align: justify;"> <li>X&aacute;c định c&aacute;c đặc trưng: C&aacute;c biến độc lập: X</li> <li>X&aacute;c định nh&atilde;n: Biến phụ thuộc: y</li> <li>X&acirc;y dựng một train/test set</li> <li>X&aacute;c định trọng số ban đầu</li> <li>X&aacute;c định h&agrave;m mất m&aacute;t: MSE</li> <li>Tối ưu h&oacute;a m&ocirc; h&igrave;nh: Gradient descent</li> <li>Định nghĩa: <ul> <li>Learning rate</li> <li>Số epoch</li> <li>Batch size</li> </ul> </li> </ul> <p style="text-align: justify;">B&agrave;i viết tiếp theo:&nbsp;<a href="../../hoi-quy-tuyen-tinh-cho-machine-learning-tu-hoc-tensorflow/#ftoc-heading-10" target="_blank" rel="noopener">Linear Regression cho Machine learning</a></p>