tek4

Linear Classifier với Tensorflow – Tự Học TensorFlow

by - September. 21, 2021
Họ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 classifier (ph&acirc;n loại tuyến t&iacute;nh) v&agrave; v&iacute; dụ minh họa về ph&acirc;n loại nhị ph&acirc;n. 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="../../hoi-quy-tuyen-tinh-cho-machine-learning-tu-hoc-tensorflow/#ftoc-heading-10" target="_blank" rel="noopener">Linear Regression cho Machine learning</a></p> <p style="text-align: justify;"><img class="aligncenter size-full wp-image-7364 disappear appear" src="../../wp-content/uploads/2021/01/11.png" sizes="(max-width: 1113px) 100vw, 1113px" srcset="https://old.tek4.vn/wp-content/uploads/2021/01/11.png 1113w, https://old.tek4.vn/wp-content/uploads/2021/01/11-300x156.png 300w, https://old.tek4.vn/wp-content/uploads/2021/01/11-1024x534.png 1024w, https://old.tek4.vn/wp-content/uploads/2021/01/11-768x400.png 768w" alt="" width="1113" height="580" loading="lazy" /></p> <h3 id="ftoc-heading-1" class="ftwp-heading" style="text-align: justify;">Linear Classifier l&agrave; g&igrave;</h3> <p style="text-align: justify;">Hai b&agrave;i to&aacute;n của học c&oacute; gi&aacute;m s&aacute;t (supervised learning) l&agrave; hồi quy tuyến t&iacute;nh (linear regression) v&agrave; ph&acirc;n loại tuyến t&iacute;nh (linear classifier). Hồi quy tuyến t&iacute;nh dự đo&aacute;n một gi&aacute; trị trong khi bộ ph&acirc;n loại tuyến t&iacute;nh dự đo&aacute;n một lớp. B&agrave;i viết n&agrave;y tập trung v&agrave;o ph&acirc;n loại tuyến t&iacute;nh.</p> <p style="text-align: justify;">C&aacute;c vấn đề ph&acirc;n loại đại diện cho khoảng 80% nhiệm vụ học m&aacute;y. Ph&acirc;n loại nhằm mục đ&iacute;ch dự đo&aacute;n x&aacute;c suất của mỗi lớp cho một tập hợp c&aacute;c đầu v&agrave;o. Nh&atilde;n (tức l&agrave; biến phụ thuộc) l&agrave; một gi&aacute; trị rời rạc, được gọi l&agrave; một lớp.</p> <ol style="text-align: justify;"> <li>Nếu nh&atilde;n chỉ c&oacute; hai lớp, thuật to&aacute;n học l&agrave; một bộ ph&acirc;n loại nhị ph&acirc;n (binary classifier).</li> <li>Ph&acirc;n loại đa lớp (Multiclass classifier) xử l&yacute; c&aacute;c nh&atilde;n c&oacute; nhiều hơn hai lớp.</li> </ol> <p style="text-align: justify;">V&iacute; dụ, một vấn đề ph&acirc;n loại nhị ph&acirc;n điển h&igrave;nh l&agrave; dự đo&aacute;n khả năng kh&aacute;ch h&agrave;ng mua h&agrave;ng lần thứ hai. Dự đo&aacute;n loại động vật hiển thị tr&ecirc;n h&igrave;nh l&agrave; b&agrave;i to&aacute;n ph&acirc;n loại đa lớp v&igrave; c&oacute; hơn hai loại động vật tồn tại.</p> <h3 id="ftoc-heading-2" class="ftwp-heading" style="text-align: justify;">Binary classifier hoạt động như thế n&agrave;o</h3> <p style="text-align: justify;">Ch&uacute;ng ta đ&atilde; biết trong hướng dẫn trước rằng một h&agrave;m bao gồm hai loại biến, một biến phụ thuộc v&agrave; một tập hợp c&aacute;c đặc trưng (biến độc lập). Trong hồi quy tuyến t&iacute;nh, một biến phụ thuộc l&agrave; một số thực kh&ocirc;ng c&oacute; phạm vi. Mục ti&ecirc;u ch&iacute;nh l&agrave; dự đo&aacute;n gi&aacute; trị của n&oacute; bằng c&aacute;ch giảm thiểu sai số b&igrave;nh phương trung b&igrave;nh (mean squared error).</p> <p style="text-align: justify;">Đối với một binary task, nh&atilde;n c&oacute; thể c&oacute; hai gi&aacute; trị nguy&ecirc;n. Trong hầu hết c&aacute;c trường hợp, n&oacute; l&agrave; [0,1] hoặc [1,2]. V&iacute; dụ, mục ti&ecirc;u l&agrave; dự đo&aacute;n liệu kh&aacute;ch h&agrave;ng c&oacute; mua sản phẩm hay kh&ocirc;ng. Nh&atilde;n được định nghĩa như sau:</p> <ul style="text-align: justify;"> <li>Y = 1 (kh&aacute;ch h&agrave;ng c&oacute; mua sản phẩm)</li> <li>Y = 0 (kh&aacute;ch h&agrave;ng kh&ocirc;ng mua sản phẩm</li> </ul> <p style="text-align: justify;">M&ocirc; h&igrave;nh sử dụng c&aacute;c đặc trưng X để ph&acirc;n loại kh&aacute;ch h&agrave;ng theo từng lớp c&oacute; khả năng nhất m&agrave; họ thuộc về, cụ thể l&agrave; người mua tiềm năng hay kh&ocirc;ng.</p> <p style="text-align: justify;">X&aacute;c suất th&agrave;nh c&ocirc;ng được t&iacute;nh bằng hồi quy logistic. Thuật to&aacute;n sẽ t&iacute;nh to&aacute;n x&aacute;c suất dựa tr&ecirc;n đặc trưng X v&agrave; dự đo&aacute;n th&agrave;nh c&ocirc;ng khi x&aacute;c suất n&agrave;y tr&ecirc;n 50%. Ch&iacute;nh thức hơn, x&aacute;c suất được t&iacute;nh như sau:</p> <p style="text-align: justify;"><span id="MathJax-Element-1-Frame" class="MathJax" tabindex="0"><span id="MathJax-Span-1" class="math"><span id="MathJax-Span-2" class="mrow"><span id="MathJax-Span-3" class="mi">P</span><span id="MathJax-Span-4" class="mo">(</span><span id="MathJax-Span-5" class="mi">Y</span><span id="MathJax-Span-6" class="mo">=</span><span id="MathJax-Span-7" class="mn">1</span><span id="MathJax-Span-8" class="texatom"><span id="MathJax-Span-9" class="mrow"><span id="MathJax-Span-10" class="mo">|</span></span></span><span id="MathJax-Span-11" class="mi">x</span><span id="MathJax-Span-12" class="mo">)</span><span id="MathJax-Span-13" class="mo">=</span><span id="MathJax-Span-14" class="mfrac"><span id="MathJax-Span-15" class="texatom"><span id="MathJax-Span-16" class="mrow"><span id="MathJax-Span-17" class="mn">1</span></span></span><span id="MathJax-Span-18" class="texatom"><span id="MathJax-Span-19" class="mrow"><span id="MathJax-Span-20" class="mn">1</span><span id="MathJax-Span-21" class="mo">+</span><span id="MathJax-Span-22" class="mi">e</span><span id="MathJax-Span-23" class="mi">x</span><span id="MathJax-Span-24" class="mi">p</span><span id="MathJax-Span-25" class="mo">(</span><span id="MathJax-Span-26" class="mo">&minus;</span><span id="MathJax-Span-27" class="mo">(</span><span id="MathJax-Span-28" class="msubsup"><span id="MathJax-Span-29" class="mi">&Theta;</span><span id="MathJax-Span-30" class="mi">T</span></span><span id="MathJax-Span-31" class="mi">x</span><span id="MathJax-Span-32" class="mo">+</span><span id="MathJax-Span-33" class="mi">b</span><span id="MathJax-Span-34" class="mo">)</span><span id="MathJax-Span-35" class="mo">)</span></span></span></span></span></span></span></p> <p style="text-align: justify;">Trong đ&oacute;&nbsp;<span id="MathJax-Element-2-Frame" class="MathJax" tabindex="0"><span id="MathJax-Span-36" class="math"><span id="MathJax-Span-37" class="mrow"><span id="MathJax-Span-38" class="mi">&Theta;</span></span></span></span>&nbsp;l&agrave; tập hợp c&aacute;c trọng số, c&aacute;c đặc trưng v&agrave; b l&agrave; độ lệch (bias).</p> <p style="text-align: justify;">H&agrave;m c&oacute; thể được chia th&agrave;nh hai phần:</p> <ul style="text-align: justify;"> <li>M&ocirc; h&igrave;nh tuyến t&iacute;nh</li> <li>H&agrave;m logistic</li> </ul> <h4 id="ftoc-heading-3" class="ftwp-heading" style="text-align: justify;"><strong>Linear model (M&ocirc; h&igrave;nh tuyến t&iacute;nh)</strong></h4> <p style="text-align: justify;">Bạn đ&atilde; quen với c&aacute;ch t&iacute;nh trọng số. Trọng số được t&iacute;nh bằng:&nbsp;<span id="MathJax-Element-3-Frame" class="MathJax" tabindex="0"><span id="MathJax-Span-39" class="math"><span id="MathJax-Span-40" class="mrow"><span id="MathJax-Span-41" class="msubsup"><span id="MathJax-Span-42" class="mi">&theta;</span><span id="MathJax-Span-43" class="mi">T</span></span><span id="MathJax-Span-44" class="mi">x</span><span id="MathJax-Span-45" class="mo">+</span><span id="MathJax-Span-46" class="mi">b</span><span id="MathJax-Span-47" class="mo">,</span><span id="MathJax-Span-48" class="msubsup"><span id="MathJax-Span-49" class="mo">&sum;</span><span id="MathJax-Span-50" class="texatom"><span id="MathJax-Span-51" class="mrow"><span id="MathJax-Span-52" class="mi">i</span><span id="MathJax-Span-53" class="mo">=</span><span id="MathJax-Span-54" class="mn">0</span></span></span><span id="MathJax-Span-55" class="texatom"><span id="MathJax-Span-56" class="mrow"><span id="MathJax-Span-57" class="mi">n</span></span></span></span><span id="MathJax-Span-58" class="msubsup"><span id="MathJax-Span-59" class="mi">x</span><span id="MathJax-Span-60" class="mi">i</span></span><span id="MathJax-Span-61" class="msubsup"><span id="MathJax-Span-62" class="mi">w</span><span id="MathJax-Span-63" class="mi">i</span></span><span id="MathJax-Span-64" class="mo">+</span><span id="MathJax-Span-65" class="mi">b</span></span></span></span>. Y l&agrave; h&agrave;m tuyến t&iacute;nh của tất cả c&aacute;c đặc trưng&nbsp;<span id="MathJax-Element-4-Frame" class="MathJax" tabindex="0"><span id="MathJax-Span-66" class="math"><span id="MathJax-Span-67" class="mrow"><span id="MathJax-Span-68" class="msubsup"><span id="MathJax-Span-69" class="mi">x</span><span id="MathJax-Span-70" class="mi">i</span></span></span></span></span>. Nếu m&ocirc; h&igrave;nh kh&ocirc;ng c&oacute; đặc trưng, dự đo&aacute;n bằng độ lệch, b.</p> <p style="text-align: justify;">C&aacute;c trọng số cho biết hướng tương quan giữa c&aacute;c đặc điểm&nbsp;<span id="MathJax-Element-5-Frame" class="MathJax" tabindex="0"><span id="MathJax-Span-71" class="math"><span id="MathJax-Span-72" class="mrow"><span id="MathJax-Span-73" class="msubsup"><span id="MathJax-Span-74" class="mi">x</span><span id="MathJax-Span-75" class="mi">i</span></span></span></span></span>&nbsp;v&agrave; nh&atilde;n y. Mối tương quan dương l&agrave;m tăng x&aacute;c suất của lớp dương trong khi mối tương quan &acirc;m dẫn đến x&aacute;c suất gần với 0, (tức l&agrave; lớp &acirc;m).</p> <p style="text-align: justify;">M&ocirc; h&igrave;nh tuyến t&iacute;nh chỉ trả về số thực, kh&ocirc;ng ph&ugrave; hợp với độ đo x&aacute;c suất của phạm vi [0,1]. Cần c&oacute; h&agrave;m logistic để chuyển đổi đầu ra của m&ocirc; h&igrave;nh tuyến t&iacute;nh th&agrave;nh x&aacute;c suất.</p> <h4 id="ftoc-heading-4" class="ftwp-heading" style="text-align: justify;"><strong>Logistic function&nbsp;</strong></h4> <p style="text-align: justify;">H&agrave;m logistic, hoặc h&agrave;m sigmoid, c&oacute; h&igrave;nh chữ S v&agrave; đầu ra của h&agrave;m n&agrave;y lu&ocirc;n nằm trong khoảng từ 0 đến 1.</p> <p style="text-align: justify;"><span id="MathJax-Element-6-Frame" class="MathJax" tabindex="0"><span id="MathJax-Span-76" class="math"><span id="MathJax-Span-77" class="mrow"><span id="MathJax-Span-78" class="mfrac"><span id="MathJax-Span-79" class="texatom"><span id="MathJax-Span-80" class="mrow"><span id="MathJax-Span-81" class="mn">1</span></span></span><span id="MathJax-Span-82" class="texatom"><span id="MathJax-Span-83" class="mrow"><span id="MathJax-Span-84" class="mn">1</span><span id="MathJax-Span-85" class="mo">+</span><span id="MathJax-Span-86" class="mi">e</span><span id="MathJax-Span-87" class="mi">x</span><span id="MathJax-Span-88" class="mi">p</span><span id="MathJax-Span-89" class="mo">(</span><span id="MathJax-Span-90" class="mo">&minus;</span><span id="MathJax-Span-91" class="mi">t</span><span id="MathJax-Span-92" class="mo">)</span></span></span></span></span></span></span></p> <p style="text-align: justify;">C&oacute; thể dễ d&agrave;ng thay thế đầu ra của hồi quy tuyến t&iacute;nh th&agrave;nh h&agrave;m sigmoid. N&oacute; dẫn đến một số mới với x&aacute;c suất từ ​​0 đến 1. Classifier&nbsp;c&oacute; thể chuyển đổi x&aacute;c suất th&agrave;nh một lớp:</p> <ul style="text-align: justify;"> <li>Gi&aacute; trị từ 0 đến 0,49 trở th&agrave;nh loại 0</li> <li>Gi&aacute; trị từ 0,5 đến 1 trở th&agrave;nh loại 1</li> </ul> <h3 id="ftoc-heading-5" class="ftwp-heading" style="text-align: justify;">L&agrave;m thế n&agrave;o để đo hiệu suất của Linear Classifier</h3> <h4 id="ftoc-heading-6" class="ftwp-heading" style="text-align: justify;">Accuracy</h4> <p style="text-align: justify;">Hiệu suất tổng thể của bộ ph&acirc;n loại được đo bằng chỉ số accuracy (độ ch&iacute;nh x&aacute;c). Độ ch&iacute;nh x&aacute;c thu thập tất cả c&aacute;c gi&aacute; trị ch&iacute;nh x&aacute;c chia cho tổng số lần quan s&aacute;t. V&iacute; dụ: gi&aacute; trị độ ch&iacute;nh x&aacute;c l&agrave; 80% c&oacute; nghĩa l&agrave; m&ocirc; h&igrave;nh đ&uacute;ng trong 80% c&aacute;c trường hợp.</p> <h4 id="ftoc-heading-7" class="ftwp-heading" style="text-align: justify;">Confusion matrix</h4> <p style="text-align: justify;">Một c&aacute;ch tốt hơn để đ&aacute;nh gi&aacute; hiệu suất của bộ ph&acirc;n loại l&agrave; xem x&eacute;t confusion matrix.</p> <p style="text-align: justify;">Confusion matrix trực quan h&oacute;a độ ch&iacute;nh x&aacute;c của bộ ph&acirc;n loại bằng c&aacute;ch so s&aacute;nh c&aacute;c lớp thực tế v&agrave; c&aacute;c lớp dự đo&aacute;n. Confusion matrix bao gồm:</p> <ul style="text-align: justify;"> <li>TP: True Positive: Gi&aacute; trị được dự đo&aacute;n ch&iacute;nh x&aacute;c l&agrave; gi&aacute; trị dương thực tế</li> <li>FP: Gi&aacute; trị được dự đo&aacute;n dự đo&aacute;n kh&ocirc;ng ch&iacute;nh x&aacute;c về gi&aacute; trị dương thực tế. Tức l&agrave; c&aacute;c gi&aacute; trị &acirc;m được dự đo&aacute;n l&agrave; dương</li> <li>FN: False Negative: Gi&aacute; trị dương được dự đo&aacute;n l&agrave; &acirc;m</li> <li>TN: True Negative: Gi&aacute; trị được dự đo&aacute;n được dự đo&aacute;n ch&iacute;nh x&aacute;c l&agrave; &acirc;m thực tế</li> </ul> <p style="text-align: justify;">Từ confusion matrix c&oacute; thể dễ d&agrave;ng so s&aacute;nh lớp thực tế v&agrave; lớp dự đo&aacute;n.</p> <h4 id="ftoc-heading-8" class="ftwp-heading" style="text-align: justify;">Precision v&agrave; Sensitivity</h4> <p style="text-align: justify;">Confusion matrix cung cấp một c&aacute;i nh&igrave;n s&acirc;u sắc về true positive v&agrave; false positive. Trong một số trường hợp, tốt hơn l&agrave; c&oacute; một số liệu ngắn gọn hơn.</p> <p style="text-align: justify;"><strong>Precision</strong></p> <p style="text-align: justify;">Precision cho thấy độ ch&iacute;nh x&aacute;c của lớp positive. N&oacute; đo lường khả năng dự đo&aacute;n của lớp positive l&agrave; đ&uacute;ng:</p> <p style="text-align: justify;"><span id="MathJax-Element-7-Frame" class="MathJax" tabindex="0"><span id="MathJax-Span-93" class="math"><span id="MathJax-Span-94" class="mrow"><span id="MathJax-Span-95" class="mi">P</span><span id="MathJax-Span-96" class="mi">r</span><span id="MathJax-Span-97" class="mi">e</span><span id="MathJax-Span-98" class="mi">c</span><span id="MathJax-Span-99" class="mi">i</span><span id="MathJax-Span-100" class="mi">s</span><span id="MathJax-Span-101" class="mi">i</span><span id="MathJax-Span-102" class="mi">o</span><span id="MathJax-Span-103" class="mi">n</span><span id="MathJax-Span-104" class="mo">=</span><span id="MathJax-Span-105" class="mfrac"><span id="MathJax-Span-106" class="texatom"><span id="MathJax-Span-107" class="mrow"><span id="MathJax-Span-108" class="mi">T</span><span id="MathJax-Span-109" class="mi">P</span></span></span><span id="MathJax-Span-110" class="texatom"><span id="MathJax-Span-111" class="mrow"><span id="MathJax-Span-112" class="mi">T</span><span id="MathJax-Span-113" class="mi">P</span><span id="MathJax-Span-114" class="mo">+</span><span id="MathJax-Span-115" class="mi">F</span><span id="MathJax-Span-116" class="mi">P</span></span></span></span></span></span></span></p> <p style="text-align: justify;">Điểm tối đa l&agrave; 1 khi bộ ph&acirc;n loại ph&acirc;n loại ho&agrave;n hảo tất cả c&aacute;c gi&aacute; trị positive. D&ugrave;ng ri&ecirc;ng Precision th&igrave; kh&ocirc;ng hữu &iacute;ch lắm v&igrave; n&oacute; bỏ qua negative. Chỉ số n&agrave;y thường được gh&eacute;p nối với chỉ số Recall. Recall c&ograve;n được gọi l&agrave; sensitivity hoặc true positive.</p> <p style="text-align: justify;"><strong>Sensitivity</strong></p> <p style="text-align: justify;">Sensitivity t&iacute;nh to&aacute;n tỷ lệ c&aacute;c lớp positive được ph&aacute;t hiện ch&iacute;nh x&aacute;c. Số liệu n&agrave;y cho biết mức độ tốt của m&ocirc; h&igrave;nh để nhận ra một lớp possitive.</p> <p style="text-align: justify;"><span id="MathJax-Element-8-Frame" class="MathJax" tabindex="0"><span id="MathJax-Span-117" class="math"><span id="MathJax-Span-118" class="mrow"><span id="MathJax-Span-119" class="mi">R</span><span id="MathJax-Span-120" class="mi">e</span><span id="MathJax-Span-121" class="mi">c</span><span id="MathJax-Span-122" class="mi">a</span><span id="MathJax-Span-123" class="mi">l</span><span id="MathJax-Span-124" class="mi">l</span><span id="MathJax-Span-125" class="mo">=</span><span id="MathJax-Span-126" class="mfrac"><span id="MathJax-Span-127" class="texatom"><span id="MathJax-Span-128" class="mrow"><span id="MathJax-Span-129" class="mi">T</span><span id="MathJax-Span-130" class="mi">P</span></span></span><span id="MathJax-Span-131" class="texatom"><span id="MathJax-Span-132" class="mrow"><span id="MathJax-Span-133" class="mi">T</span><span id="MathJax-Span-134" class="mi">P</span><span id="MathJax-Span-135" class="mo">+</span><span id="MathJax-Span-136" class="mi">F</span><span id="MathJax-Span-137" class="mi">N</span></span></span></span></span></span></span></p> <h3 id="ftoc-heading-9" class="ftwp-heading" style="text-align: justify;">Linear Classifier với TensorFlow</h3> <p style="text-align: justify;">Đối với b&agrave;i viết n&agrave;y, ch&uacute;ng ta sẽ sử dụng tập dữ liệu census dataset. Mục đ&iacute;ch l&agrave; sử dụng c&aacute;c biến trong tập dữ liệu điều tra d&acirc;n số để dự đo&aacute;n mức thu nhập. Lưu &yacute; rằng thu nhập l&agrave; một biến nhị ph&acirc;n</p> <ul style="text-align: justify;"> <li>Với gi&aacute; trị 1 nếu thu nhập&gt; 50k</li> <li>0 nếu thu nhập &lt;50k.</li> </ul> <p style="text-align: justify;">Biến n&agrave;y l&agrave; nh&atilde;n của bạn</p> <p style="text-align: justify;">Tập dữ liệu n&agrave;y bao gồm t&aacute;m biến ph&acirc;n loại:</p> <ul style="text-align: justify;"> <li>workplace</li> <li>education</li> <li>marital</li> <li>occupation</li> <li>relationship</li> <li>race</li> <li>sex</li> <li>native_country</li> </ul> <p style="text-align: justify;">V&agrave; s&aacute;u biến li&ecirc;n tục:</p> <ul style="text-align: justify;"> <li>age</li> <li>fnlwgt</li> <li>education_num</li> <li>capital_gain</li> <li>capital_loss</li> <li>hours_week</li> </ul> <p style="text-align: justify;">Th&ocirc;ng qua v&iacute; dụ về Ph&acirc;n loại TensorFlow n&agrave;y, bạn sẽ hiểu c&aacute;ch đ&agrave;o tạo Bộ ph&acirc;n loại TensorFlow tuyến t&iacute;nh với TensorFlow estimator v&agrave; c&aacute;ch cải thiện chỉ số độ ch&iacute;nh x&aacute;c.</p> <p style="text-align: justify;">Ch&uacute;ng ta sẽ tiến h&agrave;nh như sau:</p> <ul style="text-align: justify;"> <li>Bước 1) Nhập dữ liệu</li> <li>Bước 2) Chuyển đổi dữ liệu</li> <li>Bước 3) Đ&agrave;o tạo tr&igrave;nh ph&acirc;n loại</li> <li>Bước 4) Cải thiện m&ocirc; h&igrave;nh</li> <li>Bước 5) Si&ecirc;u tham số: Lasso &amp; Ridge</li> </ul> <h4 id="ftoc-heading-10" class="ftwp-heading" style="text-align: justify;">Bước 1) Nhập dữTensorflow y&ecirc;u cầu gi&aacute; trị Boolean để đ&agrave;o tạo bộ ph&acirc;n loại. liệu</h4> <p style="text-align: justify;">Trước ti&ecirc;n, ch&uacute;ng ta import c&aacute;c thư viện cần thiết.</p> <div id="urvanov-syntax-highlighter-610fea87ebeda430917919" 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-610fea87ebeda430917919-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeda430917919-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebeda430917919-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-610fea87ebeda430917919-2" class="crayon-line crayon-striped-line"><span class="crayon-e">import </span><span class="crayon-e">pandas </span><span class="crayon-st">as</span> <span class="crayon-v">pd</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Tiếp theo, cần nhập dữ liệu từ kho lưu trữ của UCI v&agrave; x&aacute;c định t&ecirc;n c&aacute;c cột. Ta sẽ sử dụng COLUMNS để đặt t&ecirc;n cho c&aacute;c cột trong khung dữ liệu pandas.</p> <p style="text-align: justify;">Lưu &yacute; rằng ta sẽ đ&agrave;o tạo tr&igrave;nh ph&acirc;n loại bằng c&aacute;ch sử dụng khung dữ liệu Pandas.</p> <div id="urvanov-syntax-highlighter-610fea87ebee2632520278" 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-610fea87ebee2632520278-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebee2632520278-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebee2632520278-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebee2632520278-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebee2632520278-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebee2632520278-6">6</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebee2632520278-1" class="crayon-line"><span class="crayon-p">## Define path data</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee2632520278-2" class="crayon-line crayon-striped-line"><span class="crayon-v">COLUMNS</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-s">'age'</span><span class="crayon-sy">,</span><span class="crayon-s">'workclass'</span><span class="crayon-sy">,</span> <span class="crayon-s">'fnlwgt'</span><span class="crayon-sy">,</span> <span class="crayon-s">'education'</span><span class="crayon-sy">,</span> <span class="crayon-s">'education_num'</span><span class="crayon-sy">,</span> <span class="crayon-s">'marital'</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee2632520278-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-s">'occupation'</span><span class="crayon-sy">,</span> <span class="crayon-s">'relationship'</span><span class="crayon-sy">,</span> <span class="crayon-s">'race'</span><span class="crayon-sy">,</span> <span class="crayon-s">'sex'</span><span class="crayon-sy">,</span> <span class="crayon-s">'capital_gain'</span><span class="crayon-sy">,</span> <span class="crayon-s">'capital_loss'</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee2632520278-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">'hours_week'</span><span class="crayon-sy">,</span> <span class="crayon-s">'native_country'</span><span class="crayon-sy">,</span> <span class="crayon-s">'label'</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee2632520278-5" class="crayon-line"><span class="crayon-v">PATH</span> <span class="crayon-o">=</span> <span class="crayon-s">"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.data"</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee2632520278-6" class="crayon-line crayon-striped-line"><span class="crayon-v">PATH_test</span> <span class="crayon-o">=</span> <span class="crayon-s">"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.test"</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Dữ liệu được lưu trữ trực tuyến đ&atilde; được ph&acirc;n chia train set v&agrave; test set.</p> <div id="urvanov-syntax-highlighter-610fea87ebee4590155869" 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-610fea87ebee4590155869-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebee4590155869-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebee4590155869-1" class="crayon-line"><span class="crayon-v">df_train</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-v">PATH</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">names</span> <span class="crayon-o">=</span> <span class="crayon-v">COLUMNS</span><span class="crayon-sy">,</span> <span class="crayon-v">index_col</span><span class="crayon-o">=</span><span class="crayon-t">False</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee4590155869-2" class="crayon-line crayon-striped-line"><span class="crayon-v">df_test</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-v">PATH_test</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">skipinitialspace</span><span class="crayon-o">=</span><span class="crayon-t">True</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> <span class="crayon-v">index_col</span><span class="crayon-o">=</span><span class="crayon-t">False</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Tập huấn luyện chứa 32.561 dữ liệu v&agrave; tập kiểm tra chưa 16.281.</p> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183" 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-610fea87ebee6661914183-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebee6661914183-19">19</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-1" class="crayon-line"><span class="crayon-e">print</span><span class="crayon-sy">(</span><span class="crayon-v">df_train</span><span class="crayon-sy">.</span><span class="crayon-v">shape</span><span class="crayon-sy">,</span> <span class="crayon-v">df_test</span><span class="crayon-sy">.</span><span class="crayon-v">shape</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-2" class="crayon-line crayon-striped-line"><span class="crayon-e">print</span><span class="crayon-sy">(</span><span class="crayon-v">df_train</span><span class="crayon-sy">.</span><span class="crayon-v">dtypes</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-3" class="crayon-line"><span class="crayon-sy">(</span><span class="crayon-cn">32561</span><span class="crayon-sy">,</span> <span class="crayon-cn">15</span><span class="crayon-sy">)</span> <span class="crayon-sy">(</span><span class="crayon-cn">16281</span><span class="crayon-sy">,</span> <span class="crayon-cn">15</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-4" class="crayon-line crayon-striped-line"><span class="crayon-e">age&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-e">int64</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-5" class="crayon-line"><span class="crayon-e">workclass&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-6" class="crayon-line crayon-striped-line"><span class="crayon-e">fnlwgt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-e">int64</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-7" class="crayon-line"><span class="crayon-e">education&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-8" class="crayon-line crayon-striped-line"><span class="crayon-e">education_num&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-e">int64</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-9" class="crayon-line"><span class="crayon-e">marital&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-10" class="crayon-line crayon-striped-line"><span class="crayon-e">occupation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-11" class="crayon-line"><span class="crayon-e">relationship&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-12" class="crayon-line crayon-striped-line"><span class="crayon-e">race&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-13" class="crayon-line"><span class="crayon-e">sex&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-14" class="crayon-line crayon-striped-line"><span class="crayon-e">capital_gain&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-e">int64</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-15" class="crayon-line"><span class="crayon-e">capital_loss&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-e">int64</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-16" class="crayon-line crayon-striped-line"><span class="crayon-e">hours_week&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-e">int64</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-17" class="crayon-line"><span class="crayon-e">native_country&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-18" class="crayon-line crayon-striped-line"><span class="crayon-e">label&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee6661914183-19" class="crayon-line"><span class="crayon-v">dtype</span><span class="crayon-o">:</span> <span class="crayon-t">object</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Tensorflow y&ecirc;u cầu gi&aacute; trị Boolean để đ&agrave;o tạo bộ ph&acirc;n loại. Bạn cần truyền c&aacute;c gi&aacute; trị từ kiểu chuỗi sang kiểu số nguy&ecirc;n. Nh&atilde;n được lưu trữ dưới dạng một đối tượng, tuy nhi&ecirc;n, bạn cần chuyển n&oacute; th&agrave;nh một gi&aacute; trị số. Đoạn m&atilde; dưới đ&acirc;y tạo một từ điển với c&aacute;c gi&aacute; trị để chuyển đổi v&agrave; lặp qua mục cột. Lưu &yacute; rằng bạn thực hiện thao t&aacute;c n&agrave;y hai lần, một cho trainset một cho testset.</p> <div id="urvanov-syntax-highlighter-610fea87ebee8788218555" 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-610fea87ebee8788218555-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebee8788218555-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebee8788218555-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebee8788218555-4">4</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebee8788218555-1" class="crayon-line"><span class="crayon-v">label</span> <span class="crayon-o">=</span> <span class="crayon-sy">{</span><span class="crayon-s">'&amp;lt;=50K'</span><span class="crayon-o">:</span> <span class="crayon-cn">0</span><span class="crayon-sy">,</span><span class="crayon-s">'&amp;gt;50K'</span><span class="crayon-o">:</span> <span class="crayon-cn">1</span><span class="crayon-sy">}</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee8788218555-2" class="crayon-line crayon-striped-line"><span class="crayon-v">df_train</span><span class="crayon-sy">.</span><span class="crayon-v">label</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-v">label</span><span class="crayon-sy">[</span><span class="crayon-v">item</span><span class="crayon-sy">]</span> <span class="crayon-st">for</span> <span class="crayon-e">item </span><span class="crayon-st">in</span> <span class="crayon-v">df_train</span><span class="crayon-sy">.</span><span class="crayon-v">label</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee8788218555-3" class="crayon-line"><span class="crayon-v">label_t</span> <span class="crayon-o">=</span> <span class="crayon-sy">{</span><span class="crayon-s">'&amp;lt;=50K.'</span><span class="crayon-o">:</span> <span class="crayon-cn">0</span><span class="crayon-sy">,</span><span class="crayon-s">'&amp;gt;50K.'</span><span class="crayon-o">:</span> <span class="crayon-cn">1</span><span class="crayon-sy">}</span></div> <div id="urvanov-syntax-highlighter-610fea87ebee8788218555-4" class="crayon-line crayon-striped-line"><span class="crayon-v">df_test</span><span class="crayon-sy">.</span><span class="crayon-v">label</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-v">label_t</span><span class="crayon-sy">[</span><span class="crayon-v">item</span><span class="crayon-sy">]</span> <span class="crayon-st">for</span> <span class="crayon-e">item </span><span class="crayon-st">in</span> <span class="crayon-v">df_test</span><span class="crayon-sy">.</span><span class="crayon-v">label</span><span class="crayon-sy">]</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Trong trainset, c&oacute; 24.720 thu nhập thấp hơn 50k v&agrave; 7841 thu nhập ở tr&ecirc;n.Tỷ lệ gần như giống nhau đối với bộ thử nghiệm.</p> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445" 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-610fea87ebeea782878445-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-20">20</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-21">21</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-22">22</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-23">23</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-24">24</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-25">25</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-26">26</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeea782878445-27">27</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-1" class="crayon-line"><span class="crayon-e">print</span><span class="crayon-sy">(</span><span class="crayon-v">df_train</span><span class="crayon-sy">[</span><span class="crayon-s">"label"</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-e">value_counts</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-2" class="crayon-line crayon-striped-line"><span class="crayon-p">### The model will be correct in atleast 70% of the case</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-3" class="crayon-line"><span class="crayon-e">print</span><span class="crayon-sy">(</span><span class="crayon-v">df_test</span><span class="crayon-sy">[</span><span class="crayon-s">"label"</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-e">value_counts</span><span class="crayon-sy">(</span><span class="crayon-sy">)</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-4" class="crayon-line crayon-striped-line"><span class="crayon-p">## Unbalanced label</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-5" class="crayon-line"><span class="crayon-e">print</span><span class="crayon-sy">(</span><span class="crayon-v">df_train</span><span class="crayon-sy">.</span><span class="crayon-v">dtypes</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-6" class="crayon-line crayon-striped-line"><span class="crayon-cn">0</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-cn">24720</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-7" class="crayon-line"><span class="crayon-cn">1</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-cn">7841</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-8" class="crayon-line crayon-striped-line"><span class="crayon-v">Name</span><span class="crayon-o">:</span> <span class="crayon-v">label</span><span class="crayon-sy">,</span> <span class="crayon-v">dtype</span><span class="crayon-o">:</span> <span class="crayon-i">int64</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-9" class="crayon-line"><span class="crayon-cn">0</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-cn">12435</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-10" class="crayon-line crayon-striped-line"><span class="crayon-cn">1</span><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-cn">3846</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-11" class="crayon-line"><span class="crayon-v">Name</span><span class="crayon-o">:</span> <span class="crayon-v">label</span><span class="crayon-sy">,</span> <span class="crayon-v">dtype</span><span class="crayon-o">:</span> <span class="crayon-e">int64</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-12" class="crayon-line crayon-striped-line"><span class="crayon-e">age&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-e">int64</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-13" class="crayon-line"><span class="crayon-e">workclass&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-14" class="crayon-line crayon-striped-line"><span class="crayon-e">fnlwgt&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-e">int64</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-15" class="crayon-line"><span class="crayon-e">education&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-16" class="crayon-line crayon-striped-line"><span class="crayon-e">education_num&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-e">int64</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-17" class="crayon-line"><span class="crayon-e">marital&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-18" class="crayon-line crayon-striped-line"><span class="crayon-e">occupation&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-19" class="crayon-line"><span class="crayon-e">relationship&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-20" class="crayon-line crayon-striped-line"><span class="crayon-e">race&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-21" class="crayon-line"><span class="crayon-e">sex&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-22" class="crayon-line crayon-striped-line"><span class="crayon-e">capital_gain&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-e">int64</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-23" class="crayon-line"><span class="crayon-e">capital_loss&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-e">int64</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-24" class="crayon-line crayon-striped-line"><span class="crayon-e">hours_week&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-e">int64</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-25" class="crayon-line"><span class="crayon-e">native_country&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-t">object</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-26" class="crayon-line crayon-striped-line"><span class="crayon-e">label&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-e">int64</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeea782878445-27" class="crayon-line"><span class="crayon-v">dtype</span><span class="crayon-o">:</span> <span class="crayon-t">object</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <h4 id="ftoc-heading-11" class="ftwp-heading" style="text-align: justify;">Bước 2) Chuyển đổi dữ liệu</h4> <p style="text-align: justify;">Bạn cần thực hiện một số bước trước khi đ&agrave;o tạo bộ ph&acirc;n loại tuyến t&iacute;nh với Tensorflow. Cần chuẩn bị c&aacute;c đặc trưng để đưa v&agrave;o m&ocirc; h&igrave;nh. Trong benchmark regression, bạn sẽ sử dụng dữ liệu gốc m&agrave; kh&ocirc;ng &aacute;p dụng bất kỳ biến đổi n&agrave;o.</p> <p style="text-align: justify;">Estimator cần c&oacute; một danh s&aacute;ch c&aacute;c đặc trưng để huấn luyện m&ocirc; h&igrave;nh. Do đ&oacute;, dữ liệu của cột y&ecirc;u cầu được chuyển đổi th&agrave;nh tensor.</p> <p style="text-align: justify;">Một phương ph&aacute;p hay l&agrave; x&aacute;c định hai danh s&aacute;ch c&aacute;c đặc trưng dựa tr&ecirc;n loại của ch&uacute;ng v&agrave; sau đ&oacute; chuyển ch&uacute;ng v&agrave;o feature_columns của estimator.</p> <p style="text-align: justify;">Bạn sẽ bắt đầu bằng c&aacute;ch chuyển đổi c&aacute;c đặc trưng li&ecirc;n tục, sau đ&oacute; x&aacute;c định nh&oacute;m với dữ liệu ph&acirc;n loại.</p> <p style="text-align: justify;">C&aacute;c đặc trưng của tập dữ liệu c&oacute; hai định dạng:</p> <ul style="text-align: justify;"> <li>Integer</li> <li>Object</li> </ul> <p style="text-align: justify;">Mỗi đặc trưng được liệt k&ecirc; trong hai biến tiếp theo t&ugrave;y theo loại của ch&uacute;ng.</p> <div id="urvanov-syntax-highlighter-610fea87ebeec962187321" 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-610fea87ebeec962187321-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeec962187321-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeec962187321-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeec962187321-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeec962187321-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebeec962187321-1" class="crayon-line"><span class="crayon-p">## Add features to the bucket: </span></div> <div id="urvanov-syntax-highlighter-610fea87ebeec962187321-2" class="crayon-line crayon-striped-line"><span class="crayon-p">### Define continuous list</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeec962187321-3" class="crayon-line"><span class="crayon-v">CONTI_FEATURES</span><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-s">'age'</span><span class="crayon-sy">,</span> <span class="crayon-s">'fnlwgt'</span><span class="crayon-sy">,</span><span class="crayon-s">'capital_gain'</span><span class="crayon-sy">,</span> <span class="crayon-s">'education_num'</span><span class="crayon-sy">,</span> <span class="crayon-s">'capital_loss'</span><span class="crayon-sy">,</span> <span class="crayon-s">'hours_week'</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeec962187321-4" class="crayon-line crayon-striped-line"><span class="crayon-p">### Define the categorical list</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeec962187321-5" class="crayon-line"><span class="crayon-v">CATE_FEATURES</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-s">'workclass'</span><span class="crayon-sy">,</span> <span class="crayon-s">'education'</span><span class="crayon-sy">,</span> <span class="crayon-s">'marital'</span><span class="crayon-sy">,</span> <span class="crayon-s">'occupation'</span><span class="crayon-sy">,</span> <span class="crayon-s">'relationship'</span><span class="crayon-sy">,</span> <span class="crayon-s">'race'</span><span class="crayon-sy">,</span> <span class="crayon-s">'sex'</span><span class="crayon-sy">,</span> <span class="crayon-s">'native_country'</span><span class="crayon-sy">]</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Feature_column được trang bị một object numeric_column để gi&uacute;p chuyển đổi c&aacute;c biến li&ecirc;n tục th&agrave;nh tensor. Trong đoạn m&atilde; dưới đ&acirc;y, bạn chuyển đổi tất cả c&aacute;c biến từ CONTI_FEATURES th&agrave;nh một tensor c&oacute; gi&aacute; trị số. Đ&acirc;y l&agrave; điều bắt buộc để x&acirc;y dựng m&ocirc; h&igrave;nh. Tất cả c&aacute;c biến độc lập cần được chuyển đổi th&agrave;nh kiểu tensor th&iacute;ch hợp.</p> <p style="text-align: justify;">Đoạn code dưới đ&acirc;y sẽ cho bạn biết điều g&igrave; đang xảy ra đằng sau feature_column.numeric_column. Ch&uacute;ng ta sẽ in gi&aacute; trị đ&atilde; chuyển đổi cho age, nhằm mục đ&iacute;ch giải th&iacute;ch, do đ&oacute; kh&ocirc;ng cần hiểu code python. Bạn c&oacute; thể tham khảo t&agrave;i liệu ch&iacute;nh thức để hiểu c&aacute;c code.</p> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001" 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-610fea87ebeee652083001-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-20">20</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-21">21</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-22">22</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-23">23</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-24">24</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-25">25</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-26">26</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-27">27</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-28">28</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-29">29</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-30">30</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-31">31</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-32">32</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-33">33</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-34">34</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-35">35</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-36">36</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-37">37</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-38">38</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-39">39</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-40">40</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebeee652083001-41">41</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-1" class="crayon-line"><span class="crayon-e">def </span><span class="crayon-e">print_transformation</span><span class="crayon-sy">(</span><span class="crayon-v">feature</span> <span class="crayon-o">=</span> <span class="crayon-s">"age"</span><span class="crayon-sy">,</span> <span class="crayon-v">continuous</span> <span class="crayon-o">=</span> <span class="crayon-t">True</span><span class="crayon-sy">,</span> <span class="crayon-v">size</span> <span class="crayon-o">=</span> <span class="crayon-cn">2</span><span class="crayon-sy">)</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-p">#X = fc.numeric_column(feature)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-p">## Create feature name</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">feature_names</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">feature</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-6" class="crayon-line crayon-striped-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-p">## Create dict with the data</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-8" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">d</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">feature_names</span><span class="crayon-sy">,</span> <span class="crayon-sy">[</span><span class="crayon-v">df_train</span><span class="crayon-sy">[</span><span class="crayon-v">feature</span><span class="crayon-sy">]</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-9" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-10" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-p">## Convert age</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-11" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">if</span> <span class="crayon-v">continuous</span> <span class="crayon-o">==</span> <span class="crayon-t">True</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-12" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">c</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-v">feature</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-13" class="crayon-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-sy">[</span><span class="crayon-v">c</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-14" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">else</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-15" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">c</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">categorical_column_with_hash_bucket</span><span class="crayon-sy">(</span><span class="crayon-v">feature</span><span class="crayon-sy">,</span> <span class="crayon-v">hash_bucket_size</span><span class="crayon-o">=</span><span class="crayon-v">size</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-16" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">c_indicator</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">indicator_column</span><span class="crayon-sy">(</span><span class="crayon-v">c</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-17" class="crayon-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-sy">[</span><span class="crayon-v">c_indicator</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-18" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-19" class="crayon-line"><span class="crayon-p">## Use input_layer to print the value</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-20" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">input_layer</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">input_layer</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-21" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">features</span><span class="crayon-o">=</span><span class="crayon-v">d</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-22" 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</span><span class="crayon-sy">_</span>columns</div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-23" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-24" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-p">## Create lookup table</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-25" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">zero</span> <span class="crayon-o">=</span> <span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-e">constant</span><span class="crayon-sy">(</span><span class="crayon-cn">0</span><span class="crayon-sy">,</span> <span class="crayon-v">dtype</span><span class="crayon-o">=</span><span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">float32</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-26" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">where</span> <span class="crayon-o">=</span> <span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-e">not_equal</span><span class="crayon-sy">(</span><span class="crayon-v">input_layer</span><span class="crayon-sy">,</span> <span class="crayon-v">zero</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-27" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-p">## Return lookup tble</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-28" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">indices</span> <span class="crayon-o">=</span> <span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-e">where</span><span class="crayon-sy">(</span><span class="crayon-v">where</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-29" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">values</span> <span class="crayon-o">=</span> <span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-e">gather_nd</span><span class="crayon-sy">(</span><span class="crayon-v">input_layer</span><span class="crayon-sy">,</span> <span class="crayon-v">indices</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-30" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-p">## Initiate graph</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-31" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">sess</span> <span class="crayon-o">=</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></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-32" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-p">## Print value</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-33" class="crayon-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">sess</span><span class="crayon-sy">.</span><span class="crayon-e">run</span><span class="crayon-sy">(</span><span class="crayon-v">input_layer</span><span class="crayon-sy">)</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-34" class="crayon-line crayon-striped-line"><span class="crayon-e">print_transformation</span><span class="crayon-sy">(</span><span class="crayon-v">feature</span> <span class="crayon-o">=</span> <span class="crayon-s">"age"</span><span class="crayon-sy">,</span> <span class="crayon-v">continuous</span> <span class="crayon-o">=</span> <span class="crayon-t">True</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-35" class="crayon-line"><span class="crayon-sy">[</span><span class="crayon-sy">[</span><span class="crayon-cn">39.</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-36" class="crayon-line crayon-striped-line"><span class="crayon-sy">[</span><span class="crayon-cn">50.</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-37" class="crayon-line"><span class="crayon-sy">[</span><span class="crayon-cn">38.</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-38" class="crayon-line crayon-striped-line"><span class="crayon-sy">.</span><span class="crayon-sy">.</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-39" class="crayon-line"><span class="crayon-sy">[</span><span class="crayon-cn">58.</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-40" class="crayon-line crayon-striped-line"><span class="crayon-sy">[</span><span class="crayon-cn">22.</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebeee652083001-41" class="crayon-line"><span class="crayon-sy">[</span><span class="crayon-cn">52.</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&aacute;c gi&aacute; trị ho&agrave;n to&agrave;n giống như trong df_train.</p> <div id="urvanov-syntax-highlighter-610fea87ebef0255495139" 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-610fea87ebef0255495139-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebef0255495139-1" class="crayon-line"><span class="crayon-v">continuous_features</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">feature_column</span><span class="crayon-sy">.</span><span class="crayon-e">numeric_column</span><span class="crayon-sy">(</span><span class="crayon-v">k</span><span class="crayon-sy">)</span> <span class="crayon-st">for</span> <span class="crayon-i">k</span> <span class="crayon-st">in</span> <span class="crayon-v">CONTI_FEATURES</span><span class="crayon-sy">]</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Theo t&agrave;i liệu TensorFlow, c&oacute; nhiều c&aacute;ch kh&aacute;c nhau để chuyển đổi dữ liệu ph&acirc;n loại. Nếu danh s&aacute;ch của một đặc trưng đ&atilde; biết v&agrave; kh&ocirc;ng c&oacute; nhiều gi&aacute; trị, bạn c&oacute; thể tạo cột ph&acirc;n loại với categorical_column_with_vocabulary_list. N&oacute; sẽ g&aacute;n cho tất cả danh s&aacute;ch một ID.</p> <p style="text-align: justify;">V&iacute; dụ: nếu một biến c&oacute; ba gi&aacute; trị kh&aacute;c nhau:</p> <ul style="text-align: justify;"> <li>Husband</li> <li>Wife</li> <li>Single</li> </ul> <p style="text-align: justify;">Sau đ&oacute;, ba ID sẽ được quy định. V&iacute; dụ, husband sẽ c&oacute; ID 1, wife c&oacute; ID 2, v.v.</p> <p style="text-align: justify;">Với mục đ&iacute;ch minh họa, bạn c&oacute; thể sử dụng m&atilde; n&agrave;y để chuyển đổi một biến đối tượng th&agrave;nh một cột ph&acirc;n loại trong TensorFlow.</p> <p style="text-align: justify;">Đặc trưng sex chỉ c&oacute; 2 gi&aacute; trị l&agrave; male hoặc female. Khi ch&uacute;ng ta chuyển đổi đặc trưng n&agrave;y, Tensorflow sẽ tạo 2 cột mới, một cột d&agrave;nh cho male v&agrave; một cột d&agrave;nh cho female. Nếu giới t&iacute;nh bằng male th&igrave; cột mới bằng 1 v&agrave; female bằng 0. V&iacute; dụ n&agrave;y được hiển thị trong bảng dưới đ&acirc;y:</p> <table class="table table-striped aligncenter"> <tbody> <tr> <td>rows</td> <td>sex</td> <td>after transformation</td> <td>male</td> <td>female</td> </tr> <tr> <td>1</td> <td>male</td> <td>=&gt;</td> <td>1</td> <td>0</td> </tr> <tr> <td>2</td> <td>male</td> <td>=&gt;</td> <td>1</td> <td>0</td> </tr> <tr> <td>3</td> <td>female</td> <td>=&gt;</td> <td>0</td> <td>1</td> </tr> </tbody> </table> <p style="text-align: justify;">Trong Tensorflow:</p> <div id="urvanov-syntax-highlighter-610fea87ebef3178418925" 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-610fea87ebef3178418925-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebef3178418925-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebef3178418925-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebef3178418925-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebef3178418925-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebef3178418925-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebef3178418925-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebef3178418925-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebef3178418925-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebef3178418925-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebef3178418925-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebef3178418925-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebef3178418925-13">13</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebef3178418925-1" class="crayon-line"><span class="crayon-e">print_transformation</span><span class="crayon-sy">(</span><span class="crayon-v">feature</span> <span class="crayon-o">=</span> <span class="crayon-s">"sex"</span><span class="crayon-sy">,</span> <span class="crayon-v">continuous</span> <span class="crayon-o">=</span> <span class="crayon-t">False</span><span class="crayon-sy">,</span> <span class="crayon-v">size</span> <span class="crayon-o">=</span> <span class="crayon-cn">2</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebef3178418925-2" class="crayon-line crayon-striped-line"><span class="crayon-sy">[</span><span class="crayon-sy">[</span><span class="crayon-cn">1.</span> <span class="crayon-cn">0.</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebef3178418925-3" class="crayon-line"><span class="crayon-sy">[</span><span class="crayon-cn">1.</span> <span class="crayon-cn">0.</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebef3178418925-4" class="crayon-line crayon-striped-line"><span class="crayon-sy">[</span><span class="crayon-cn">1.</span> <span class="crayon-cn">0.</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebef3178418925-5" class="crayon-line"><span class="crayon-sy">.</span><span class="crayon-sy">.</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebef3178418925-6" class="crayon-line crayon-striped-line"><span class="crayon-sy">[</span><span class="crayon-cn">0.</span> <span class="crayon-cn">1.</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebef3178418925-7" class="crayon-line"><span class="crayon-sy">[</span><span class="crayon-cn">1.</span> <span class="crayon-cn">0.</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebef3178418925-8" class="crayon-line crayon-striped-line"><span class="crayon-sy">[</span><span class="crayon-cn">0.</span> <span class="crayon-cn">1.</span><span class="crayon-sy">]</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebef3178418925-9" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebef3178418925-10" class="crayon-line crayon-striped-line"><span class="crayon-v">relationship</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">categorical_column_with_vocabulary_list</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea87ebef3178418925-11" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-s">'relationship'</span><span class="crayon-sy">,</span> <span class="crayon-sy">[</span></div> <div id="urvanov-syntax-highlighter-610fea87ebef3178418925-12" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-s">'Husband'</span><span class="crayon-sy">,</span> <span class="crayon-s">'Not-in-family'</span><span class="crayon-sy">,</span> <span class="crayon-s">'Wife'</span><span class="crayon-sy">,</span> <span class="crayon-s">'Own-child'</span><span class="crayon-sy">,</span> <span class="crayon-s">'Unmarried'</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebef3178418925-13" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-s">'Other-relative'</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Tuy nhi&ecirc;n, một c&aacute;ch nhanh hơn để chuyển đổi dữ liệu l&agrave; sử dụng phương thức categorical_column_with_hash_bucket. Việc thay đổi c&aacute;c biến string trong một sparse matrix sẽ rất hữu &iacute;ch. Sparse matrix l&agrave; ma trận c&oacute; phần lớn l&agrave; 0. Bạn chỉ cần chỉ định số lượng buckets v&agrave; cột kh&oacute;a. Số lượng buckets l&agrave; số lượng nh&oacute;m tối đa m&agrave; Tensorflow c&oacute; thể tạo. Cột kh&oacute;a chỉ đơn giản l&agrave; t&ecirc;n của cột cần chuyển đổi.</p> <p style="text-align: justify;">Trong đoạn m&atilde; dưới đ&acirc;y, bạn tạo một v&ograve;ng lặp tr&ecirc;n tất cả c&aacute;c đặc trưng ph&acirc;n loại.</p> <div id="urvanov-syntax-highlighter-610fea87ebef5991502429" 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-610fea87ebef5991502429-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebef5991502429-1" class="crayon-line"><span class="crayon-v">categorical_features</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">feature_column</span><span class="crayon-sy">.</span><span class="crayon-e">categorical_column_with_hash_bucket</span><span class="crayon-sy">(</span><span class="crayon-v">k</span><span class="crayon-sy">,</span> <span class="crayon-v">hash_bucket_size</span><span class="crayon-o">=</span><span class="crayon-cn">1000</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">CATE_FEATURES</span><span class="crayon-sy">]</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <h4 id="ftoc-heading-12" class="ftwp-heading" style="text-align: justify;">Bước 3) Đ&agrave;o tạo bộ ph&acirc;n loại</h4> <p style="text-align: justify;">TensorFlow hiện cung cấp một estimator cho hồi quy tuyến t&iacute;nh v&agrave; ph&acirc;n loại tuyến t&iacute;nh.</p> <ul style="text-align: justify;"> <li>Hồi quy tuyến t&iacute;nh: LinearRegressor</li> <li>Ph&acirc;n loại tuyến t&iacute;nh: LinearClassifier</li> </ul> <p style="text-align: justify;">C&uacute; ph&aacute;p của bộ ph&acirc;n loại tuyến t&iacute;nh giống như trong hướng dẫn về hồi quy tuyến t&iacute;nh ngoại trừ một đối số, n_class. Bạn cần x&aacute;c định cột đặc trưng, thư mục m&ocirc; h&igrave;nh v&agrave; so s&aacute;nh với c&ocirc;ng cụ hồi quy tuyến t&iacute;nh, bạn cũng cần x&aacute;c định số lượng lớp. Đối với hồi quy logit, số lớp bằng 2.</p> <p style="text-align: justify;">M&ocirc; h&igrave;nh sẽ t&iacute;nh to&aacute;n trọng số của c&aacute;c cột chứa trong li&ecirc;n tục v&agrave; ph&acirc;n loại.</p> <div id="urvanov-syntax-highlighter-610fea87ebf09120882281" 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-610fea87ebf09120882281-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf09120882281-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf09120882281-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf09120882281-4">4</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf09120882281-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">LinearClassifier</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf09120882281-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">n_classes</span> <span class="crayon-o">=</span> <span class="crayon-cn">2</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf09120882281-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">model_dir</span><span class="crayon-o">=</span><span class="crayon-s">"ongoing/train"</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf09120882281-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">feature_columns</span><span class="crayon-o">=</span><span class="crayon-v">categorical_features</span><span class="crayon-o">+</span> <span class="crayon-v">continuous_features</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fea87ebf0e611311328" 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-610fea87ebf0e611311328-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf0e611311328-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf0e611311328-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf0e611311328-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-610fea87ebf0e611311328-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">'ongoing/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></div> <div id="urvanov-syntax-highlighter-610fea87ebf0e611311328-3" class="crayon-line"><span class="crayon-o">&amp;</span><span class="crayon-v">lt</span><span class="crayon-sy">;</span><span class="crayon-v">tensorflow</span><span class="crayon-sy">.</span><span class="crayon-v">python</span><span class="crayon-sy">.</span><span class="crayon-v">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">0x181f24c898</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&acirc;y giờ bộ ph&acirc;n loại đ&atilde; được x&aacute;c định, bạn c&oacute; thể tạo h&agrave;m input. Phương ph&aacute;p n&agrave;y giống như trong hướng dẫn hồi quy tuyến t&iacute;nh. Ở đ&acirc;y, bạn sử dụng batch size l&agrave; 128 v&agrave; x&aacute;o trộn dữ liệu.</p> <div id="urvanov-syntax-highlighter-610fea87ebf10651544193" 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-610fea87ebf10651544193-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf10651544193-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf10651544193-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf10651544193-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf10651544193-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf10651544193-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf10651544193-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf10651544193-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf10651544193-9">9</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf10651544193-1" class="crayon-line"><span class="crayon-v">FEATURES</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-s">'age'</span><span class="crayon-sy">,</span><span class="crayon-s">'workclass'</span><span class="crayon-sy">,</span> <span class="crayon-s">'fnlwgt'</span><span class="crayon-sy">,</span> <span class="crayon-s">'education'</span><span class="crayon-sy">,</span> <span class="crayon-s">'education_num'</span><span class="crayon-sy">,</span> <span class="crayon-s">'marital'</span><span class="crayon-sy">,</span> <span class="crayon-s">'occupation'</span><span class="crayon-sy">,</span> <span class="crayon-s">'relationship'</span><span class="crayon-sy">,</span> <span class="crayon-s">'race'</span><span class="crayon-sy">,</span> <span class="crayon-s">'sex'</span><span class="crayon-sy">,</span> <span class="crayon-s">'capital_gain'</span><span class="crayon-sy">,</span> <span class="crayon-s">'capital_loss'</span><span class="crayon-sy">,</span> <span class="crayon-s">'hours_week'</span><span class="crayon-sy">,</span> <span class="crayon-s">'native_country'</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf10651544193-2" class="crayon-line crayon-striped-line"><span class="crayon-v">LABEL</span><span class="crayon-o">=</span> <span class="crayon-s">'label'</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf10651544193-3" class="crayon-line"><span class="crayon-e">def </span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">data_set</span><span class="crayon-sy">,</span> <span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">None</span><span class="crayon-sy">,</span> <span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span> <span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">True</span><span class="crayon-sy">)</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf10651544193-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">return</span> <span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">estimator</span><span class="crayon-sy">.</span><span class="crayon-v">inputs</span><span class="crayon-sy">.</span><span class="crayon-e">pandas_input_fn</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf10651544193-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">x</span><span class="crayon-o">=</span><span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">DataFrame</span><span class="crayon-sy">(</span><span class="crayon-sy">{</span><span class="crayon-v">k</span><span class="crayon-o">:</span> <span class="crayon-v">data_set</span><span class="crayon-sy">[</span><span class="crayon-v">k</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-e">values </span><span class="crayon-st">for</span> <span class="crayon-i">k</span> <span class="crayon-st">in</span> <span class="crayon-v">FEATURES</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf10651544193-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">y</span> <span class="crayon-o">=</span> <span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">Series</span><span class="crayon-sy">(</span><span class="crayon-v">data_set</span><span class="crayon-sy">[</span><span class="crayon-v">LABEL</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-v">values</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf10651544193-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">batch_size</span><span class="crayon-o">=</span><span class="crayon-v">n_batch</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fea87ebf10651544193-8" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">num_epochs</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf10651544193-9" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-v">shuffle</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Bạn tạo một h&agrave;m với c&aacute;c đối số được y&ecirc;u cầu bởi linear estimator, tức l&agrave; số epochs, số batch v&agrave; x&aacute;o trộn tập dữ liệu hoặc ghi ch&uacute;. V&igrave; ta sử dụng phương ph&aacute;p Pandas để chuyển dữ liệu v&agrave;o m&ocirc; h&igrave;nh, n&ecirc;n cần x&aacute;c định c&aacute;c biến X l&agrave;m khung dữ liệu pandas. Lưu &yacute; rằng cần lặp lại tất cả dữ liệu được lưu trữ trong FEATURES.</p> <p style="text-align: justify;">H&atilde;y huấn luyện m&ocirc; h&igrave;nh với object model.train. Sử dụng h&agrave;m được x&aacute;c định trước đ&oacute; để cung cấp cho m&ocirc; h&igrave;nh c&aacute;c gi&aacute; trị th&iacute;ch hợp. Lưu &yacute; rằng đặt batch size th&agrave;nh 128 v&agrave; số epoch th&agrave;nh none.M&ocirc; h&igrave;nh sẽ được đ&agrave;o tạo tr&ecirc;n một ngh&igrave;n bước.</p> <div id="urvanov-syntax-highlighter-610fea87ebf12181404962" 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-610fea87ebf12181404962-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf12181404962-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf12181404962-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf12181404962-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf12181404962-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf12181404962-1" class="crayon-line"><span class="crayon-v">model</span><span class="crayon-sy">.</span><span class="crayon-e">train</span><span class="crayon-sy">(</span><span class="crayon-v">input_fn</span><span class="crayon-o">=</span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">df_train</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf12181404962-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">None</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf12181404962-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf12181404962-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">False</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf12181404962-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">steps</span><span class="crayon-o">=</span><span class="crayon-cn">1000</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191" 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-610fea87ebf14986133191-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-20">20</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-21">21</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-22">22</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-23">23</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-24">24</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-25">25</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-26">26</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-27">27</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-28">28</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-29">29</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf14986133191-30">30</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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-610fea87ebf14986133191-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-610fea87ebf14986133191-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-610fea87ebf14986133191-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-610fea87ebf14986133191-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-610fea87ebf14986133191-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-610fea87ebf14986133191-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">ongoing</span><span class="crayon-o">/</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-610fea87ebf14986133191-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">88.722855</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-610fea87ebf14986133191-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">65.8282</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">52583.64</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.528</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">118.386</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">25203.816</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.837</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">110.542</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">54924.312</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.905</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">199.03</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">68509.31</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.502</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">167.488</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">9151.754</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.599</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">220.155</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">34576.06</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.453</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">199.016</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">36047.117</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.503</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">197.531</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">22608.148</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.505</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">208.479</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">22201.918</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.479</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">ongoing</span><span class="crayon-o">/</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-610fea87ebf14986133191-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">5444.363.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-29" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf14986133191-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">LinearClassifier </span><span class="crayon-i">at</span> <span class="crayon-cn">0x181f223630</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ưu &yacute; rằng loss đ&atilde; giảm sau đ&oacute; trong 100 bước cuối c&ugrave;ng, tức l&agrave; từ 901 đến 1000.</p> <p style="text-align: justify;">Gi&aacute; trị loss cuối c&ugrave;ng sau một ngh&igrave;n lần lặp l&agrave; 5444. Bạn c&oacute; thể thử nghiệm&nbsp; m&ocirc; h&igrave;nh của m&igrave;nh tr&ecirc;n bộ thử nghiệm v&agrave; xem hiệu suất. Để đ&aacute;nh gi&aacute; hiệu suất của m&ocirc; h&igrave;nh, bạn cần sử dụng đ&aacute;nh gi&aacute; đối tượng. Cấp nguồn cho m&ocirc; h&igrave;nh với bộ thử nghiệm v&agrave; đặt số epoch th&agrave;nh 1, tức l&agrave; dữ liệu sẽ chuyển đến m&ocirc; h&igrave;nh chỉ một lần.</p> <div id="urvanov-syntax-highlighter-610fea87ebf16699620932" 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-610fea87ebf16699620932-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf16699620932-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf16699620932-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf16699620932-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf16699620932-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf16699620932-1" class="crayon-line"><span class="crayon-v">model</span><span class="crayon-sy">.</span><span class="crayon-e">evaluate</span><span class="crayon-sy">(</span><span class="crayon-v">input_fn</span><span class="crayon-o">=</span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">df_test</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf16699620932-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf16699620932-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf16699620932-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">False</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf16699620932-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">steps</span><span class="crayon-o">=</span><span class="crayon-cn">1000</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742" 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-610fea87ebf1a983522742-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-20">20</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-21">21</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-22">22</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-23">23</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf1a983522742-24">24</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-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-610fea87ebf1a983522742-2" class="crayon-line crayon-striped-line"><span class="crayon-v">WARNING</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Trapezoidal </span><span class="crayon-e">rule </span><span class="crayon-st">is</span> <span class="crayon-e">known </span><span class="crayon-st">to</span> <span class="crayon-e">produce </span><span class="crayon-e">incorrect </span><span class="crayon-v">PR</span><span class="crayon-o">-</span><span class="crayon-v">AUCs</span><span class="crayon-sy">;</span> <span class="crayon-e">please </span><span class="crayon-st">switch</span> <span class="crayon-st">to</span> <span class="crayon-s">"careful_interpolation"</span> <span class="crayon-v">instead</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-3" class="crayon-line"><span class="crayon-v">WARNING</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Trapezoidal </span><span class="crayon-e">rule </span><span class="crayon-st">is</span> <span class="crayon-e">known </span><span class="crayon-st">to</span> <span class="crayon-e">produce </span><span class="crayon-e">incorrect </span><span class="crayon-v">PR</span><span class="crayon-o">-</span><span class="crayon-v">AUCs</span><span class="crayon-sy">;</span> <span class="crayon-e">please </span><span class="crayon-st">switch</span> <span class="crayon-st">to</span> <span class="crayon-s">"careful_interpolation"</span> <span class="crayon-v">instead</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-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">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-610fea87ebf1a983522742-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">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">06</span><span class="crayon-o">-</span><span class="crayon-cn">02</span><span class="crayon-o">-</span><span class="crayon-cn">08</span><span class="crayon-o">:</span><span class="crayon-cn">28</span><span class="crayon-o">:</span><span class="crayon-cn">22</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-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">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-610fea87ebf1a983522742-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">Restoring </span><span class="crayon-e">parameters </span><span class="crayon-e">from </span><span class="crayon-v">ongoing</span><span class="crayon-o">/</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-610fea87ebf1a983522742-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">Running </span><span class="crayon-v">local_init_op</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-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">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-610fea87ebf1a983522742-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-i">Evaluation</span> <span class="crayon-sy">[</span><span class="crayon-cn">100</span><span class="crayon-o">/</span><span class="crayon-cn">1000</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-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-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">06</span><span class="crayon-o">-</span><span class="crayon-cn">02</span><span class="crayon-o">-</span><span class="crayon-cn">08</span><span class="crayon-o">:</span><span class="crayon-cn">28</span><span class="crayon-o">:</span><span class="crayon-cn">23</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-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-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">accuracy</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.7615626</span><span class="crayon-sy">,</span> <span class="crayon-v">accuracy_baseline</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.76377374</span><span class="crayon-sy">,</span> <span class="crayon-v">auc</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.63300294</span><span class="crayon-sy">,</span> <span class="crayon-v">auc_precision_recall</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.50891197</span><span class="crayon-sy">,</span> <span class="crayon-v">average_loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">47.12155</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">label</span><span class="crayon-o">/</span><span class="crayon-v">mean</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.23622628</span><span class="crayon-sy">,</span> <span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">5993.6406</span><span class="crayon-sy">,</span> <span class="crayon-v">precision</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.49401596</span><span class="crayon-sy">,</span> <span class="crayon-v">prediction</span><span class="crayon-o">/</span><span class="crayon-v">mean</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.18454961</span><span class="crayon-sy">,</span> <span class="crayon-v">recall</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.38637546</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-13" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-14" class="crayon-line crayon-striped-line"><span class="crayon-sy">{</span><span class="crayon-s">'accuracy'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.7615626</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-15" class="crayon-line"><span class="crayon-s">'accuracy_baseline'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.76377374</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-16" class="crayon-line crayon-striped-line"><span class="crayon-s">'auc'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.63300294</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-17" class="crayon-line"><span class="crayon-s">'auc_precision_recall'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.50891197</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-18" class="crayon-line crayon-striped-line"><span class="crayon-s">'average_loss'</span><span class="crayon-o">:</span> <span class="crayon-cn">47.12155</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-19" class="crayon-line"><span class="crayon-s">'global_step'</span><span class="crayon-o">:</span> <span class="crayon-cn">1000</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-20" class="crayon-line crayon-striped-line"><span class="crayon-s">'label/mean'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.23622628</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-21" class="crayon-line"><span class="crayon-s">'loss'</span><span class="crayon-o">:</span> <span class="crayon-cn">5993.6406</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-22" class="crayon-line crayon-striped-line"><span class="crayon-s">'precision'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.49401596</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-23" class="crayon-line"><span class="crayon-s">'prediction/mean'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.18454961</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1a983522742-24" class="crayon-line crayon-striped-line"><span class="crayon-s">'recall'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.38637546</span><span class="crayon-sy">}</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">TensorFlow trả về tất cả c&aacute;c số liệu bạn đ&atilde; học trong phần l&yacute; thuyết. Kh&ocirc;ng c&oacute; bất ngờ, độ ch&iacute;nh x&aacute;c lớn do nh&atilde;n kh&ocirc;ng c&acirc;n bằng. Tr&ecirc;n thực tế, m&ocirc; h&igrave;nh hoạt động tốt hơn một ch&uacute;t so với phỏng đo&aacute;n ngẫu nhi&ecirc;n. H&atilde;y tưởng tượng m&ocirc; h&igrave;nh dự đo&aacute;n tất cả c&aacute;c hộ gia đ&igrave;nh c&oacute; thu nhập thấp hơn 50 ngh&igrave;n, khi đ&oacute; m&ocirc; h&igrave;nh c&oacute; độ ch&iacute;nh x&aacute;c l&agrave; 70%. Khi ph&acirc;n t&iacute;ch kỹ hơn, bạn c&oacute; thể thấy dự đo&aacute;n v&agrave; recall l&agrave; kh&aacute; thấp.</p> <h4 id="ftoc-heading-13" class="ftwp-heading" style="text-align: justify;">Bước 4) Cải thiện m&ocirc; h&igrave;nh</h4> <p style="text-align: justify;">B&acirc;y giờ bạn đ&atilde; c&oacute; một benchmark model, bạn c&oacute; thể cố gắng cải thiện n&oacute;, tức l&agrave; tăng độ ch&iacute;nh x&aacute;c.</p> <p style="text-align: justify;">Polynomial regression l&agrave; c&ocirc;ng cụ khi c&oacute; sự kh&ocirc;ng tuyến t&iacute;nh trong dữ liệu. C&oacute; hai c&aacute;ch để nắm bắt t&iacute;nh kh&ocirc;ng tuyến t&iacute;nh trong dữ liệu.</p> <ul style="text-align: justify;"> <li>Th&ecirc;m số hạng đa thức</li> <li>Bucketize h&oacute;a biến li&ecirc;n tục th&agrave;nh một biến ph&acirc;n loại</li> </ul> <h5 id="ftoc-heading-14" class="ftwp-heading" style="text-align: justify;"><strong>Polynomial term</strong></h5> <p style="text-align: justify;">Từ h&igrave;nh b&ecirc;n dưới, bạn c&oacute; thể thấy &nbsp;polynomial regression l&agrave; g&igrave;. N&oacute; l&agrave; một phương tr&igrave;nh với X biến với sức mạnh kh&aacute;c nhau. Hồi quy đa thức bậc hai c&oacute; hai biến, X v&agrave; X b&igrave;nh phương. Mức độ thứ ba c&oacute; ba biến X, X<sup>2</sup>&nbsp; v&agrave; X<sup>3</sup></p> <p style="text-align: justify;"><img class="aligncenter wp-image-8349 size-full disappear appear" src="../../wp-content/uploads/2021/02/082918_1030_LinearClass4-e1612962962343.png" sizes="(max-width: 548px) 100vw, 548px" srcset="https://old.tek4.vn/wp-content/uploads/2021/02/082918_1030_LinearClass4-e1612962962343.png 548w, https://old.tek4.vn/wp-content/uploads/2021/02/082918_1030_LinearClass4-e1612962962343-300x115.png 300w" alt="" width="548" height="210" loading="lazy" /></p> <p style="text-align: justify;">Dưới đ&acirc;y, ch&uacute;ng ta x&acirc;y dựng một đồ thị với hai biến, X v&agrave; Y. R&otilde; r&agrave;ng l&agrave; mối quan hệ kh&ocirc;ng tuyến t&iacute;nh. Nếu ch&uacute;ng ta th&ecirc;m một hồi quy tuyến t&iacute;nh, ch&uacute;ng ta c&oacute; thể thấy m&ocirc; h&igrave;nh kh&ocirc;ng thể nắm bắt được m&ocirc; h&igrave;nh (h&igrave;nh b&ecirc;n tr&aacute;i).</p> <p style="text-align: justify;">B&acirc;y giờ, h&atilde;y nh&igrave;n v&agrave;o h&igrave;nh b&ecirc;n tr&aacute;i từ h&igrave;nh dưới đ&acirc;y, ch&uacute;ng ta đ&atilde; th&ecirc;m năm số hạng v&agrave;o hồi quy (đ&oacute; l&agrave; y=x+x<sup>2</sup>+x<sup>3</sup>+x<sup>4</sup>+x<sup>5&nbsp;</sup>). M&ocirc; h&igrave;nh b&acirc;y giờ nắm bắt m&ocirc; h&igrave;nh tốt hơn.</p> <p style="text-align: justify;"><img class="aligncenter size-full wp-image-8350 disappear appear" src="../../wp-content/uploads/2021/02/082918_1030_LinearClass5.png" sizes="(max-width: 627px) 100vw, 627px" srcset="https://old.tek4.vn/wp-content/uploads/2021/02/082918_1030_LinearClass5.png 627w, https://old.tek4.vn/wp-content/uploads/2021/02/082918_1030_LinearClass5-300x123.png 300w" alt="" width="627" height="257" loading="lazy" /></p> <p style="text-align: justify;">H&atilde;y quay lại v&iacute; dụ của ch&uacute;ng ta. Age kh&ocirc;ng nằm trong mối quan hệ tuyến t&iacute;nh với relationship. Early age c&oacute; thể gần bằng 0 v&igrave; trẻ em hoặc thanh ni&ecirc;n kh&ocirc;ng đi l&agrave;m. Sau đ&oacute;, n&oacute; tăng l&ecirc;n trong độ tuổi lao động (working age) v&agrave; giảm khi nghỉ hưu (retirement). N&oacute; thường l&agrave; h&igrave;nh chữ U đảo ngược. Một c&aacute;ch để nắm bắt m&ocirc; h&igrave;nh n&agrave;y l&agrave; th&ecirc;m lũy thừa hai v&agrave;o hồi quy.</p> <p style="text-align: justify;">H&atilde;y xem n&oacute; c&oacute; l&agrave;m tăng độ ch&iacute;nh x&aacute;c kh&ocirc;ng.</p> <p style="text-align: justify;">Bạn cần th&ecirc;m đặc trưng mới n&agrave;y v&agrave;o tập dữ liệu v&agrave; trong danh s&aacute;ch đặc trưng li&ecirc;n tục.</p> <p style="text-align: justify;">Bạn th&ecirc;m biến mới trong tập dữ liệu huấn luyện v&agrave; kiểm tra, v&igrave; vậy việc viết một h&agrave;m sẽ thuận tiện hơn.</p> <div id="urvanov-syntax-highlighter-610fea87ebf1e512705316" 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-610fea87ebf1e512705316-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf1e512705316-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf1e512705316-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf1e512705316-4">4</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf1e512705316-1" class="crayon-line"><span class="crayon-e">def </span><span class="crayon-e">square_var</span><span class="crayon-sy">(</span><span class="crayon-v">df_t</span><span class="crayon-sy">,</span> <span class="crayon-v">df_te</span><span class="crayon-sy">,</span> <span class="crayon-v">var_name</span> <span class="crayon-o">=</span> <span class="crayon-s">'age'</span><span class="crayon-sy">)</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1e512705316-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">df_t</span><span class="crayon-sy">[</span><span class="crayon-s">'new'</span><span class="crayon-sy">]</span> <span class="crayon-o">=</span> <span class="crayon-v">df_t</span><span class="crayon-sy">[</span><span class="crayon-v">var_name</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-e">pow</span><span class="crayon-sy">(</span><span class="crayon-cn">2</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1e512705316-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">df_te</span><span class="crayon-sy">[</span><span class="crayon-s">'new'</span><span class="crayon-sy">]</span> <span class="crayon-o">=</span> <span class="crayon-v">df_te</span><span class="crayon-sy">[</span><span class="crayon-v">var_name</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-e">pow</span><span class="crayon-sy">(</span><span class="crayon-cn">2</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf1e512705316-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">return</span> <span class="crayon-v">df_t</span><span class="crayon-sy">,</span> <span class="crayon-v">df_te</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">H&agrave;m c&oacute; 3 đối số:</p> <ul style="text-align: justify;"> <li>df_t: x&aacute;c định tập huấn luyện</li> <li>df_te:&nbsp; x&aacute;c định tập kiểm tra</li> <li>var_name = &lsquo;age&rsquo;: X&aacute;c định biến để chuyển đổi</li> </ul> <p style="text-align: justify;">Bạn c&oacute; thể sử dụng đối tượng pow(2) để b&igrave;nh phương biến age. Lưu &yacute; rằng biến mới được đặt t&ecirc;n l&agrave; &lsquo;new&rsquo;.</p> <p style="text-align: justify;">B&acirc;y giờ h&agrave;m square_var đ&atilde; được viết, bạn c&oacute; thể tạo tập dữ liệu mới.</p> <div id="urvanov-syntax-highlighter-610fea87ebf22159295681" 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-610fea87ebf22159295681-1">1</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf22159295681-1" class="crayon-line"><span class="crayon-v">df_train_new</span><span class="crayon-sy">,</span> <span class="crayon-v">df_test_new</span> <span class="crayon-o">=</span> <span class="crayon-e">square_var</span><span class="crayon-sy">(</span><span class="crayon-v">df_train</span><span class="crayon-sy">,</span> <span class="crayon-v">df_test</span><span class="crayon-sy">,</span> <span class="crayon-v">var_name</span> <span class="crayon-o">=</span> <span class="crayon-s">'age'</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Như bạn c&oacute; thể thấy, tập dữ liệu mới c&oacute; th&ecirc;m một đặc trưng.</p> <div id="urvanov-syntax-highlighter-610fea87ebf24924507272" 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-610fea87ebf24924507272-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf24924507272-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf24924507272-1" class="crayon-line"><span class="crayon-e">print</span><span class="crayon-sy">(</span><span class="crayon-v">df_train_new</span><span class="crayon-sy">.</span><span class="crayon-v">shape</span><span class="crayon-sy">,</span> <span class="crayon-v">df_test_new</span><span class="crayon-sy">.</span><span class="crayon-v">shape</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf24924507272-2" class="crayon-line crayon-striped-line"><span class="crayon-sy">(</span><span class="crayon-cn">32561</span><span class="crayon-sy">,</span> <span class="crayon-cn">16</span><span class="crayon-sy">)</span> <span class="crayon-sy">(</span><span class="crayon-cn">16281</span><span class="crayon-sy">,</span> <span class="crayon-cn">16</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Biến b&igrave;nh phương được gọi l&agrave; new trong tập dữ liệu. Bạn cần th&ecirc;m n&oacute; v&agrave;o danh s&aacute;ch c&aacute;c đặc trưng li&ecirc;n tục.</p> <div id="urvanov-syntax-highlighter-610fea87ebf25130541625" 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-610fea87ebf25130541625-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf25130541625-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf25130541625-1" class="crayon-line"><span class="crayon-v">CONTI_FEATURES_NEW</span><span class="crayon-h">&nbsp;&nbsp;</span><span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-s">'age'</span><span class="crayon-sy">,</span> <span class="crayon-s">'fnlwgt'</span><span class="crayon-sy">,</span><span class="crayon-s">'capital_gain'</span><span class="crayon-sy">,</span> <span class="crayon-s">'education_num'</span><span class="crayon-sy">,</span> <span class="crayon-s">'capital_loss'</span><span class="crayon-sy">,</span> <span class="crayon-s">'hours_week'</span><span class="crayon-sy">,</span> <span class="crayon-s">'new'</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf25130541625-2" class="crayon-line crayon-striped-line"><span class="crayon-v">continuous_features_new</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">feature_column</span><span class="crayon-sy">.</span><span class="crayon-e">numeric_column</span><span class="crayon-sy">(</span><span class="crayon-v">k</span><span class="crayon-sy">)</span> <span class="crayon-st">for</span> <span class="crayon-i">k</span> <span class="crayon-st">in</span> <span class="crayon-v">CONTI_FEATURES_NEW</span><span class="crayon-sy">]</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Lưu &yacute; rằng bạn đ&atilde; thay đổi thư mục của Graph. Bạn kh&ocirc;ng thể đ&agrave;o tạo c&aacute;c m&ocirc; h&igrave;nh kh&aacute;c nhau trong c&ugrave;ng một thư mục. C&oacute; nghĩa l&agrave;, bạn cần thay đổi đường dẫn của đối số model_dir. Nếu kh&ocirc;ng, tensorflow sẽ b&aacute;o lỗi.</p> <div id="urvanov-syntax-highlighter-610fea87ebf27709668676" 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-610fea87ebf27709668676-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf27709668676-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf27709668676-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf27709668676-1" class="crayon-line"><span class="crayon-v">model_1</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">LinearClassifier</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf27709668676-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">model_dir</span><span class="crayon-o">=</span><span class="crayon-s">"ongoing/train1"</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf27709668676-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">feature_columns</span><span class="crayon-o">=</span><span class="crayon-v">categorical_features</span><span class="crayon-o">+</span> <span class="crayon-v">continuous_features_new</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610fea87ebf29528352431" 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-610fea87ebf29528352431-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf29528352431-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf29528352431-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf29528352431-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf29528352431-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf29528352431-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf29528352431-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf29528352431-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf29528352431-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf29528352431-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf29528352431-11">11</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf29528352431-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-610fea87ebf29528352431-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">'ongoing/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></div> <div id="urvanov-syntax-highlighter-610fea87ebf29528352431-3" class="crayon-line"><span class="crayon-o">&amp;</span><span class="crayon-v">lt</span><span class="crayon-sy">;</span><span class="crayon-v">tensorflow</span><span class="crayon-sy">.</span><span class="crayon-v">python</span><span class="crayon-sy">.</span><span class="crayon-v">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">0x1820f04b70</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 id="urvanov-syntax-highlighter-610fea87ebf29528352431-4" class="crayon-line crayon-striped-line"><span class="crayon-v">FEATURES_NEW</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-s">'age'</span><span class="crayon-sy">,</span><span class="crayon-s">'workclass'</span><span class="crayon-sy">,</span> <span class="crayon-s">'fnlwgt'</span><span class="crayon-sy">,</span> <span class="crayon-s">'education'</span><span class="crayon-sy">,</span> <span class="crayon-s">'education_num'</span><span class="crayon-sy">,</span> <span class="crayon-s">'marital'</span><span class="crayon-sy">,</span> <span class="crayon-s">'occupation'</span><span class="crayon-sy">,</span> <span class="crayon-s">'relationship'</span><span class="crayon-sy">,</span> <span class="crayon-s">'race'</span><span class="crayon-sy">,</span> <span class="crayon-s">'sex'</span><span class="crayon-sy">,</span> <span class="crayon-s">'capital_gain'</span><span class="crayon-sy">,</span> <span class="crayon-s">'capital_loss'</span><span class="crayon-sy">,</span> <span class="crayon-s">'hours_week'</span><span class="crayon-sy">,</span> <span class="crayon-s">'native_country'</span><span class="crayon-sy">,</span> <span class="crayon-s">'new'</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf29528352431-5" class="crayon-line"><span class="crayon-e">def </span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">data_set</span><span class="crayon-sy">,</span> <span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">None</span><span class="crayon-sy">,</span> <span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span> <span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">True</span><span class="crayon-sy">)</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf29528352431-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">return</span> <span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">estimator</span><span class="crayon-sy">.</span><span class="crayon-v">inputs</span><span class="crayon-sy">.</span><span class="crayon-e">pandas_input_fn</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf29528352431-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">x</span><span class="crayon-o">=</span><span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">DataFrame</span><span class="crayon-sy">(</span><span class="crayon-sy">{</span><span class="crayon-v">k</span><span class="crayon-o">:</span> <span class="crayon-v">data_set</span><span class="crayon-sy">[</span><span class="crayon-v">k</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-e">values </span><span class="crayon-st">for</span> <span class="crayon-i">k</span> <span class="crayon-st">in</span> <span class="crayon-v">FEATURES_NEW</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf29528352431-8" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">y</span> <span class="crayon-o">=</span> <span class="crayon-v">pd</span><span class="crayon-sy">.</span><span class="crayon-e">Series</span><span class="crayon-sy">(</span><span class="crayon-v">data_set</span><span class="crayon-sy">[</span><span class="crayon-v">LABEL</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-v">values</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf29528352431-9" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">batch_size</span><span class="crayon-o">=</span><span class="crayon-v">n_batch</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fea87ebf29528352431-10" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">num_epochs</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf29528352431-11" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-v">shuffle</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">B&acirc;y giờ bộ ph&acirc;n loại được thiết kế với tập dữ liệu mới, bạn c&oacute; thể đ&agrave;o tạo v&agrave; đ&aacute;nh gi&aacute; m&ocirc; h&igrave;nh.</p> <div id="urvanov-syntax-highlighter-610fea87ebf2b339912854" 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-610fea87ebf2b339912854-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2b339912854-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2b339912854-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2b339912854-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2b339912854-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf2b339912854-1" class="crayon-line"><span class="crayon-v">model_1</span><span class="crayon-sy">.</span><span class="crayon-e">train</span><span class="crayon-sy">(</span><span class="crayon-v">input_fn</span><span class="crayon-o">=</span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">df_train</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2b339912854-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">None</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2b339912854-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2b339912854-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">False</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2b339912854-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">steps</span><span class="crayon-o">=</span><span class="crayon-cn">1000</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673" 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-610fea87ebf2f877738673-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-20">20</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-21">21</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-22">22</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-23">23</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-24">24</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-25">25</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-26">26</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-27">27</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-28">28</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-29">29</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf2f877738673-30">30</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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-610fea87ebf2f877738673-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-610fea87ebf2f877738673-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-610fea87ebf2f877738673-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-610fea87ebf2f877738673-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-610fea87ebf2f877738673-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-610fea87ebf2f877738673-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">ongoing</span><span class="crayon-o">/</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-610fea87ebf2f877738673-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">88.722855</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-610fea87ebf2f877738673-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">81.487</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">70077.66</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.228</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">111.169</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">49522.082</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.899</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">128.91</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">107120.57</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.776</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">132.546</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">12814.152</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.755</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">162.194</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">19573.898</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.617</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">204.852</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">26381.986</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.488</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">188.923</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">23417.719</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.529</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">192.041</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">23946.049</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.521</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">197.025</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">3309.5786</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.507</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">ongoing</span><span class="crayon-o">/</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-610fea87ebf2f877738673-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">28861.898.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-29" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf2f877738673-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">LinearClassifier </span><span class="crayon-i">at</span> <span class="crayon-cn">0x1820f04c88</span><span class="crayon-o">&amp;</span><span class="crayon-v">gt</span><span class="crayon-sy">;</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610fea87ebf31304770601" 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-610fea87ebf31304770601-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf31304770601-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf31304770601-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf31304770601-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf31304770601-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf31304770601-1" class="crayon-line"><span class="crayon-v">model_1</span><span class="crayon-sy">.</span><span class="crayon-e">evaluate</span><span class="crayon-sy">(</span><span class="crayon-v">input_fn</span><span class="crayon-o">=</span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">df_test_new</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf31304770601-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf31304770601-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf31304770601-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">False</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf31304770601-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">steps</span><span class="crayon-o">=</span><span class="crayon-cn">1000</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515" 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-610fea87ebf33755496515-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-20">20</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-21">21</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-22">22</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-23">23</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf33755496515-24">24</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-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-610fea87ebf33755496515-2" class="crayon-line crayon-striped-line"><span class="crayon-v">WARNING</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Trapezoidal </span><span class="crayon-e">rule </span><span class="crayon-st">is</span> <span class="crayon-e">known </span><span class="crayon-st">to</span> <span class="crayon-e">produce </span><span class="crayon-e">incorrect </span><span class="crayon-v">PR</span><span class="crayon-o">-</span><span class="crayon-v">AUCs</span><span class="crayon-sy">;</span> <span class="crayon-e">please </span><span class="crayon-st">switch</span> <span class="crayon-st">to</span> <span class="crayon-s">"careful_interpolation"</span> <span class="crayon-v">instead</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-3" class="crayon-line"><span class="crayon-v">WARNING</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Trapezoidal </span><span class="crayon-e">rule </span><span class="crayon-st">is</span> <span class="crayon-e">known </span><span class="crayon-st">to</span> <span class="crayon-e">produce </span><span class="crayon-e">incorrect </span><span class="crayon-v">PR</span><span class="crayon-o">-</span><span class="crayon-v">AUCs</span><span class="crayon-sy">;</span> <span class="crayon-e">please </span><span class="crayon-st">switch</span> <span class="crayon-st">to</span> <span class="crayon-s">"careful_interpolation"</span> <span class="crayon-v">instead</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-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">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-610fea87ebf33755496515-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">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">06</span><span class="crayon-o">-</span><span class="crayon-cn">02</span><span class="crayon-o">-</span><span class="crayon-cn">08</span><span class="crayon-o">:</span><span class="crayon-cn">28</span><span class="crayon-o">:</span><span class="crayon-cn">37</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-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">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-610fea87ebf33755496515-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">Restoring </span><span class="crayon-e">parameters </span><span class="crayon-e">from </span><span class="crayon-v">ongoing</span><span class="crayon-o">/</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-610fea87ebf33755496515-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">Running </span><span class="crayon-v">local_init_op</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-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">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-610fea87ebf33755496515-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-i">Evaluation</span> <span class="crayon-sy">[</span><span class="crayon-cn">100</span><span class="crayon-o">/</span><span class="crayon-cn">1000</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-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-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">06</span><span class="crayon-o">-</span><span class="crayon-cn">02</span><span class="crayon-o">-</span><span class="crayon-cn">08</span><span class="crayon-o">:</span><span class="crayon-cn">28</span><span class="crayon-o">:</span><span class="crayon-cn">39</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-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-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">accuracy</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.7944229</span><span class="crayon-sy">,</span> <span class="crayon-v">accuracy_baseline</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.76377374</span><span class="crayon-sy">,</span> <span class="crayon-v">auc</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.6093755</span><span class="crayon-sy">,</span> <span class="crayon-v">auc_precision_recall</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.54885805</span><span class="crayon-sy">,</span> <span class="crayon-v">average_loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">111.0046</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">label</span><span class="crayon-o">/</span><span class="crayon-v">mean</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.23622628</span><span class="crayon-sy">,</span> <span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">14119.265</span><span class="crayon-sy">,</span> <span class="crayon-v">precision</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.6682401</span><span class="crayon-sy">,</span> <span class="crayon-v">prediction</span><span class="crayon-o">/</span><span class="crayon-v">mean</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.09116262</span><span class="crayon-sy">,</span> <span class="crayon-v">recall</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.2576703</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-13" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-14" class="crayon-line crayon-striped-line"><span class="crayon-sy">{</span><span class="crayon-s">'accuracy'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.7944229</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-15" class="crayon-line"><span class="crayon-s">'accuracy_baseline'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.76377374</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-16" class="crayon-line crayon-striped-line"><span class="crayon-s">'auc'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.6093755</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-17" class="crayon-line"><span class="crayon-s">'auc_precision_recall'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.54885805</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-18" class="crayon-line crayon-striped-line"><span class="crayon-s">'average_loss'</span><span class="crayon-o">:</span> <span class="crayon-cn">111.0046</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-19" class="crayon-line"><span class="crayon-s">'global_step'</span><span class="crayon-o">:</span> <span class="crayon-cn">1000</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-20" class="crayon-line crayon-striped-line"><span class="crayon-s">'label/mean'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.23622628</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-21" class="crayon-line"><span class="crayon-s">'loss'</span><span class="crayon-o">:</span> <span class="crayon-cn">14119.265</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-22" class="crayon-line crayon-striped-line"><span class="crayon-s">'precision'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.6682401</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-23" class="crayon-line"><span class="crayon-s">'prediction/mean'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.09116262</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf33755496515-24" class="crayon-line crayon-striped-line"><span class="crayon-s">'recall'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.2576703</span><span class="crayon-sy">}</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Biến b&igrave;nh phương cải thiện độ ch&iacute;nh x&aacute;c từ 0,76 l&ecirc;n 0,79. H&atilde;y xem liệu bạn c&oacute; thể l&agrave;m tốt hơn bằng c&aacute;ch kết hợp thuật ngữ bucketization v&agrave; interaction với nhau hay kh&ocirc;ng.</p> <h5 id="ftoc-heading-15" class="ftwp-heading" style="text-align: justify;">Bucketization v&agrave; interaction</h5> <p style="text-align: justify;">Như bạn đ&atilde; thấy trước đ&acirc;y, bộ ph&acirc;n loại tuyến t&iacute;nh kh&ocirc;ng thể nắm bắt ch&iacute;nh x&aacute;c mẫu thu nhập theo độ tuổi. Đ&oacute; l&agrave; bởi v&igrave; n&oacute; học một trọng số duy nhất cho mỗi đặc trưng. Để gi&uacute;p bộ ph&acirc;n loại dễ d&agrave;ng hơn, một điều bạn c&oacute; thể l&agrave;m l&agrave; bucket đặc trưng n&agrave;y. Bucketing chuyển đổi một đặc trưng số th&agrave;nh một số đặc trưng nhất định dựa tr&ecirc;n phạm vi m&agrave; đặc trưng rơi v&agrave;o v&agrave; mỗi đặc trưng mới n&agrave;y cho biết liệu tuổi của một người c&oacute; nằm trong phạm vi đ&oacute; hay kh&ocirc;ng.</p> <p style="text-align: justify;">Với c&aacute;c đặc trưng mới n&agrave;y, m&ocirc; h&igrave;nh tuyến t&iacute;nh c&oacute; thể nắm bắt mối quan hệ bằng c&aacute;ch học c&aacute;c trọng số kh&aacute;c nhau cho mỗi bucket.</p> <p style="text-align: justify;">Trong TensorFlow, n&oacute; được thực hiện với bucketized_column.</p> <div id="urvanov-syntax-highlighter-610fea87ebf35131560323" 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-610fea87ebf35131560323-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf35131560323-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf35131560323-3">3</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf35131560323-1" class="crayon-line"><span class="crayon-v">age</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-610fea87ebf35131560323-2" class="crayon-line crayon-striped-line"><span class="crayon-v">age_buckets</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">bucketized_column</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf35131560323-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">age</span><span class="crayon-sy">,</span> <span class="crayon-v">boundaries</span><span class="crayon-o">=</span><span class="crayon-sy">[</span><span class="crayon-cn">18</span><span class="crayon-sy">,</span> <span class="crayon-cn">25</span><span class="crayon-sy">,</span> <span class="crayon-cn">30</span><span class="crayon-sy">,</span> <span class="crayon-cn">35</span><span class="crayon-sy">,</span> <span class="crayon-cn">40</span><span class="crayon-sy">,</span> <span class="crayon-cn">45</span><span class="crayon-sy">,</span> <span class="crayon-cn">50</span><span class="crayon-sy">,</span> <span class="crayon-cn">55</span><span class="crayon-sy">,</span> <span class="crayon-cn">60</span><span class="crayon-sy">,</span> <span class="crayon-cn">65</span><span class="crayon-sy">]</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Bạn đ&atilde; biết tuổi t&aacute;c l&agrave; kh&ocirc;ng tuyến t&iacute;nh với thu nhập. Một c&aacute;ch kh&aacute;c để cải thiện m&ocirc; h&igrave;nh l&agrave; th&ocirc;ng qua interaction. Theo c&aacute;ch n&oacute;i của TensorFlow, đ&oacute; l&agrave; sự giao nhau giữa c&aacute;c đặc trưng. Feature crossing l&agrave; một c&aacute;ch để tạo c&aacute;c đặc trưng mới l&agrave; sự kết hợp của c&aacute;c đặc trưng hiện c&oacute;, điều n&agrave;y c&oacute; thể hữu &iacute;ch cho bộ ph&acirc;n loại tuyến t&iacute;nh kh&ocirc;ng thể lập m&ocirc; h&igrave;nh tương t&aacute;c giữa c&aacute;c đặc trưng.</p> <p style="text-align: justify;">Bạn c&oacute; thể chia nhỏ age bằng một đặc trưng kh&aacute;c như education.</p> <div id="urvanov-syntax-highlighter-610fea87ebf39560175037" 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-610fea87ebf39560175037-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf39560175037-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf39560175037-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf39560175037-4">4</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf39560175037-1" class="crayon-line"><span class="crayon-v">education_x_occupation</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">crossed_column</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf39560175037-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-sy">[</span><span class="crayon-s">'education'</span><span class="crayon-sy">,</span> <span class="crayon-s">'occupation'</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-v">hash_bucket_size</span><span class="crayon-o">=</span><span class="crayon-cn">1000</span><span class="crayon-sy">)</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf39560175037-3" class="crayon-line"><span class="crayon-v">age_buckets_x_education_x_occupation</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">crossed_column</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf39560175037-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-sy">[</span><span class="crayon-v">age_buckets</span><span class="crayon-sy">,</span> <span class="crayon-s">'education'</span><span class="crayon-sy">,</span> <span class="crayon-s">'occupation'</span><span class="crayon-sy">]</span><span class="crayon-sy">,</span> <span class="crayon-v">hash_bucket_size</span><span class="crayon-o">=</span><span class="crayon-cn">1000</span><span class="crayon-sy">)</span><span class="crayon-sy">]</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Để tạo cột cross feature, bạn sử dụng crossed_column với c&aacute;c biến để cross trong bracket. Hash_bucket_size cho biết khả năng crossing tối đa.&nbsp;Để tạo interaction giữa c&aacute;c biến (&iacute;t nhất một biến cần được ph&acirc;n loại), bạn c&oacute; thể sử dụng tf.feature_column.crossed_column. Để sử dụng đối tượng n&agrave;y, bạn cần th&ecirc;m v&agrave;o square bracket biến tương t&aacute;c v&agrave; đối số thứ hai, bucket size. Bucket size l&agrave; số lượng nh&oacute;m tối đa c&oacute; thể c&oacute; trong một biến. Ở đ&acirc;y bạn đặt n&oacute; ở 1000 v&igrave; bạn kh&ocirc;ng biết số lượng ch&iacute;nh x&aacute;c của nh&oacute;m.</p> <p style="text-align: justify;">Age_buckets cần được b&igrave;nh phương trước để th&ecirc;m n&oacute; v&agrave;o c&aacute;c cột đặc trưng. Bạn cũng th&ecirc;m c&aacute;c đặc trưng mới v&agrave;o c&aacute;c cột đặc trưng v&agrave; chuẩn bị estimator.</p> <div id="urvanov-syntax-highlighter-610fea87ebf3c426490421" 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-610fea87ebf3c426490421-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf3c426490421-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf3c426490421-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf3c426490421-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf3c426490421-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf3c426490421-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf3c426490421-7">7</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf3c426490421-1" class="crayon-line"><span class="crayon-v">base_columns</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf3c426490421-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">age_buckets</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf3c426490421-3" class="crayon-line"><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf3c426490421-4" class="crayon-line crayon-striped-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf3c426490421-5" class="crayon-line"><span class="crayon-v">model_imp</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">LinearClassifier</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf3c426490421-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">model_dir</span><span class="crayon-o">=</span><span class="crayon-s">"ongoing/train3"</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf3c426490421-7" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">feature_columns</span><span class="crayon-o">=</span><span class="crayon-v">categorical_features</span><span class="crayon-o">+</span><span class="crayon-v">base_columns</span><span class="crayon-o">+</span><span class="crayon-v">education_x_occupation</span><span class="crayon-o">+</span><span class="crayon-v">age_buckets_x_education_x_occupation</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-610fea87ebf3d017804656" 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-610fea87ebf3d017804656-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf3d017804656-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf3d017804656-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-610fea87ebf3d017804656-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">'ongoing/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">0x1823021be0</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> <div id="urvanov-syntax-highlighter-610fea87ebf43333364125" 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-610fea87ebf43333364125-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf43333364125-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf43333364125-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf43333364125-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf43333364125-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf43333364125-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf43333364125-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf43333364125-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf43333364125-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf43333364125-10">10</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf43333364125-1" class="crayon-line"><span class="crayon-v">FEATURES_imp</span> <span class="crayon-o">=</span> <span class="crayon-sy">[</span><span class="crayon-s">'age'</span><span class="crayon-sy">,</span><span class="crayon-s">'workclass'</span><span class="crayon-sy">,</span> <span class="crayon-s">'education'</span><span class="crayon-sy">,</span> <span class="crayon-s">'education_num'</span><span class="crayon-sy">,</span> <span class="crayon-s">'marital'</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf43333364125-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">'occupation'</span><span class="crayon-sy">,</span> <span class="crayon-s">'relationship'</span><span class="crayon-sy">,</span> <span class="crayon-s">'race'</span><span class="crayon-sy">,</span> <span class="crayon-s">'sex'</span><span class="crayon-sy">,</span> <span class="crayon-s">'native_country'</span><span class="crayon-sy">,</span> <span class="crayon-s">'new'</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf43333364125-3" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf43333364125-4" class="crayon-line crayon-striped-line"><span class="crayon-e">def </span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">data_set</span><span class="crayon-sy">,</span> <span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">None</span><span class="crayon-sy">,</span> <span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span> <span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">True</span><span class="crayon-sy">)</span><span class="crayon-o">:</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf43333364125-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-st">return</span> <span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">estimator</span><span class="crayon-sy">.</span><span class="crayon-v">inputs</span><span class="crayon-sy">.</span><span class="crayon-e">pandas_input_fn</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf43333364125-6" 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-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_imp</span><span class="crayon-sy">}</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf43333364125-7" 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">pd</span><span class="crayon-sy">.</span><span class="crayon-e">Series</span><span class="crayon-sy">(</span><span class="crayon-v">data_set</span><span class="crayon-sy">[</span><span class="crayon-v">LABEL</span><span class="crayon-sy">]</span><span class="crayon-sy">.</span><span class="crayon-v">values</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf43333364125-8" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">batch_size</span><span class="crayon-o">=</span><span class="crayon-v">n_batch</span><span class="crayon-sy">,</span><span class="crayon-h">&nbsp;&nbsp; </span></div> <div id="urvanov-syntax-highlighter-610fea87ebf43333364125-9" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">num_epochs</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf43333364125-10" 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-v">shuffle</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Bạn đ&atilde; sẵn s&agrave;ng ước t&iacute;nh m&ocirc; h&igrave;nh mới v&agrave; xem n&oacute; c&oacute; cải thiện độ ch&iacute;nh x&aacute;c hay kh&ocirc;ng.</p> <div id="urvanov-syntax-highlighter-610fea87ebf44007816320" 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-610fea87ebf44007816320-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf44007816320-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf44007816320-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf44007816320-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf44007816320-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf44007816320-1" class="crayon-line"><span class="crayon-v">model_imp</span><span class="crayon-sy">.</span><span class="crayon-e">train</span><span class="crayon-sy">(</span><span class="crayon-v">input_fn</span><span class="crayon-o">=</span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">df_train_new</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf44007816320-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">None</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf44007816320-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf44007816320-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">False</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf44007816320-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">steps</span><span class="crayon-o">=</span><span class="crayon-cn">1000</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933" 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-610fea87ebf46089381933-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-20">20</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-21">21</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-22">22</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-23">23</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-24">24</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-25">25</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-26">26</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-27">27</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-28">28</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-29">29</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf46089381933-30">30</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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-610fea87ebf46089381933-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-610fea87ebf46089381933-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-610fea87ebf46089381933-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-610fea87ebf46089381933-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-610fea87ebf46089381933-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-610fea87ebf46089381933-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">ongoing</span><span class="crayon-o">/</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-610fea87ebf46089381933-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">88.722855</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-610fea87ebf46089381933-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">94.969</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">50.334488</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.054</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">242.342</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">56.153225</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.414</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">213.686</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">45.792007</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.470</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">174.084</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">37.485672</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.572</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">191.78</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">56.48449</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.524</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">163.436</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">32.528934</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.612</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">164.347</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">37.438057</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.607</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">154.274</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">61.1075</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.647</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">189.14</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">44.69645</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.531</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">ongoing</span><span class="crayon-o">/</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-610fea87ebf46089381933-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">44.18133.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-29" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf46089381933-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">LinearClassifier </span><span class="crayon-i">at</span> <span class="crayon-cn">0x1823021cf8</span><span class="crayon-o">&amp;</span><span class="crayon-v">gt</span><span class="crayon-sy">;</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610fea87ebf48358892432" 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-610fea87ebf48358892432-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf48358892432-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf48358892432-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf48358892432-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf48358892432-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf48358892432-1" class="crayon-line"><span class="crayon-v">model_imp</span><span class="crayon-sy">.</span><span class="crayon-e">evaluate</span><span class="crayon-sy">(</span><span class="crayon-v">input_fn</span><span class="crayon-o">=</span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">df_test_new</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf48358892432-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf48358892432-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf48358892432-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">False</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf48358892432-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">steps</span><span class="crayon-o">=</span><span class="crayon-cn">1000</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714" 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-610fea87ebf4a966846714-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-20">20</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-21">21</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-22">22</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-23">23</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-24">24</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf4a966846714-25">25</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-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-610fea87ebf4a966846714-2" class="crayon-line crayon-striped-line"><span class="crayon-v">WARNING</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Trapezoidal </span><span class="crayon-e">rule </span><span class="crayon-st">is</span> <span class="crayon-e">known </span><span class="crayon-st">to</span> <span class="crayon-e">produce </span><span class="crayon-e">incorrect </span><span class="crayon-v">PR</span><span class="crayon-o">-</span><span class="crayon-v">AUCs</span><span class="crayon-sy">;</span> <span class="crayon-e">please </span><span class="crayon-st">switch</span> <span class="crayon-st">to</span> <span class="crayon-s">"careful_interpolation"</span> <span class="crayon-v">instead</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-3" class="crayon-line"><span class="crayon-v">WARNING</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Trapezoidal </span><span class="crayon-e">rule </span><span class="crayon-st">is</span> <span class="crayon-e">known </span><span class="crayon-st">to</span> <span class="crayon-e">produce </span><span class="crayon-e">incorrect </span><span class="crayon-v">PR</span><span class="crayon-o">-</span><span class="crayon-v">AUCs</span><span class="crayon-sy">;</span> <span class="crayon-e">please </span><span class="crayon-st">switch</span> <span class="crayon-st">to</span> <span class="crayon-s">"careful_interpolation"</span> <span class="crayon-v">instead</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-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">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-610fea87ebf4a966846714-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">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">06</span><span class="crayon-o">-</span><span class="crayon-cn">02</span><span class="crayon-o">-</span><span class="crayon-cn">08</span><span class="crayon-o">:</span><span class="crayon-cn">28</span><span class="crayon-o">:</span><span class="crayon-cn">52</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-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">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-610fea87ebf4a966846714-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">Restoring </span><span class="crayon-e">parameters </span><span class="crayon-e">from </span><span class="crayon-v">ongoing</span><span class="crayon-o">/</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-610fea87ebf4a966846714-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">Running </span><span class="crayon-v">local_init_op</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-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">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-610fea87ebf4a966846714-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-i">Evaluation</span> <span class="crayon-sy">[</span><span class="crayon-cn">100</span><span class="crayon-o">/</span><span class="crayon-cn">1000</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-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-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">06</span><span class="crayon-o">-</span><span class="crayon-cn">02</span><span class="crayon-o">-</span><span class="crayon-cn">08</span><span class="crayon-o">:</span><span class="crayon-cn">28</span><span class="crayon-o">:</span><span class="crayon-cn">54</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-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-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">accuracy</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.8358209</span><span class="crayon-sy">,</span> <span class="crayon-v">accuracy_baseline</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.76377374</span><span class="crayon-sy">,</span> <span class="crayon-v">auc</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.88401634</span><span class="crayon-sy">,</span> <span class="crayon-v">auc_precision_recall</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.69599575</span><span class="crayon-sy">,</span> <span class="crayon-v">average_loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.35122654</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">label</span><span class="crayon-o">/</span><span class="crayon-v">mean</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.23622628</span><span class="crayon-sy">,</span> <span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">44.67437</span><span class="crayon-sy">,</span> <span class="crayon-v">precision</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.68986726</span><span class="crayon-sy">,</span> <span class="crayon-v">prediction</span><span class="crayon-o">/</span><span class="crayon-v">mean</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.23320661</span><span class="crayon-sy">,</span> <span class="crayon-v">recall</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.55408216</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-13" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-14" class="crayon-line crayon-striped-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-15" class="crayon-line"><span class="crayon-sy">{</span><span class="crayon-s">'accuracy'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.8358209</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-16" class="crayon-line crayon-striped-line"><span class="crayon-s">'accuracy_baseline'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.76377374</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-17" class="crayon-line"><span class="crayon-s">'auc'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.88401634</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-18" class="crayon-line crayon-striped-line"><span class="crayon-s">'auc_precision_recall'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.69599575</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-19" class="crayon-line"><span class="crayon-s">'average_loss'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.35122654</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-20" class="crayon-line crayon-striped-line"><span class="crayon-s">'global_step'</span><span class="crayon-o">:</span> <span class="crayon-cn">1000</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-21" class="crayon-line"><span class="crayon-s">'label/mean'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.23622628</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-22" class="crayon-line crayon-striped-line"><span class="crayon-s">'loss'</span><span class="crayon-o">:</span> <span class="crayon-cn">44.67437</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-23" class="crayon-line"><span class="crayon-s">'precision'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.68986726</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-24" class="crayon-line crayon-striped-line"><span class="crayon-s">'prediction/mean'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.23320661</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4a966846714-25" class="crayon-line"><span class="crayon-s">'recall'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.55408216</span><span class="crayon-sy">}</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Mức độ ch&iacute;nh x&aacute;c mới l&agrave; 83,58%. N&oacute; cao hơn bốn phần trăm so với m&ocirc; h&igrave;nh trước đ&oacute;.</p> <p style="text-align: justify;">Cuối c&ugrave;ng, bạn c&oacute; thể th&ecirc;m điều khoản quy định để tr&aacute;nh t&igrave;nh trạng qu&aacute; khớp.</p> <h4 id="ftoc-heading-16" class="ftwp-heading" style="text-align: justify;">Bước 5) Si&ecirc;u tham số: Lasso &amp; Ridge</h4> <p style="text-align: justify;">M&ocirc; h&igrave;nh của bạn c&oacute; thể bị&nbsp;<strong>overfitting</strong>&nbsp;hoặc&nbsp;<strong>underfitting</strong>.</p> <ul style="text-align: justify;"> <li>Overfitting: M&ocirc; h&igrave;nh kh&ocirc;ng thể đưa ra dự đo&aacute;n ch&iacute;nh x&aacute;c tr&ecirc;n dữ liệu mới</li> <li>Underfitting: M&ocirc; h&igrave;nh kh&ocirc;ng thể nắm bắt được mẫu dữ liệu. Tức l&agrave; hồi quy tuyến t&iacute;nh khi dữ liệu phi tuyến t&iacute;nh</li> </ul> <p style="text-align: justify;">Khi một m&ocirc; h&igrave;nh c&oacute; nhiều tham số v&agrave; lượng dữ liệu tương đối thấp, n&oacute; sẽ dẫn đến dự đo&aacute;n k&eacute;m. Trọng số được sử dụng để đưa ra dự đo&aacute;n. Nếu c&aacute;c quan s&aacute;t của tập kiểm tra cho nh&oacute;m cụ thể n&agrave;y ho&agrave;n to&agrave;n kh&aacute;c với tập huấn luyện, th&igrave; m&ocirc; h&igrave;nh sẽ đưa ra dự đo&aacute;n sai. Trong qu&aacute; tr&igrave;nh đ&aacute;nh gi&aacute; với tập huấn luyện, độ ch&iacute;nh x&aacute;c l&agrave; tốt, nhưng kh&ocirc;ng tốt với tập kiểm tra v&igrave; c&aacute;c trọng số được t&iacute;nh kh&ocirc;ng phải l&agrave; trọng số thực để tổng qu&aacute;t h&oacute;a mẫu. Trong trường hợp n&agrave;y, n&oacute; kh&ocirc;ng đưa ra dự đo&aacute;n hợp l&yacute; về dữ liệu kh&ocirc;ng nh&igrave;n thấy.</p> <p style="text-align: justify;">Để ngăn chặn việc qu&aacute; khớp, ch&iacute;nh quy h&oacute;a cung cấp cho bạn khả năng kiểm so&aacute;t sự phức tạp đ&oacute; v&agrave; l&agrave;m cho n&oacute; dễ tổng qu&aacute;t hơn. C&oacute; hai kỹ thuật ch&iacute;nh quy h&oacute;a:</p> <ul style="text-align: justify;"> <li>L1: Lasso</li> <li>L2: Ridge</li> </ul> <p style="text-align: justify;">Trong TensorFlow, bạn c&oacute; thể th&ecirc;m hai si&ecirc;u tham số n&agrave;y trong tr&igrave;nh tối ưu h&oacute;a. V&iacute; dụ, si&ecirc;u tham số L2 c&agrave;ng cao, trọng số c&oacute; xu hướng rất thấp v&agrave; gần bằng kh&ocirc;ng, khi L2 gần bằng 0 c&oacute; nghĩa l&agrave; trọng số gần với hồi quy tuyến t&iacute;nh th&ocirc;ng thường.</p> <p style="text-align: justify;">Bạn c&oacute; thể tự m&igrave;nh thử c&aacute;c gi&aacute; trị kh&aacute;c nhau của c&aacute;c si&ecirc;u tham số v&agrave; xem liệu bạn c&oacute; thể tăng mức độ ch&iacute;nh x&aacute;c hay kh&ocirc;ng.</p> <p style="text-align: justify;">H&atilde;y xem mức độ ch&iacute;nh x&aacute;c:</p> <div id="urvanov-syntax-highlighter-610fea87ebf4d898126226" 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-610fea87ebf4d898126226-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf4d898126226-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf4d898126226-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf4d898126226-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf4d898126226-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf4d898126226-6">6</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf4d898126226-1" class="crayon-line"><span class="crayon-v">model_regu</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">LinearClassifier</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4d898126226-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">model_dir</span><span class="crayon-o">=</span><span class="crayon-s">"ongoing/train4"</span><span class="crayon-sy">,</span> <span class="crayon-v">feature_columns</span><span class="crayon-o">=</span><span class="crayon-v">categorical_features</span><span class="crayon-o">+</span><span class="crayon-v">base_columns</span><span class="crayon-o">+</span><span class="crayon-v">education_x_occupation</span><span class="crayon-o">+</span><span class="crayon-v">age_buckets_x_education_x_occupation</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4d898126226-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">optimizer</span><span class="crayon-o">=</span><span class="crayon-v">tf</span><span class="crayon-sy">.</span><span class="crayon-v">train</span><span class="crayon-sy">.</span><span class="crayon-e">FtrlOptimizer</span><span class="crayon-sy">(</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4d898126226-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">learning_rate</span><span class="crayon-o">=</span><span class="crayon-cn">0.1</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4d898126226-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">l1_regularization_strength</span><span class="crayon-o">=</span><span class="crayon-cn">0.9</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf4d898126226-6" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">l2_regularization_strength</span><span class="crayon-o">=</span><span class="crayon-cn">5</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-610fea87ebf51365097928" 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-610fea87ebf51365097928-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf51365097928-2">2</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf51365097928-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-610fea87ebf51365097928-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">'ongoing/train4'</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">0x1820d9c128</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> <div id="urvanov-syntax-highlighter-610fea87ebf53149785131" 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-610fea87ebf53149785131-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf53149785131-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf53149785131-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf53149785131-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf53149785131-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf53149785131-1" class="crayon-line"><span class="crayon-v">model_regu</span><span class="crayon-sy">.</span><span class="crayon-e">train</span><span class="crayon-sy">(</span><span class="crayon-v">input_fn</span><span class="crayon-o">=</span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">df_train_new</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf53149785131-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-v">None</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf53149785131-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf53149785131-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">False</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf53149785131-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">steps</span><span class="crayon-o">=</span><span class="crayon-cn">1000</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517" 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-610fea87ebf57428280517-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-20">20</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-21">21</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-22">22</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-23">23</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-24">24</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-25">25</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-26">26</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-27">27</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-28">28</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-29">29</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-30">30</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf57428280517-31">31</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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-610fea87ebf57428280517-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-610fea87ebf57428280517-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-610fea87ebf57428280517-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-610fea87ebf57428280517-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-610fea87ebf57428280517-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-610fea87ebf57428280517-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">ongoing</span><span class="crayon-o">/</span><span class="crayon-v">train4</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-610fea87ebf57428280517-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">88.722855</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-610fea87ebf57428280517-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">77.4165</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">50.38778</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.294</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">187.889</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">55.38014</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.535</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">201.895</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">46.806694</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.491</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">217.992</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">38.68271</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.460</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">193.676</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">56.99398</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.516</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">202.195</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">33.263622</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.497</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">216.756</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">37.7902</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.459</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">240.215</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">61.732605</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.416</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">220.336</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">46.938225</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.456</span> <span class="crayon-v">sec</span><span class="crayon-sy">)</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-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">ongoing</span><span class="crayon-o">/</span><span class="crayon-v">train4</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-610fea87ebf57428280517-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">43.4942.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-29" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-30" class="crayon-line crayon-striped-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf57428280517-31" class="crayon-line"><span class="crayon-o">&amp;</span><span class="crayon-v">lt</span><span class="crayon-sy">;</span><span class="crayon-v">tensorflow</span><span class="crayon-sy">.</span><span class="crayon-v">python</span><span class="crayon-sy">.</span><span class="crayon-v">estimator</span><span class="crayon-sy">.</span><span class="crayon-v">canned</span><span class="crayon-sy">.</span><span class="crayon-v">linear</span><span class="crayon-sy">.</span><span class="crayon-e">LinearClassifier </span><span class="crayon-i">at</span> <span class="crayon-cn">0x181ff39e48</span><span class="crayon-o">&amp;</span><span class="crayon-v">gt</span><span class="crayon-sy">;</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <div id="urvanov-syntax-highlighter-610fea87ebf59043346960" 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-610fea87ebf59043346960-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf59043346960-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf59043346960-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf59043346960-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf59043346960-5">5</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf59043346960-1" class="crayon-line"><span class="crayon-v">model_regu</span><span class="crayon-sy">.</span><span class="crayon-e">evaluate</span><span class="crayon-sy">(</span><span class="crayon-v">input_fn</span><span class="crayon-o">=</span><span class="crayon-e">get_input_fn</span><span class="crayon-sy">(</span><span class="crayon-v">df_test_new</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf59043346960-2" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">num_epochs</span><span class="crayon-o">=</span><span class="crayon-cn">1</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf59043346960-3" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">n_batch</span> <span class="crayon-o">=</span> <span class="crayon-cn">128</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf59043346960-4" class="crayon-line crayon-striped-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">shuffle</span><span class="crayon-o">=</span><span class="crayon-t">False</span><span class="crayon-sy">)</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf59043346960-5" class="crayon-line"><span class="crayon-h">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span class="crayon-v">steps</span><span class="crayon-o">=</span><span class="crayon-cn">1000</span><span class="crayon-sy">)</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;"><strong>Output</strong></p> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660" 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-610fea87ebf5b216671660-1">1</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-2">2</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-3">3</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-4">4</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-5">5</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-6">6</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-7">7</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-8">8</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-9">9</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-10">10</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-11">11</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-12">12</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-13">13</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-14">14</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-15">15</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-16">16</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-17">17</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-18">18</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-19">19</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-20">20</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-21">21</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-22">22</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-23">23</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-24">24</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-25">25</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-26">26</div> <div class="crayon-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-27">27</div> <div class="crayon-num crayon-striped-num" data-line="urvanov-syntax-highlighter-610fea87ebf5b216671660-28">28</div> </div> </td> <td class="urvanov-syntax-highlighter-code"> <div class="crayon-pre"> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-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-610fea87ebf5b216671660-2" class="crayon-line crayon-striped-line"><span class="crayon-v">WARNING</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Trapezoidal </span><span class="crayon-e">rule </span><span class="crayon-st">is</span> <span class="crayon-e">known </span><span class="crayon-st">to</span> <span class="crayon-e">produce </span><span class="crayon-e">incorrect </span><span class="crayon-v">PR</span><span class="crayon-o">-</span><span class="crayon-v">AUCs</span><span class="crayon-sy">;</span> <span class="crayon-e">please </span><span class="crayon-st">switch</span> <span class="crayon-st">to</span> <span class="crayon-s">"careful_interpolation"</span> <span class="crayon-v">instead</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-3" class="crayon-line"><span class="crayon-v">WARNING</span><span class="crayon-o">:</span><span class="crayon-v">tensorflow</span><span class="crayon-o">:</span><span class="crayon-e">Trapezoidal </span><span class="crayon-e">rule </span><span class="crayon-st">is</span> <span class="crayon-e">known </span><span class="crayon-st">to</span> <span class="crayon-e">produce </span><span class="crayon-e">incorrect </span><span class="crayon-v">PR</span><span class="crayon-o">-</span><span class="crayon-v">AUCs</span><span class="crayon-sy">;</span> <span class="crayon-e">please </span><span class="crayon-st">switch</span> <span class="crayon-st">to</span> <span class="crayon-s">"careful_interpolation"</span> <span class="crayon-v">instead</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-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">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-610fea87ebf5b216671660-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">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">06</span><span class="crayon-o">-</span><span class="crayon-cn">02</span><span class="crayon-o">-</span><span class="crayon-cn">08</span><span class="crayon-o">:</span><span class="crayon-cn">29</span><span class="crayon-o">:</span><span class="crayon-cn">07</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-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">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-610fea87ebf5b216671660-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">Restoring </span><span class="crayon-e">parameters </span><span class="crayon-e">from </span><span class="crayon-v">ongoing</span><span class="crayon-o">/</span><span class="crayon-v">train4</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-610fea87ebf5b216671660-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">Running </span><span class="crayon-v">local_init_op</span><span class="crayon-sy">.</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-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">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-610fea87ebf5b216671660-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-i">Evaluation</span> <span class="crayon-sy">[</span><span class="crayon-cn">100</span><span class="crayon-o">/</span><span class="crayon-cn">1000</span><span class="crayon-sy">]</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-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-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">06</span><span class="crayon-o">-</span><span class="crayon-cn">02</span><span class="crayon-o">-</span><span class="crayon-cn">08</span><span class="crayon-o">:</span><span class="crayon-cn">29</span><span class="crayon-o">:</span><span class="crayon-cn">09</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-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-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">accuracy</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.83833915</span><span class="crayon-sy">,</span> <span class="crayon-v">accuracy_baseline</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.76377374</span><span class="crayon-sy">,</span> <span class="crayon-v">auc</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.8869794</span><span class="crayon-sy">,</span> <span class="crayon-v">auc_precision_recall</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.7014905</span><span class="crayon-sy">,</span> <span class="crayon-v">average_loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.34691378</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">label</span><span class="crayon-o">/</span><span class="crayon-v">mean</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.23622628</span><span class="crayon-sy">,</span> <span class="crayon-v">loss</span> <span class="crayon-o">=</span> <span class="crayon-cn">44.12581</span><span class="crayon-sy">,</span> <span class="crayon-v">precision</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.69720596</span><span class="crayon-sy">,</span> <span class="crayon-v">prediction</span><span class="crayon-o">/</span><span class="crayon-v">mean</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.23662092</span><span class="crayon-sy">,</span> <span class="crayon-v">recall</span> <span class="crayon-o">=</span> <span class="crayon-cn">0.5579823</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-13" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-14" class="crayon-line crayon-striped-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-15" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-16" class="crayon-line crayon-striped-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-17" class="crayon-line"></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-18" class="crayon-line crayon-striped-line"><span class="crayon-sy">{</span><span class="crayon-s">'accuracy'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.83833915</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-19" class="crayon-line"><span class="crayon-s">'accuracy_baseline'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.76377374</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-20" class="crayon-line crayon-striped-line"><span class="crayon-s">'auc'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.8869794</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-21" class="crayon-line"><span class="crayon-s">'auc_precision_recall'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.7014905</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-22" class="crayon-line crayon-striped-line"><span class="crayon-s">'average_loss'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.34691378</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-23" class="crayon-line"><span class="crayon-s">'global_step'</span><span class="crayon-o">:</span> <span class="crayon-cn">1000</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-24" class="crayon-line crayon-striped-line"><span class="crayon-s">'label/mean'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.23622628</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-25" class="crayon-line"><span class="crayon-s">'loss'</span><span class="crayon-o">:</span> <span class="crayon-cn">44.12581</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-26" class="crayon-line crayon-striped-line"><span class="crayon-s">'precision'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.69720596</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-27" class="crayon-line"><span class="crayon-s">'prediction/mean'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.23662092</span><span class="crayon-sy">,</span></div> <div id="urvanov-syntax-highlighter-610fea87ebf5b216671660-28" class="crayon-line crayon-striped-line"><span class="crayon-s">'recall'</span><span class="crayon-o">:</span> <span class="crayon-cn">0.5579823</span><span class="crayon-sy">}</span></div> </div> </td> </tr> </tbody> </table> </div> </div> <p style="text-align: justify;">Với si&ecirc;u tham số n&agrave;y, bạn sẽ tăng một ch&uacute;t số liệu về độ ch&iacute;nh x&aacute;c.</p> <h3 id="ftoc-heading-17" class="ftwp-heading" style="text-align: justify;">Kết Luận</h3> <p style="text-align: justify;">Để đ&agrave;o tạo một m&ocirc; h&igrave;nh, 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 trainset/testset</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 (Tỷ lệ học)</li> <li>Số epoch</li> <li>Batch size</li> <li>Số lớp</li> </ul> </li> </ul> <p style="text-align: justify;">Trong b&agrave;i viết n&agrave;y, ch&uacute;ng ta đ&atilde; học c&aacute;ch sử dụng API cấp cao cho bộ ph&acirc;n loại hồi quy tuyến t&iacute;nh. Cần x&aacute;c định:</p> <ol style="text-align: justify;"> <li>C&aacute;c cột đặc trưng. Nếu li&ecirc;n tục: tf.feature_column.numeric_column(). Bạn c&oacute; thể điền v&agrave;o một danh s&aacute;ch với khả năng hiểu danh s&aacute;ch python</li> <li>Estimator: tf.estimator.LinearClassifier (feature_columns, model_dir, n_classes = 2)</li> <li>Một h&agrave;m để nhập dữ liệu, batch size v&agrave; epoch: input_fn()</li> </ol> <p style="text-align: justify;">Sau đ&oacute;, đ&atilde; sẵn s&agrave;ng đ&agrave;o tạo, đ&aacute;nh gi&aacute; v&agrave; đưa ra dự đo&aacute;n với train(), evaluate() v&agrave; predict().</p> <p style="text-align: justify;">Để cải thiện hiệu suất của m&ocirc; h&igrave;nh, bạn c&oacute; thể:</p> <ul style="text-align: justify;"> <li>Sử dụng hồi quy đa thức</li> <li>Interaction term: tf.feature_column.crossed_column</li> <li>Th&ecirc;m tham số ch&iacute;nh quy.</li> </ul> <p style="text-align: justify;">B&agrave;i viết tiếp theo:&nbsp;<a href="../../kernel-methods-trong-machine-learning-tu-hoc-tensorflow/" target="_blank" rel="noopener">Kernel Methods trong Machine learning</a></p>