A New Programming Paradigm

参考:Ubuntu 16 安装TensorFlow及Jupyter notebook 安装TensorFlow。

本篇博客翻译来自 Introduction to TensorFlow for Artificial Intelligence, Machine Learning, and Deep Learning

仅供学习、交流等非盈利性质使用!!!

其他相关文章
Coursera TensorFlow 基础课程-week4
Coursera TensorFlow 基础课程-week3
Coursera TensorFlow 基础课程-week2
Coursera TensorFlow 基础课程-week1

文章目录

  • A New Programming Paradigm
    • 1. 神经网络的“Hello World”
    • 2. Quiz:
    • 3. Excise

1. 神经网络的“Hello World”

给定如下的一组数字,如何拟合?

X = -1, 0 ,1 ,2 , 3, 4
Y = -3, -1,1 ,3 , 5, 7

如果用神经网络的方式该如何解决?

神经网络的解决方案是这样子的:

① 抽选一个拟合函数来对所有数据进行拟合;

② 使用损失函数来判读这次拟合的好坏;

③ 同时使用优化器来修改拟合函数,再次拟合;

④ 重复上面的步骤到指定次数,或收敛。

上面步骤的具体代码过程如下:

  1. 定义模型
model = keras.Sequential([keras.layers.Dense(units=1,input_shape=[1])])
  • keras.layers.Dense :定义一层神经网络;
  • units: 这层神经网络中神经元的个数,如上面代码中,只有一个神经元;
  • input_shape:说明输入的数据的维度;
  • keras.Sequential : 定义一个线性模型;
  1. 定义损失函数
model.compile(optimizer='sgd', loss='mean_squared_error')

损失函数就是指的是这次拟合的效果好坏,比如应用这次拟合后,预测值和真实值一点也不差,那么就说明拟合比较好。

  1. 设置输入、输出
xs = np.array([-1, 0 ,1 ,2 , 3, 4] , dtype = float)
ys = np.array([-3, -1,1 ,3 , 5, 7] , dtype = float)
  1. 拟合参数
model.fit(xs, ys, epochs = 500)

调用模型的fit函数即可来拟合模型的参数,而epochs则指的是拟合多少次。设置500次后,进行拟合,可以得到下面的结果:

Epoch 1/500
6/6 [==============================] - 1s 101ms/sample - loss: 60.8370
Epoch 2/500
6/6 [==============================] - 0s 501us/sample - loss: 48.2978
...
Epoch 499/500
6/6 [==============================] - 0s 451us/sample - loss: 7.3124e-05
Epoch 500/500
6/6 [==============================] - 0s 518us/sample - loss: 7.1621e-05

可以看到,最后拟合误差已经非常接近 0 了。

  1. 预测新数据:
print(model.predict([10.0]))
[[18.97531]]

从预测结果来看结果非常接近19(如果用2x-1 = y 来拟合的话,结果就是19)。

所以结果不是19的理由是:

  • 训练数据非常少,仅有6组数据;
  • 10的预测结果有很大可能是19,但是神经网络并不能够确定,所以这里给出了一个概率值。

code download: link1 或 link2

拓展: From rules to data

说的就是:之前的给定一个规则和输入数据,然后就可以推测出新的数据的结果。而现在是给定输入输出数据,然后让神经网络模型训练,训练后,给新的输入即可得到输出,这就是和之前的不同。

2. Quiz:

  1. 第 1 个问题
    The diagram for traditional programming had Rules and Data In, but what came out?
  • Binary
  • Machine Learning
  • Bugs
  • Answers
  1. 第 2 个问题
    The diagram for Machine Learning had Answers and Data In, but what came out?
  • Rules
  • Models
  • Binary
  • Bugs
  1. 第 3 个问题
    When I tell a computer what the data represents (i.e. this data is for walking, this data is for running), what is that process called?
  • Labelling the Data
  • Categorizing the Data
  • Programming the Data
  • Learning the Data
  1. 第 4 个问题
    What is a Dense?
  • A layer of disconnected neurons
  • Mass over Volume
  • A single neuron
  • A layer of connected neurons
  1. 第 5 个问题
    What does a Loss function do?
  • Figures out if you win or lose
  • Generates a guess
  • Decides to stop training a neural network
  • Measures how good the current ‘guess’ is
  1. 第 6 个问题
    What does the optimizer do?
  • Generates a new and improved guess
  • Measures how good the current guess is
  • Decides to stop training a neural network
  • Figures out how to efficiently compile your code
  1. 第 7 个问题
    What is Convergence?
  • The process of getting very close to the correct answer
  • A programming API for AI
  • A dramatic increase in loss
  • The bad guys in the next ‘Star Wars’ movie
  1. 第 8 个问题
    What does model.fit do?
  • It makes a model fit available memory
  • It optimizes an existing model
  • It trains the neural network to fit one set of values to another
  • It determines if your activity is good for your body
My guess:
1. D
2. A
3. D
4. D
5. D
6. A
7. A
8. C

3. Excise

房屋价格预测:一般来说,一个房子需要花费50k+50k,通常50K是底价,然后每加1间房,增加50K,所以1间房一般花费100k,2间房花费150k,以此类推。
那么如果7间房,耗费多少呢?接近400K么?
Hints:100K可以只使用1来代替。

import tensorflow as tf
import numpy as np
from tensorflow import keras
model = # Your Code Here#
model.compile(# Your Code Here#)
xs = # Your Code Here#
ys = # Your Code Here#
model.fit(# Your Code here#)
print(model.predict([7.0]))

The Answers: excise answer.

Coursera TensorFlow 基础课程-week1相关推荐

  1. Coursera TensorFlow 基础课程-week3

    Enhancing Vision with Convolutional Neural Networks 参考:Ubuntu 16 安装TensorFlow及Jupyter notebook 安装Ten ...

  2. Coursera TensorFlow 基础课程-week4

    Using Real-world Images 参考:Ubuntu 16 安装TensorFlow及Jupyter notebook 安装TensorFlow. 本篇博客翻译来自 Introducti ...

  3. 资源 | Intel发布AI免费系列课程3部曲:机器学习基础、深度学习基础以及TensorFlow基础

    翻译 | AI科技大本营(公众号ID:rgznai100) 校对 | 成龙 编辑 | 明明 Intel于近期发布了三门AI系列的免费课程,分别是关于机器学习基础.深度学习基础.TensorFlow基础 ...

  4. 【神经网络与深度学习-TensorFlow实践】-中国大学MOOC课程(八)(TensorFlow基础))

    [神经网络与深度学习-TensorFlow实践]-中国大学MOOC课程(八)(TensorFlow基础)) 8 TensorFlow基础 8.1 TensorFlow2.0特性 8.1.1 Tenso ...

  5. 吴恩达Coursera深度学习课程 deeplearning.ai (4-4) 神经风格转换--编程作业

    吴恩达Coursera深度学习课程 deeplearning.ai (4-4) 神经风格转换–编程作业 注:由于这个作业目前未找到完整的中文版的,所以楼主综合了几篇不完整的,自己完整运行了一遍(pyt ...

  6. 【完结】有三AI阿里云的深度学习基础课程暂时完结,欢迎扩散学习

    2021年3月份有三AI与阿里天池联合推出了深度学习系列课程, 课程内容包括人工智能与深度学习发展背景,深度学习典型应用,卷积神经网络,循环神经网络,生成对抗网络,深度学习开源框架等内容,目前已经基本 ...

  7. 深度学习(6)TensorFlow基础操作二: 创建Tensor

    深度学习(6)TensorFlow基础操作二: 创建Tensor 一. 创建方式 1. From Numpy,List 2. zeros,ones (1) tf.zeros() (2) tf.zero ...

  8. NLP Coursera By Michael Collins - Week1

    转载自   NLP Coursera By Michael Collins - Week1 NLP Coursera By Michael Collins - Week1 构建模型框架 - Marko ...

  9. Coursera自动驾驶课程第16讲:LIDAR Sensing

    在第15讲<Coursera自动驾驶课程第15讲:GNSS and INS Sensing for Pose Estimation> 我们学习了自动驾驶定位中常用的两种传感器:IMU(惯性 ...

最新文章

  1. Android自定义控件属性的使用
  2. ARM嵌入式开发之JTAG与SWD接口
  3. Ardino基础教程 21_最简单最快控制LCD1602
  4. eclipse 64位_第3天 | 12天搞定Python,用Eclipse编写代码
  5. QTP中对用户自定义环境变量的XML操作的几个函数
  6. java date 时分秒_java Date 获得时分秒代码
  7. qt 线程接收线程 moveToThread 特性
  8. JavaScript模块化开发(一)基础知识
  9. HikariCP 的使用
  10. 解决WIN10本地账号绑定微软账号后无法解绑的方法
  11. JS引擎V8的内存回收机制与内存限制(标记清除法)
  12. 阿里巴巴产品实习生4天
  13. B. Alyona and a Narrow Fridge 【 思维题 】
  14. java内存模型之先行发生原则
  15. 2023中科院沈阳计算所初试401分经验贴
  16. 北京大学计算机系张润楠,耀华吧:物理竞赛之”我爸是李刚“
  17. U盘无法格式化的解决办法
  18. 生成二维码或条形码JavaScript脚本库
  19. 计算机毕业设计 SSM+MySQL毕业设计 疫情期间医院门诊管理系统
  20. 在Makefile中无缝连接字符串

热门文章

  1. 联通光纤猫入户升级:千兆光纤宽带的网卡,为什么只显示100M?
  2. MicroSoft Visual Studio 2013 社区版下载地址
  3. 操作系统:进程同步演示
  4. 想从事人工智能方面,需要自学什么?
  5. 深度盘点:Python 变量类型转换的 6 种方法
  6. vue element-ui elementUi 邮箱自动补全 邮箱自动填充
  7. 纳米表征技术 2022.10.5
  8. assert()详解
  9. vue项目获取下拉框选中id_vue获取下拉框值
  10. android——利用gradle实现多渠道打包并自定义包名(umeng多渠道)