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

相关推荐
Baihai_IDP30 分钟前
旗舰模型反而效率更低?解开 Gemini 4 Carbon 的耗时长之谜
人工智能·llm·gemini
always202239 分钟前
AI运行时 · 附录4 - KVCache 卸载与推理运行时:PagedAttention / PD 分离 / 分层缓存的显存经济学
人工智能·缓存
七夜zippoe43 分钟前
WorkBuddy 制作AI武侠短片实战:无 ffmpeg 的 OpenCV 拼接实战
人工智能·opencv·ai·ffmpeg·视频·workbuddy
智能汽车人1 小时前
自动驾驶---FSD v15 更新
人工智能·机器学习·自动驾驶
MyBili1 小时前
Chrome内置AI功能全攻略:Gemini侧边栏与端侧AI接口
人工智能·chrome·谷歌浏览器·隐私保护·ai助手·gemini·内置ai
Leo.yuan2 小时前
告别纯文本对话:2026支持可视化卡片交互的AI Agent平台横向选型
人工智能·交互
土豆12502 小时前
写公众号、拍短片:任务编排插件的两个能力包
人工智能·llm
Ceelog2 小时前
2026 年 Mac 磁盘清理工具怎么选:App Store 沙盒版、开源命令行和老牌软件对比
macos
mingo_敏2 小时前
TaCo:面向边缘设备的轻量化目标跟踪 | 把相关运算重新捡起来,速度精度双高
人工智能·计算机视觉·目标跟踪
AI创界者2 小时前
Python 进阶实战(第八十三章):基于 Redis Lua 脚本的分布式令牌桶限流、异步熔断器状态机与信号优雅关机实战
人工智能·python·aigc