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

相关推荐
火山引擎开发者社区10 小时前
火山AgentPlan/CodingPlan同步上线GLM-5.2
人工智能
冬奇Lab11 小时前
Skill 系列(05):Skill 工作流串联——4 种模式实测,并发加速 1.5x
人工智能·开源
冬奇Lab11 小时前
每日一个开源项目(第141篇):hiring-agent - HackerRank 开源了他们的简历评分系统,你的简历能得几分?
人工智能·面试·开源
甲维斯11 小时前
又升级咯!坦克大战2026,科技与复古并存!
前端·人工智能·游戏开发
姗姗来迟了13 小时前
用React Hook封装AI对话状态
人工智能
Goodbye14 小时前
从 Token 到 Embedding:LLM 核心基础深度解析
javascript·人工智能
阿瑞IT14 小时前
AI Agent 在甘特计划变更场景中的动态响应工程实践
人工智能
用户9385156350714 小时前
工具调用背后:LLM 如何突破“缸中大脑”,操控真实世界?
javascript·人工智能