没有合适的资源?快使用搜索试试~ 我知道了~
首页Python深度学习实战指南:初学者入门教程
"《基于Python的深度学习:实践入门》" 这本书名为《基于Python的深度学习:实践入门》(DeepLearning with Python: A Hands-on Introduction),作者是Nikhil Ketkar。它是一本针对初学者编写的深入浅出的教程,旨在帮助读者快速掌握深度学习的基础知识和实战技能,特别强调了Python这一强大的编程工具在深度学习领域的应用。 书中内容覆盖了深度学习的基本概念、原理和实际操作步骤,包括但不限于神经网络的构建、深度学习框架如TensorFlow和Keras的使用,以及卷积神经网络(CNN)、循环神经网络(RNN)等核心模型的实现。通过大量的实例和案例分析,读者可以直观地理解这些复杂算法的工作原理,并能够在实践中运用它们解决实际问题。 该书不仅适合计算机科学专业背景的初学者,也对希望扩展技术栈或从事数据科学、人工智能领域工作的工程师具有很高的价值。作者Nikhil Ketkar以其清晰的讲解和实用的教学方法,引导读者逐步掌握深度学习的核心技术和Python编程技巧。 此外,书籍提供了丰富的代码示例,读者可以在阅读过程中跟随代码进行实践操作,加深理解和记忆。同时,书中还包含了一些版权和许可声明,确保读者在合法范围内使用信息,尊重知识产权。 《基于Python的深度学习:实践入门》是一本结合理论与实践的教程,是深度学习初学者进入这个领域的理想指南,也是技术从业者提升技能、探索新趋势的实用参考书。无论是想从零开始学习深度学习,还是想要在Python环境下深化现有知识,这本书都是一个不可多得的资源。
资源详情
资源推荐
![](https://csdnimg.cn/release/download_crawler_static/10051677/bg10.jpg)
Chapter 1 ■ IntroduCtIon to deep LearnIng
4
Overview of Subsequent Chapters
We now provide an overall outline of the subsequent chapters for the reader. It is important to note that
each of the chapters covers either the concepts or the skills (or in certain cases both) with respect to deep
learning. We highlight these below so that the readers can ensure that they have internalized these concepts
and skills. It is highly recommended that the readers not only read the chapters but also work out the
mathematical details (using pen and paper) and play with the source code provided in each of the chapters.
1. Chapter 2 covers the basics of Machine Learning. The key take home point for
this chapter is the concept of generalizing over unseen examples, the ideas of
over-fitting and under-fitting the training data, the capacity of the model, and the
notion of regularization.
2. Chapter 3 covers Feed Forward Neural Networks and serves as the conceptual
foundation for the entire book. Concepts like the overall structure of the neural
network, the input, hidden and output layers, cost functions and their basis on
the principle of Maximum Likelihood are the important concepts in this chapter.
3. Chapter 4 provides a hands-on introduction to the Theano library. It covers how
to define networks as computational graphs, automatically derive gradients for
complicated networks, and train neural networks.
4. Chapter 5 covers Convolutional Neural Networks, which are perhaps the most
successful application of deep learning.
5. Chapter 6 covers Recurrent Neural Networks and Long Short Term Memory
(LSTM) networks, which are another successful application of deep learning.
6. Chapter 7 provides a hands-on introduction to the Keras library. The Keras
library provides a number of high-level abstractions over the Theano library
and is probably the ideal go-to tool when it comes to building deep learning
applications.
7. Chapter 8 introduces the reader to Stochastic Gradient Descent (SGD), which is
the most common procedure used to train Neural Networks. This chapter also
covers the shortcomings of SGD and a number of variations to SGD that address
these shortcomings.
8. Chapter 9 introduces the reader to Automatic Differentiation (commonly
referred to as backpropagation), which is a standard technique used to derive
gradients (required for SGD) for arbitrarily complicated networks.
9. Chapter 10 introduces the reader to Graphical Processing Units (GPUs) and
GPU-based computation, which has acted as a key enabling technology for deep
learning.
Installing the Required Libraries
There are a number of libraries that the reader will need to install in order to run the source code for
the examples in the chapters. We recommend that the reader install Anaconda Python Distribution
(https://www.continuum.io/downloads), which would make the process of installing the required packages
significantly easy (using either conda or pip). The list of packages the reader would need includes Scikit-learn,
Theano, Autograd, Keras, and PyOpenCL.
![](https://csdnimg.cn/release/download_crawler_static/10051677/bg11.jpg)
5
© Nikhil Ketkar 2017
N. Ketkar, Deep Learning with Python, DOI 10.1007/978-1-4842-2766-4_2
CHAPTER 2
Machine Learning Fundamentals
Deep Learning is a branch of Machine Learning and in this chapter we will cover the fundamentals of
Machine Learning. While machine learning as a subject is inherently mathematical in nature, we will keep
mathematics to the basic minimum required to develop intuition about the subject. Prerequisites for the
subject matter covered in this chapter would be linear algebra, multivariable calculus, and basic probability
theory.
Intuition
As human beings we are intuitively aware of the concept of learning: it simply means to get better at a task
over a period of time. The task could be physical (like learning to drive a car) or intellectual (like learning
a new language). The subject of machine learning focuses on development of algorithms that can learn as
humans do; that is, they get better at a task over a period over time, with experience.
The first question to ask is why we would be interested in development of algorithms that improve
their performance over time, with experience. After all, there are many algorithms that are developed and
implemented to solve real world problems that don’t improve over time, they simply are developed by
humans and implemented in software and they get the job done. From banking to e-commerce and from
navigation systems in our cars to landing a spacecraft on the moon, algorithms are everywhere, and, a
majority of them do not improve over time. These algorithms simply perform the task they are intended to
perform, with some maintenance required from time to time. Why do we need machine learning?
The answer to this question is that for certain tasks it is easier to develop an algorithm that learns/
improves its performance with experience than to develop an algorithm manually. While this might seem
unintuitive to the reader at this point, we will build intuition for this during the course of this chapter.
Binary Classification
In order to further discuss the matter at hand, we need to be precise about some of the terms we have been
intuitively using, like task, learning, experience, and improvement. We will start with the task of binary
classification.
Consider an abstract problem domain where we have data of the form
D = {(x
1
, y
1
), (x
2
, y
2
), … (x
n
, y
n
)}
where x
n
Î
and y = ±1. We do not have access to all such data but only a subset
SDÎ
. Using S, our task
is to generate a computational procedure that implements the function
fx y:
®
such that we can use f to
make predictions over unseen data
xy S
ii
,
()
Ï that are correct, fx y
ii
()
= . Let us denote
UDÎ
as the set of
![](https://csdnimg.cn/release/download_crawler_static/10051677/bg12.jpg)
CHAPTER 2 ■ MACHINE LEARNING FUNDAMENTALS
6
unseen data, that is,
xy S
ii
,
()
Ï and xy U
ii
,
()
Î . We measure performance over this task as the error over
unseen data,
EfDU
fx y
U
xy U
ii
ii
,,
()
=
()
¹
é
ë
ù
û
()
Î
å
,
.
We now have a precise definition of the task, which is to categorize data into one of two categories
(y = ±1) based on some seen data S by generating f. We measure performance (and improvement in
performance) using the error E (f,D,U) over unseen data U. The size of the seen data |S| is the conceptual
equivalent of experience. In this context, we want to develop algorithms that generate such functions
f (which are commonly referred to as a model). In general, the field of machine learning studies the
development of such algorithms that produce models that make predictions over unseen data for such
algorithms, and other formal tasks (we will be introducing multiple such tasks later in the chapter). Note that
the x is commonly referred to as the input/input variable and y is referred to as the output/output variable.
As with any other discipline in computer science, the computational characteristics of such algorithms
is an important facet, but in addition to that we also would like to have a model f that achieves a lower error
E (f, D, U) with as small a |S| as possible.
Let us now relate this abstract but precise definition to a real world problem so that our abstractions
are grounded. Let us say an e-commerce web site wants to customize the landing page for registered users
to show them the products the users might be interested in buying. The web site has historical data on users
and would like to implement this as a feature so as to increase sales. Let us now see how this real world
problem maps onto the abstract problem of binary classification we described earlier.
The first thing that one might notice is that given a particular user and a particular product, one wants
to predict whether the user will buy the product. Since this is the value to be predicted, it maps onto y = ±1,
where we will let the value of y = +1 denote the prediction that the user will buy the product and we will
denote y = –1 as the prediction that the user does not buy the product. Note that that there is no particular
reason for picking these values; we could have swapped this (let y = +1 denote the does not buy case and
y = –1 denote the buy case) and there would be no difference. We just use y = ±1 to denote the two classes of
interest to categorize data. Next, let us assume that we can somehow represent the attributes of the product
and the user’s buying and browsing history as
x
n
Î
. This step is referred to as feature engineering in
machine learning and we will cover it later in the chapter. For now, it suffices to say that we are able to
generate such a mapping. Thus, we have historical data of what the users browsed and bought, attributes of
a product and whether the user bought the product or not mapped onto {(x
1
,y
1
),(x
2
, y
2
), … (x
n
, y
n
)}. Now,
based on this data, we would like to generate a function or a model
fx y:
®
which we can use to determine
which products a particular user will buy and use this to populate the landing page for users. We can
measure how well the model is doing on unseen data by populating the landing page for users and see
whether they buy the products or not and evaluate the error E (f,D,U).
Regression
Let us introduce another task, namely regression. Here, we have data of the form Dxyxyxy
nn
=
()()
¼
()
{}
11 22
,, ,
,,
where
x
n
Î
and y
Î
and our task is to generate a computational procedure that implements the function
fx y:
®
. Note that instead of the prediction being a binary class label y = ±1 like in binary classification, we have
real valued prediction. We measure performance over this task as the root mean squared error (RMSE) over
unseen data,
![](https://csdnimg.cn/release/download_crawler_static/10051677/bg13.jpg)
CHAPTER 2 ■ MACHINE LEARNING FUNDAMENTALS
7
EfDU
yfx
U
xy U
ii
ii
,,
()
=
-
()
()
æ
è
ç
ç
ç
ç
ö
ø
÷
÷
÷
÷
()
Î
å
,
2
1
2
.
■ Note That the RMSE is simply taking the difference between the predicted and actual value, squaring it so
as to account for both positive and negative differences, taking the mean so as to aggregate over all the unseen
data and, finally, taking the square root so as to counterbalance the square operation.
A real world problem that corresponds to the abstract task of regression is to predict the credit score for
an individual based on their financial history, which can be used by a credit card company to extend the line
of credit.
Generalization
Let us now cover what is the single most important intuition in machine leaning, which is that we want to
develop/generate models that have good performance over unseen data. In order to do that, let us introduce
a toy data set for a regression task first.
We generate the toy dataset by generating 100 values equidistantly between -1 and 1 as the input
variable (x). We generate the output variable (y) based on
yxx=+
++
22
2
where ε
~,
.N 001
()
is noise
(random variation) from a normal distribution with 0 mean and 0.1 being the standard deviation. Code for
this is presented in Listing 2-1 and the data is plotted in Figure2-1.
Listing 2-1. Generalization vs. Rote Learning
#Generate Toy Dataset
import pylab
import numpy
x = numpy.linspace(-1,1,100)
signal = 2 + x + 2 * x * x
noise = numpy.random.normal(0, 0.1, 100)
y = signal + noise
pylab.plot(signal,'b');
pylab.plot(y,'g')
pylab.plot(noise, 'r')
pylab.xlabel("x")
pylab.ylabel("y")
pylab.legend(["Without Noise", "With Noise", "Noise"], loc = 2)
x_train = x[0:80]
y_train = y[0:80]
# Model with degree 1
pylab.figure()
degree = 2
X_train = numpy.column_stack([numpy.power(x_train,i) for i in xrange(0,degree)])
![](https://csdnimg.cn/release/download_crawler_static/10051677/bg14.jpg)
CHAPTER 2 ■ MACHINE LEARNING FUNDAMENTALS
8
model = numpy.dot(numpy.dot(numpy.linalg.inv(numpy.dot(X_train.transpose(),X_train)),X_
train.transpose()),y_train)
pylab.plot(x,y,'g')
pylab.xlabel("x")
pylab.ylabel("y")
predicted = numpy.dot(model, [numpy.power(x,i) for i in xrange(0,degree)])
pylab.plot(x, predicted,'r')
pylab.legend(["Actual", "Predicted"], loc = 2)
train_rmse1 = numpy.sqrt(numpy.sum(numpy.dot(y[0:80] - predicted[0:80], y_train -
predicted[0:80])))
test_rmse1 = numpy.sqrt(numpy.sum(numpy.dot(y[80:] - predicted[80:], y[80:] -
predicted[80:])))
print("Train RMSE (Degree = 1)", train_rmse1)
print("Test RMSE (Degree = 1)", test_rmse1)
# Model with degree 2
pylab.figure()
degree = 3
X_train = numpy.column_stack([numpy.power(x_train,i) for i in xrange(0,degree)])
model = numpy.dot(numpy.dot(numpy.linalg.inv(numpy.dot(X_train.transpose(),X_train)),
X_train.transpose()),y_train)
pylab.plot(x,y,'g')
pylab.xlabel("x")
pylab.ylabel("y")
predicted = numpy.dot(model, [numpy.power(x,i) for i in xrange(0,degree)])
pylab.plot(x, predicted,'r')
pylab.legend(["Actual", "Predicted"], loc = 2)
train_rmse1 = numpy.sqrt(numpy.sum(numpy.dot(y[0:80] - predicted[0:80],
y_train - predicted[0:80])))
test_rmse1 = numpy.sqrt(numpy.sum(numpy.dot(y[80:] - predicted[80:],
y[80:] - predicted[80:])))
print("Train RMSE (Degree = 2)", train_rmse1)
print("Test RMSE (Degree = 2)", test_rmse1)
# Model with degree 8
pylab.figure()
degree = 9
X_train = numpy.column_stack([numpy.power(x_train,i) for i in xrange(0,degree)])
model = numpy.dot(numpy.dot(numpy.linalg.inv(numpy.dot(X_train.transpose(),X_train)),
X_train.transpose()), y_train)
pylab.plot(x, y,'g')
pylab.xlabel("x")
pylab.ylabel("y")
predicted = numpy.dot(model, [numpy.power(x,i) for i in xrange(0,degree)])
pylab.plot(x, predicted,'r')
pylab.legend(["Actual", "Predicted"], loc = 3)
train_rmse2 = numpy.sqrt(numpy.sum(numpy.dot(y[0:80] - predicted[0:80],
y_train - predicted[0:80])))
test_rmse2 = numpy.sqrt(numpy.sum(numpy.dot(y[80:] - predicted[80:],
y[80:] - predicted[80:])))
print("Train RMSE (Degree = 8)", train_rmse2)
print("Test RMSE (Degree = 8)", test_rmse2)
dou.bz/35ODPo
剩余168页未读,继续阅读
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://profile-avatar.csdnimg.cn/718d1028538142ed838ef76e82bf7469_gemstoneatxm.jpg!1)
黑猫警长
- 粉丝: 19
- 资源: 11
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![](https://csdnimg.cn/release/wenkucmsfe/public/img/voice.245cc511.png)
最新资源
- 岩石滑动与断层冲击地压:声发射特征分析
- 新时代煤炭工业八大战略新取向剖析
- 开采强度对华亭矿区冲击地压危险性的影响分析
- 新安煤矿探采对比:影响安全生产的关键因素与技术支撑
- 210MW循环流化床锅炉引风机变频改造优化与节能效果
- 浅埋煤层开采沉陷预测:方法应用与影响分析
- 优化巷道过陷落柱支护方案:数值模拟与现场试验
- 坚硬顶板定向断裂爆破技术:安全高效采煤新方案
- 北航2019算法课作业解析:投资策略与凸子多边形优化
- 断层破碎带垮冒下堆积体边界抗力分布关键影响因素
- 哈拉沟选煤厂优化末煤系统提高效率与处理能力
- 瓦斯涌出影响下采动煤体蠕变失稳研究
- 提升煤矿装载效率的可控箕斗定量装载设备设计
- 水分调控下烟煤瓦斯吸附特性对比研究
- 重介质悬浮液密度控制硬件设计与选型探讨
- 坚硬顶板巷道支护参数设计:现场测试与数值分析
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035711.png)
![](https://img-home.csdnimg.cn/images/20220527035111.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![](https://csdnimg.cn/release/wenkucmsfe/public/img/green-success.6a4acb44.png)