Deep Learning(3)

Linear Units in Keras

The easiest way to create a model in Keras is through 'keras.Sequential', which creates a stack of layers from a neural network. Of course, we can also use a dense layer to create the model.

We can define a linear model that takes three input features ('sugars', 'fiber', and 'protein') and then generate a simgle output ('calories') like this:

python 复制代码
from tensorflow import keras
from tensorflow.keras import layers

# Create a network with 1 linear unit
model = keras.Sequential([
    layers.Dense(units=1, input_shape=[3])
])

With the first parameter, 'units' , we define how many outputs we want. In this case, we're just predicting 'calories', so we'll use 'units = 1'.

With the second parameter, 'input_shape', we tell Keras the dimension of the inputs. Setting 'input_shape=3' ensures that the model will accept three features as input ('sugars', 'fiber', and 'protein').

This model is now ready to be fit to training data

相关推荐
Python大数据分析@2 分钟前
为什么codex和chatgpt合并?
人工智能
SEO_juper8 分钟前
实体SEO:从关键词到实体的2026搜索引擎与AI引用实战指南
人工智能·搜索引擎·seo·独立站·谷歌优化
集思广益的灰太狼9 分钟前
变频器启动致PLC数据异常?西门子G120配合滤波器EMC抑制方案
人工智能·算法·工控·emc·电磁兼容·变频器·西门子
luckystar513~14 分钟前
自己动手编写skills:我让AI使用git更规范、合理
人工智能
AI备案指南-满满15 分钟前
数字虚拟人也开始备案了:AI虚拟人“生成式AI备案 + 算法备案“双重合规全解析
大数据·人工智能·机器人·生成式人工智能·算法备案
用户2986985301418 分钟前
PDF 转纯文本(TXT)免费攻略:轻松提取文字内容
人工智能·后端·c#
深频率18 分钟前
AI吃电更吃铜:高端铜箔需求一年增260%
人工智能
charles_he19 分钟前
Agent 写操作超时后,最危险的动作是“再试一次”
人工智能·架构·agent
Sky1987star19 分钟前
Sales Agent OS 为什么必须保留人工接管与结果回写?
大数据·人工智能
茉莉玫瑰花茶20 分钟前
知识库的构建 [ 4 ]
人工智能·机器学习