#deeplearning course-01

deeplearning course-01

@(学习笔记)


本笔记为Andrew NG的DeepLearning课程,其链接为:Coursera链接 网易云课堂链接
个人建议用coursera的比较好,虽然付费了,但是有题目可以做

PS:如果有错误,欢迎指正!


1.学习概论

  • m作为训练数据大小

2. numpy常用操作方式

  1. 1.
cal = A.sum(axis = 0) #矩阵纵向列(垂直)相加
  1. numpy具备 broadcast功能,即,矩阵向量等相加,自动扩增维度相加;
A = [1 ,2 ,3
     4, 5, 6]
B = [2 , 2, 2]
C = A + B = [3, 4, 5
             6, 7, 8]
  1. debug方式
    • 不要使用shape (5,)的方式,该方式生成的不是向量而是一排数字,其转置和本体相同,可能会造成奇怪的问题;
a =  np.random.randn(5) 错误,rank = 1
a = np.random.randn(5,1) 正确
  • 利用断言判断维度是否正确:
assert(a.shape ==(5,1))
  • 归一化
    Another common technique we use in Machine Learning and Deep Learning is to normalize our data. It often leads to a better performance because gradient descent converges faster after normalization. Here, by normalization we mean changing x to xx x ‖ x ‖ (dividing each row vector of x by its norm).

For example, if

x=[023644](3) (3) x = [ 0 3 4 2 6 4 ]
then
x=np.linalg.norm(x,axis=1,keepdims=True)=[556](4) (4) ‖ x ‖ = n p . l i n a l g . n o r m ( x , a x i s = 1 , k e e p d i m s = T r u e ) = [ 5 56 ]
and
x_normalized=xx=[02563565645456](5) (5) x _ n o r m a l i z e d = x ‖ x ‖ = [ 0 3 5 4 5 2 56 6 56 4 56 ]
Note that you can divide matrices of different sizes and it works fine: this is called broadcasting and you’re going to learn about it in part 5.
- 展开矩阵为一维
For convenience, you should now reshape images of shape (num_px, num_px, 3) in a numpy-array of shape (num_px num_px 3, 1). After this, our training (and test) dataset is a numpy-array where each column represents a flattened image. There should be m_train (respectively m_test) columns.

Exercise: Reshape the training and test data sets so that images of size (num_px, num_px, 3) are flattened into single vectors of shape (num_px num_px 3, 1).

A trick when you want to flatten a matrix X of shape (a,b,c,d) to a matrix X_flatten of shape (b cd, a) is to use:

X_flatten = X.reshape(X.shape[0], -1).T      # X.T is the transpose of X
  • propagate:
    m = X.shape[1]

    # FORWARD PROPAGATION (FROM X TO COST)
    ### START CODE HERE ### (≈ 2 lines of code)
    A = sigmoid(np.dot(w.T,X)+b)                                    # compute activation
    print("A shape: " + str(A.shape))
    print("Y shape: " + str(Y.shape))
    cost = -sum(sum(Y*np.log(A) + (1-Y)*np.log(1-A))/m)                                 # compute cost
    print("cost" + str(cost))
    ### END CODE HERE ###

    # BACKWARD PROPAGATION (TO FIND GRAD)
    ### START CODE HERE ### (≈ 2 lines of code)
    dw = np.dot(X,(A-Y).T)/m
    db = np.sum(A-Y)/m
    ### END CODE HERE ###
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值