当前位置:网站首页>TensorFlow2 study notes: 8. tf.keras implements linear regression, Income dataset: years of education and income dataset
TensorFlow2 study notes: 8. tf.keras implements linear regression, Income dataset: years of education and income dataset
2022-08-04 06:05:00 【Live up to [email protected]】
1、Income数据集
IncomeThe dataset is machine learning、Typical learning data for linear regression in a deep learning experiment:下载Income数据集
It mainly has two types of data,受教育年限和对应的收入情况
It can be observed by the scatter plot,apparently linear relationship
数据预览:
散点图:
2、创建模型
2.1导入数据、定义特征和标签
import tensorflow as tf
import pandas as pd
import matplotlib.pyplot as plt
data=pd.read_csv("./Income.csv")
# Define input featuresx 和对应标签y
x=data.Education
y=data.Income
2.2创建模型
#顺序模型:只有一个输入和一个输出.tf.keras.Sequential()is a sequential model
model=tf.keras.Sequential() #初始化模型
model.add(tf.keras.layers.Dense(1,input_shape=(1,))) #添加层
model.compile(optimizer='adam',loss='mse') # Configure training items mse均方差 梯度优化Adam
通过:model.summary()function to look at the model
3、训练模型
model.fit(x,y,epochs=500)
#x y Feed the data features and labels defined above epochsis the number of training iterations
训练结果:
4、完整代码
import tensorflow as tf
import pandas as pd
import matplotlib.pyplot as plt
data=pd.read_csv("./Income.csv")
x=data.Education
y=data.Income
model=tf.keras.Sequential()
model.add(tf.keras.layers.Dense(1,input_shape=(1,)))
model.summary()
model.compile(optimizer='adam',loss='mse')
h=model.fit(x,y,epochs=500)
版权声明
本文为[Live up to [email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/216/202208040525327517.html
边栏推荐
猜你喜欢

MySql的concat和group_concat的区别

安装dlib踩坑记录,报错:WARNING: pip is configured with locations that require TLS/SSL

AIDL communication between two APPs

Delphi-C side interesting menu operation interface design

CTFshow—Web入门—信息(9-20)

TensorFlow2学习笔记:6、过拟合和欠拟合,及其缓解方案

判断字符串是否有子字符串重复出现

【CV-Learning】卷积神经网络预备知识

Kubernetes集群安装

对象存储-分布式文件系统-MinIO-1:概念
随机推荐
攻防世界MISC—MISCall
Th in thymeleaf: href use notes
8.30难题留坑:计数器问题和素数等差数列问题
Learning curve learning_curve function in sklearn
flink-sql所有语法详解
【深度学习21天学习挑战赛】0、搭建学习环境
(十六)图的基本操作---两种遍历
The pipeline mechanism in sklearn
flink-sql查询配置与性能优化参数详解
智能合约安全——delegatecall (1)
Kubernetes集群安装
ISCC2021———MISC部分复现(练武)
简单说Q-Q图;stats.probplot(QQ图)
(十五)B-Tree树(B-树)与B+树
剑指 Offer 2022/7/4
【深度学习21天学习挑战赛】备忘篇:我们的神经网模型到底长啥样?——model.summary()详解
二月、三月校招面试复盘总结(二)
TensorFlow2 study notes: 5. Common activation functions
安装dlib踩坑记录,报错:WARNING: pip is configured with locations that require TLS/SSL
Delphi-C side interesting menu operation interface design