Skip to Content
Python机器学习手册:从数据预处理到深度学习
book

Python机器学习手册:从数据预处理到深度学习

by Chris Albon
July 2019
Intermediate to advanced
365 pages
8h 13m
Chinese
Publishing House of Electronics Industry
Content preview from Python机器学习手册:从数据预处理到深度学习
322
20
神经网络
讨论
正如我们在
20.7
节中讨论的,一般来说在前几个
epoch
中,训练集和测试集的误差都会
减小,但是到了某个节点,神经网络会开始“记住”测试集数据,导致训练集误差持续
减小而测试集误差开始增大。因为存在这种现象,所以一个最普遍且有效的对抗过拟合
的方法就是,监视训练过程并且在测试集误差开始增大时就结束训练。这个策略被称作
提前结束。
Keras
中,我们可以用一个回调函数来实施提前结束策略。回调函数是可以在训练
过程的某几个特定阶段应用的函数,比如在每个
epoch
结束的时候。在本节的解决方
案中,我们加入了
EarlyStopping(monitor='val_loss', patience=2)
,告诉程序我
们想监视每个
epoch
的测试集(验证集)损失,并且如果连续两个
epoch
测试集损失
的情况都没有得到改善,就中断训练。但是因为我们设定了
patience=2
,所以得不到
最佳模型,而会得到最佳模型之后的两个
epoch
的模型。因此,我们也可以添加一个
ModelCheckpoint
操作,在每个检查点(如果你有一个持续多日的训练由于某种原因被
打断,这时检查点就会很有用)之后把模型保存到文件中。这对我们会很有帮助,因为
如果设定
save_best_only=True
ModelCheckpoint
就会仅保存最佳模型。
20.10
 通过
Dropout
减少过拟合
问题描述
减少过拟合。
解决方案
使用
Dropout
(丢弃)方法向网络结构中引入噪声
#
加载库
import numpy ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

精通特征工程

精通特征工程

Alice Zheng, Amanda Casari
精通機器學習

精通機器學習

Aurélien Géron
Python数据分析基础

Python数据分析基础

Clinton W. Brownley

Publisher Resources

ISBN: 9787121369629