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

相关推荐
imbackneverdie32 分钟前
AI4S不止于分子药物:以MedPeer为代表的科研基建打开产业新增量
大数据·人工智能·算法·aigc·科研·学术·ai 4s
agent喵1 小时前
从知识库问答到业务自动化:AI Agent 工作流搭建经验分享
人工智能
周末程序猿1 小时前
图解 120 个大语言模型(LLM)核心概念(1-30)
人工智能
EQUINOX11 小时前
【论文阅读】| MoCo精读
论文阅读·人工智能·python·深度学习·机器学习
刘一说2 小时前
AI科技热点日报 | 2026年07月09日
人工智能·科技
LYFlied2 小时前
Anthropic Agent隔离架构解读:比权限弹窗更可靠的是限制爆炸半径
人工智能·架构·软件工程·claude·安全架构·ai agent
敲代码的嘎仔2 小时前
实习日志day6--实习日志day6--title命名规范化&businessType纠正&补充缺失的@Log注解&报警与通信模块补充&产出阶段总结文档
java·开发语言·人工智能·git·python·实习·大二
ZZZMMM.zip2 小时前
基于鸿蒙HarmonyOS NEXT开发AI英语口语应用:智能口语练习新体验与鸿蒙Flutter框架跨端实
人工智能·flutter·华为·harmonyos·鸿蒙·鸿蒙系统
程序喵大人2 小时前
【AI专栏】图解Transformer - 第05章:LLM 推理工程
人工智能·深度学习·llm·transformer
甲维斯2 小时前
差距太大了!GPT5.6Sol 正面战 Fable5,啥也不是!
人工智能·ai编程