Neural Networks and Deep Learning week2 Logistic Regression with a Neural Network mindset

这个实验旨在通过神经网络的视角实现逻辑回归,识别猫图片。内容包括初始化参数、计算代价函数、梯度下降算法。文章提供了辅助函数如sigmoid、参数初始化、前向和后向传播、优化等,并整合成一个模型。实验还强调了避免过度拟合和调整学习率的重要性。
摘要由CSDN通过智能技术生成

该实验作业的主要目的

  1. 通过该实验指导完成对猫图片的识别
  2. 在此过程中需要a初始化参量b计算代价函数c使用连续梯度算法

你可能对以下参考文献感兴趣

http://www.wildml.com/2015/09/implementing-a-neural-network-from-scratch/    这是一篇从头开始搭建神经网络的文章,可以更好的帮助你理解神经网络的细节,该文章有github的同步文件,你也可以去看看github上同步实现操作

https://stats.stackexchange.com/questions/211436/why-normalize-images-by-subtracting-datasets-image-mean-instead-of-the-current   这是一个论坛,可以帮助你理解我们之前对图片进行标准化的原因

总体进程

载入文件

2加载数据集,并进行大小预处理

学习算法的一般结构 a初始化模型的参数b学习参数c使用参数进行预测d分析结果得出结论

现在开始我们搭建自己的神经网络

4.1 辅助函数 sigmoid

4.2 初始化模型参数 initialize_with_zeros(dim)

4.3 前向和后向传播 propagate(w, b, X, Y)  注意,本次中我们仅1层网络(没有掩蔽层),因此前向传播和后向传播写在一起,一般情况下,前向传播和后向传播是分开写的,这将在下周或者下下周的代码中有所体现

4.4 训练参数optimize(w, b, X, Y, num_iterations, learning_rate, print_cost = False)

4.4 预测结果 predict(w, b, X)

5 整合神经网络的操作 model(X_train, Y_train, X_test, Y_test, num_iterations = 2000, learning_rate = 0.5, print_cost = False)

现在你已经完成了作业,为了更好的理解过程(正如机器学习那门课一样)我们先来看梯度下降曲线

更改我们的学习率,当太大会出现折叠,太小下降缓慢

测试我们自己的其他图片

在需要写代码的前面我将提示任务目标

Logistic Regression with a Neural Network mindset

Welcome to your first (required) programming assignment! You will build a logistic regression classifier to recognize cats. This assignment will step you through how to do this with a Neural Network mindset, and so will also hone your intuitions about deep learning.

Instructions:

  • Do not use loops (for/while) in your code, unless the instructions explicitly ask you to do so.

You will learn to:

  • Build the general architecture of a learning algorithm, including:
    • Initializing parameters
    • Calculating the cost function and its gradient
    • Using an optimization algorithm (gradient descent)
  • Gather all three functions above into a main model function, in the right order.
 

Updates

This notebook has been updated over the past few months. The prior version was named "v5", and the current versionis now named '6a'

If you were working on a previous version:

  • You can find your prior work by looking in the file directory for the older files (named by version name).
  • To view the file directory, click on the "Coursera" icon in the top left corner of this notebook.
  • Please copy your work from the older versions to the new version, in order to submit your work for grading.

List of Updates

  • Forward propagation formula, indexing now starts at 1 instead of 0.
  • Optimization function comment now says "print cost every 100 training iterations" instead of "examples".
  • Fixed grammar in the comments.
  • Y_prediction_test variable name is used consistently.
  • Plot's axis label now says "iterations (hundred)" instead of "iterations".
  • When testing the model, the test image is normalized by dividing by 255.
 

1 - Packages

First, let's run the cell below to import all the packages that you will need during this assignment.

  • numpy is the fundamental package for scientific computing with Python.
  • h5py is a common package to interact with a dataset that is stored on an H5 file.
  • matplotlib is a famous library to plot graphs in Python.
  • PIL and scipy are used here to test your model with your own picture at the end.
import numpy as np
import matplotlib.pyplot as plt
import h5py
import scipy
from PIL import Image
from scipy import ndimage
from lr_utils import load_dataset

%matplotlib inline

2 - Overview of the Problem set

Problem Statement: You are given a dataset ("data.h5") containing:

- a training set of m_train images labeled as cat (y=1) or non-cat (y=0)
- a test set of m_test images labeled as cat or non-cat
- each image is of shape (num_px, num_px, 3) where 3 is for the 3 channels (RGB). Thus, each image is square (height = num_px) and (width = num_px).

You will build a simple image-recognition algorithm that can correctly classify pictures as cat or non-cat.

Let's get more familiar with the dataset. Load the data by running the following code.

# Loading the data (cat/non-cat)
train_set_x_orig, train_set_y, test_set_x_orig, test_set_y, classes = load_dataset()

We added "_orig" at the end of image datasets (train and test) because we are going to preprocess them. After preprocessing, we will end up with train_set_x and test_set_x (the labels train_set_y and test_set_y don't need any preprocessing).

Each line of your train_set_x_orig and test_set_x_orig is an array representing an image. You can visualize an example by running the following code. Feel free also to change the index value and re-run to see other images.

# Example of a picture
index = 25
plt.imshow(train_set_x_orig[index])
print ("y = " + str(train_set_y[:, index]) + ", it's a '" + classes[np.squeeze(train_set_y[:, index])].decode("utf-8") +  "' picture.")

Many software bugs in deep learning come from having matrix/vector dimensions that don't fit. If you can keep your matrix/vector dimensions straight you will go a long way toward eliminating many bugs.

### 回答1: 《Neural Networks and Deep Learning》这本书被许多人评价为是关于深度学习的一本非常好的入门书。它以清晰易懂的方式解释了深度学习的核心概念,并且使用大量的图片和代码来帮助读者理解。如果您对深度学习感兴趣,那么这本书是一个不错的选择。 ### 回答2: 《Neural Networks and Deep Learning》是一本非常出色的书籍。它由Michael Nielsen撰写,提供了关于神经网络和深度学习的详细而清晰的介绍。 这本书以易于理解和深入的方式解释了神经网络和深度学习的基本概念和原理。它从基础知识开始,逐步引导读者了解神经元、多层神经网络、反向传播和激活函数等关键概念。通过直观的解释和简单的数学推导,读者可以很好地理解这些复杂的概念。 书中还包含了许多实例和示例,帮助读者将理论应用到实际问题中。例如,它详细介绍了如何使用神经网络解决手写数字识别的问题,并提供了相关的代码实现。这些实例不仅使得理论更加易于理解,也为读者提供了实际操作的经验和技能。 此外,《Neural Networks and Deep Learning》还提供了大量的引用文献和进一步阅读的建议,帮助读者进一步深入学习和探索相关领域的研究。这为读者进一步拓宽知识领域提供了便利。 总体而言,这本书不仅适合对神经网络和深度学习感兴趣的初学者,也适合那些已经有一定了解但希望进一步加深理解的读者。它以简洁明了的方式传递了复杂的概念,提供了大量的实例和引用文献,是一本极具价值的学习资源。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值