python深度学习读书笔记(一)

一 从数据中学习表示

机器学习的要素
  • 输入数据点
  • 预期输出的示例
  • 衡量算法效果好坏的方法

机器学习和深度学习的核心问题在于有意义的变换数据,换句话说在于学习输入数据的有用表示

学习指的是寻找更好数据表示的自动搜索过程
在这里插入图片描述

二 深度学习的工作原理

深度学习:学习数据表示的多级方法

1 深度学习的目标:寻找权重参数

在这里插入图片描述

2 深度学习的衡量标准 损失函数

在这里插入图片描述

3 深度学习的核心算法 反向传播算法

在这里插入图片描述

三 深度学习的hello word 手写数字识别

1 加载keras中的MNINST 数据集

from keras.datasets import mnist
#加载keras中的MNIST数据集
(train_images,train_lables),(test_images,test_lables) = mnist.load_data()

2 网络架构

from keras import models
from keras import layers
#网络架构
network = models.Sequential()
network.add(layers.Dense(512,activation='relu',input_shape=(28*28,)))
network.add(layers.Dense(10,activation='softmax'))

3 编译步骤

三个参数

  • 损失函数(loss function): 网络如何衡量在训练数据上的性能,即网络如何朝着正确的方向前进
  • 优化器(optimizer):基于训练数据和损失函数来更新网络机制
  • 在训练和测试过程需要监控的指标(metric):精度 正确分类图像占的比例
#编译
network.compile(optimizer='rmsprop',
                loss='categorical_crossentropy',
                metrics=['accuracy'])

4 准备图像数据

对数据进行预处理,将其变换程网络要求的形状,并缩放到所有值都在0-1

#准备图像数据
train_images = train_images.reshape((60000,28*28))
train_images = train_images.astype('float32')/255

test_images = test_images.reshape((10000,28*28))
test_images = test_images.astype('float32')/255

5 准备标签

#准备标签
from keras.utils import to_categorical
train_lables = to_categorical(train_lables)
test_lables = to_categorical(test_lables)

6 训练和测试

训练是通过调用网络的fit方法来完成的 在训练数据上拟合(fit)模型

训练过程中显示两个数字:一个是网络在训练数据上的损失(loss),一个是网络在训练数据上的精度(acc)

# 训练过程
network.fit(train_images,train_lables,epochs=5,batch_size=128)
print("===================")
# 测试过程
test_loss,test_acc =network.evaluate(test_images,test_lables)
print("test_acc",test_acc)
发布了67 篇原创文章 · 获赞 0 · 访问量 1227

猜你喜欢

转载自blog.csdn.net/qq_32719221/article/details/103984199