机器学习16:使用 TensorFlow 进行神经网络编程练习

在【机器学习15】中,笔者介绍了神经网络的基本原理。在本篇中,我们使用 TensorFlow 来训练、验证神经网络模型,并探索不同 “层数+节点数” 对模型预测效果的影响,以便读者对神经网络模型有一个更加直观的认识。

目录

1.导入依赖模块

2.加载数据集

3.表示数据

4.构建线性回归模型-作为基线

4.1 定义损失打印函数

4.2 定义函数以创建和训练线性回归模型

4.3 定义线性回归模型输出

4.4 调用函数训练、测试模型

4.5 完整代码运行

5.深度神经网络模型

5.1 定义深度神经网络(DNN)模型

5.2 调用函数来构建和训练深度神经网络

5.3 优化深度神经网络的拓扑结构

5.3.1 实验一:增加层数

5.3.2 实验一:减少节点数

6.两种模型结果对比

7.参考文献


1.导入依赖模块

相较于前面的系列文章,需要新增一个模块 seaborn。可以通过 PyCharm 的图形化工具安装,也可以通过命令“pip3 install --index-url https://mirrors.aliyun.com/pypi/simple/ seaborn” 直接安装。

import numpy as np
import pandas as pd
import tensorflow as tf
from matplotlib import pyplot as plt
import seaborn as sns

# The following lines adjust the granularity of reporting.
pd.options.display.max_rows = 10
pd.options.display.float_format = "{:.1f}".format

2.加载数据集

本案例中采用的数据集原始地址为如下:

  • 训练数据:https://download.mlcc.google.com/mledu-datasets/california_housing_train.csv
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Programming Exercise 1: Linear Regression Machine Learning Introduction In this exercise, you will implement linear regression and get to see it work on data. Before starting on this programming exercise, we strongly recom- mend watching the video lectures and completing the review questions for the associated topics. To get started with the exercise, you will need to download the starter code and unzip its contents to the directory where you wish to complete the exercise. If needed, use the cd command in Octave/MATLAB to change to this directory before starting this exercise. You can also find instructions for installing Octave/MATLAB in the “En- vironment Setup Instructions” of the course website. Files included in this exercise ex1.m - Octave/MATLAB script that steps you through the exercise ex1 multi.m - Octave/MATLAB script for the later parts of the exercise ex1data1.txt - Dataset for linear regression with one variable ex1data2.txt - Dataset for linear regression with multiple variables submit.m - Submission script that sends your solutions to our servers [?] warmUpExercise.m - Simple example function in Octave/MATLAB [?] plotData.m - Function to display the dataset [?] computeCost.m - Function to compute the cost of linear regression [?] gradientDescent.m - Function to run gradient descent [†] computeCostMulti.m - Cost function for multiple variables [†] gradientDescentMulti.m - Gradient descent for multiple variables [†] featureNormalize.m - Function to normalize features [†] normalEqn.m - Function to compute the normal equations ? indicates files you will need to complete † indicates optional exercises

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jin_Kwok

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值