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

相关推荐
dozenyaoyida13 分钟前
AI与大模型新闻日报 | 2026-11-08
人工智能·搜索引擎·ai·大模型·新闻
泯泷22 分钟前
AI Agent 工具设计:读完一百页 PDF,不等于真的看懂了
人工智能·llm·agent
泯泷3 小时前
AI 怎样"查资料"?——RAG 检索增强生成入门(三)
人工智能·llm
Solange__3 小时前
Blender 3D模型优化:普通复制、共享网格、实例、合并怎么选?
人工智能·3d·ai·自然语言处理·编辑器·blender·材质
师夷长技以自愈3 小时前
手搓 AI Agent 第 8 篇:从手写循环到画流程图——LangGraph 封装
人工智能·python
数据治理自习室3 小时前
2026最新:MCP开发与使用指南
人工智能
小小疯狐狸3 小时前
我踩过的Agent harness几个坑:上下文越跑越慢
人工智能
kaixin_啊啊4 小时前
【零基础学AI】第 30 章——对话记录与结构化输出
人工智能
泯泷4 小时前
让知识"长骨架"——RAPTOR、GraphRAG 与 OpenViking(四)
人工智能·llm
kaixin_啊啊5 小时前
【零基础学AI】第 30 章课后练习与答案
人工智能