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

相关推荐
minhuan30 分钟前
大模型应用:AI智能体高并发实战:Redis缓存+负载均衡协同解决推理超时难题.133
人工智能·redis·智能体推理缓存·智能体负载均衡·大模型集群应用
圣殿骑士-Khtangc1 小时前
Windsurf AI IDE 超详细使用教程:从安装到实战,一站式上手
人工智能·ai编程·编程助手·windsurf
weixin_505154466 小时前
打破传统界限:Bowell Studio引领3D作业指导新纪元
人工智能·3d·制造·数据安全·数字孪生·数据可视化
ModelHub XC信创模盒8 小时前
中国信创AI生态下 “信创模盒”社区战略招募种子用户
人工智能·大模型·开发者·信创·算力
袋鼠云数栈9 小时前
集团数字化统战实战:统一数据门户与全业态监管体系构建
大数据·数据结构·人工智能·多模态
廋到被风吹走9 小时前
【AI】Codex 多语言实测:Python/Java/JS/SQL 效果横评
java·人工智能·python
cskywit9 小时前
【IEEE TNNLS 2025】赋予大模型“跨院行医”的能力:基于全局与局部提示的医学图像泛化框架 (GLP) 解析
人工智能
2501_948114249 小时前
AI API Gateway 选型指南:2026 年生产环境下的聚合平台深度对比
人工智能·gateway
实在智能RPA9 小时前
Agent 在物流行业能实现哪些自动化?——深度拆解 AI Agent 驱动的智慧物流新范式
运维·人工智能·ai·自动化
TechubNews9 小时前
Jack Dorsey:告别传统公司层级,借助 AI 走向智能体架构
大数据·人工智能