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技术8 分钟前
PAI 模型蒸馏全新发布「场景化蒸馏」:把最佳实践装进模板,让大模型能力"轻装上阵"
人工智能
亚川楼宇自控系统数据中心厂家13 分钟前
机房 3D 可视化技术:从平面监控到立体化管理的升级
大数据·数据库·人工智能
LaughingZhu14 分钟前
任务在飞书创建,开发在 Orca 继续:我把飞书项目接到了 Linear
大数据·人工智能·深度学习·神经网络·飞书
一水鉴天28 分钟前
UML/MOF 元层级与 Model & Notation:整体设计核心术语的定稿探讨 20261012(豆包“查看聊天内容”继续)
人工智能·机器学习
陈嘿萌32 分钟前
TIP 2026|没有分割标签,也能做任务导向图像融合:SSVIF的自监督语义注入
图像处理·人工智能·深度学习·计算机视觉·图像融合·学术研究与理论基础
森山冶仁33 分钟前
把专家抽检变成分钟级全量初审:科学数据审核智能体的召回率与证据链怎么设计
人工智能·数据治理·数据质量·元数据
空 白II34 分钟前
10.12 大语言模型研究简报:美国恢复英国对前沿AI模型的预发布安全测试合作
人工智能·语言模型·自然语言处理
xier_ran43 分钟前
【infra之路】AI 编译器学习笔记(四):PatternRewriter 与贪心 driver
人工智能·笔记·学习
智享 AI 科技44 分钟前
2026年AI私域系统怎么选?从功能到服务的全维度对比
大数据·人工智能·经验分享
镜象科技1 小时前
AI心理健康解决方案服务商行业趋势:镜象科技如何引领校园心理健康数字化升级
人工智能·科技