当前位置:网站首页>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
边栏推荐
- Lombok的一些使用心得
- 智能合约安全——私有数据访问
- yolov3数据读入(二)
- lmxcms1.4
- sklearn中的pipeline机制
- RecyclerView的用法
- Delphi-C side interesting menu operation interface design
- Logistic Regression --- Introduction, API Introduction, Case: Cancer Classification Prediction, Classification Evaluation, and ROC Curve and AUC Metrics
- ISCC-2022
- 线性回归02---波士顿房价预测
猜你喜欢
随机推荐
flink sql left join数据倾斜问题解决
TensorFlow2 study notes: 5. Common activation functions
对象存储-分布式文件系统-MinIO-1:概念
npm install dependency error npm ERR! code ENOTFOUNDnpm ERR! syscall getaddrinfonpm ERR! errno ENOTFOUND
flink自定义轮询分区产生的问题
判断字符串是否有子字符串重复出现
fill_between in Matplotlib; np.argsort() function
Usage of RecyclerView
(十一)树--堆排序
Kubernetes基础入门(完整版)
剑指 Offer 20226/30
SQL练习 2022/7/4
自动化运维工具Ansible(1)基础
flink on yarn指定第三方jar包
NFT市场可二开开源系统
AIDL communication between two APPs
flink-sql大量使用案例
(TensorFlow)——tf.variable_scope和tf.name_scope详解
读研碎碎念
属性动画的用法 以及ButterKnife的用法