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

相关推荐
AI-小柒4 分钟前
Seedance 2.0(即梦 2.0)深度解析:AI 视频进入「导演级」可控时代
大数据·人工智能·网络协议·tcp/ip·http·音视频
ZhengEnCi7 分钟前
07. 向量数据库构建与优化
人工智能
lynn-fish14 分钟前
标讯 “加速度”:AI 如何重构电力招投标的决策与效率
人工智能·ai·电网·电力·招投标·标讯
TImCheng060914 分钟前
落地实施方案:为销售团队引入AI工具的四阶段(选型-试点-培训-复盘)攻略
大数据·人工智能
进击monkey16 分钟前
告别Confluence卡顿和权限迷宫:PandaWiki三个月实操体验
人工智能
仙女修炼史25 分钟前
Making Convolutional Networks Shift-Invariant Again
人工智能·深度学习·计算机视觉
EasyGBS27 分钟前
从“联网互通”到“安全可信”:EasyGBS支持GB35114国密协议,覆盖全场景安防合规升级
大数据·人工智能·安全·gb28181·gb35114
程序员Linc31 分钟前
小智esp32小玩意2:了解面包板与小智最基本AI对话电路连接
人工智能
奔跑草-31 分钟前
【AI日报】每日AI最新消息2026-02-24
人工智能