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

相关推荐
JXSJHF10 分钟前
告别云端依赖:2026年AI PC如何实现离线运行百亿参数模型
人工智能
财迅通Ai13 分钟前
海立股份子公司参展AWE2026 以创新科技赋能行业转型升级
大数据·人工智能·物联网
SuAluvfy13 分钟前
AI 编辑器:Cursor vs Trae
人工智能·编辑器
UWA14 分钟前
顺势而为,AI 技术融入性能优化
人工智能·ai·性能优化·游戏开发
HowDonew14 分钟前
PyTorch 目标检测:为何训练 Loss 极低,一开 model.eval() 测试就瞬间爆炸?
人工智能·pytorch·目标检测
SelectDB技术团队14 分钟前
OLAP 无需事务?Apache Doris 如何让实时分析兼具事务保障
数据库·数据仓库·人工智能·云原生·实时分析
浩哥依然14 分钟前
【论文笔记之 ULCNET】Ultra Low Complexity Deep Learning Based Noise Suppression
论文阅读·深度学习·神经网络·语音增强·语音降噪小模型
用户48159301959116 分钟前
文件即真理:深度解析 OpenClaw 的 Markdown 记忆系统
人工智能
renhongxia116 分钟前
人工智能代理能生成微服务吗?我们离多远了?
人工智能·深度学习·学习·微服务·云原生·架构·机器人
liliangcsdn18 分钟前
Mac环境OpenClaw龙虾的初步测试和验证
人工智能·macos