当前位置:网站首页>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
边栏推荐
猜你喜欢

Matplotlib中的fill_between;np.argsort()函数

Install dlib step pit record, error: WARNING: pip is configured with locations that require TLS/SSL

(九)哈希表

with recursive用法

ISCC2021——web部分

Vulnhub:Sar-1

ISCC-2022

Jupyter Notebook installed library;ModuleNotFoundError: No module named 'plotly' solution.

SQL的性能分析、优化
![[Introduction to go language] 12. Pointer](/img/c8/4489993e66f1ef383ce49c95d78b1f.png)
[Introduction to go language] 12. Pointer
随机推荐
属性动画的用法 以及ButterKnife的用法
k9s-终端UI工具
Kubernetes基本入门-名称空间资源(三)
IvNWJVPMLt
postgresql 事务隔离级别与锁
SQL练习 2022/7/1
CAS与自旋锁、ABA问题
二月、三月校招面试复盘总结(二)
Shell(3)条件控制语句
自动化运维工具Ansible(3)PlayBook
postgresql中创建新用户等各种命令
【go语言入门笔记】12、指针
Thread 、Handler和IntentService的用法
lmxcms1.4
Simple and clear, the three paradigms of database design
8.30难题留坑:计数器问题和素数等差数列问题
剑指 Offer 2022/7/4
彻底搞懂箱形图分析
(九)哈希表
【CV-Learning】卷积神经网络