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

相关推荐
2501_93029699几秒前
模型驱动创作全链路梳理:2026上半年图像与视频生成AI模型全景盘点
人工智能·音视频
qzhqbb4 分钟前
Agent 系统架构与核心技术要点
人工智能·系统架构
love530love14 分钟前
用自然语言让 AI Agent 卸载软件 —— 以卸载 Visual Studio 2026 为例
ide·人工智能·windows·agent·visual studio·ai agent·marvis
猿类生物17 分钟前
从 Prompt Engineering 到 Loop Engineering:AI 编码的下一个边界
人工智能·ai编程
Codebee24 分钟前
万字长文解析企业级Super Agent工程方案
人工智能
wenzhangli724 分钟前
oodAgent 4.0 Skills分布式调度 — 从Code Agent实战看自主维护的Agent网络
运维·网络·人工智能·自动化
接着奏乐接着舞。30 分钟前
【2026年7月最新】69道RAG面试题
前端·人工智能·后端·aigc·embedding·rag
以和为贵31 分钟前
前端也能搞懂 Agent:从 Function Calling 到自主编排
前端·人工智能·架构
断眉的派大星33 分钟前
YOLO实例分割详细解析
人工智能·yolo·计算机视觉
DogDaoDao42 分钟前
LLM:用一条命令统一所有大语言模型的 CLI 工具
人工智能·语言模型·自然语言处理·llm·github