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

相关推荐
dozenyaoyida几秒前
AI与大模型新闻日报 | 2026-09-09
人工智能·ai·chatgpt·大模型·新闻
xqqxqxxq16 分钟前
AI Agent学习:主动工具发现(李博杰《深入理解 AI Agent》4.8观后总结)
人工智能·学习
海上彼尚40 分钟前
Cursor 模型的强度实测排行
前端·人工智能·后端
ai小陈43 分钟前
PyTorch Profiler性能分析实战:定位GPU训练中的慢算子
人工智能·深度学习·机器学习·ai·性能优化·gpu算力
罗西的思考1 小时前
[Agent Memory / 强化学习] MemPO源码学习笔记 ---(1)--- 总体
人工智能·算法·机器学习
冬奇Lab1 小时前
DeepSeek Harness 系列(02):万物皆插件——Cordis 核心设计深度解读
人工智能·deepseek
老金带你玩AI1 小时前
image 2.5刷屏了:有人拿它做广告,有人已经做出了动画
人工智能
FII工业富联科技服务1 小时前
GPT-6 Astra发布,Agent的竞争开始从“会调用工具”走向“完成完整工作”
大数据·人工智能·gpt·架构·机器人·制造
Mr数据杨1 小时前
议会事务多标签文本分类实战 从 Open Data St Gallen 看推荐排序建模
人工智能·数据分析·kaggle竞赛
梦想的颜色1 小时前
【AI速览】2026年 9月 GPT‑6 Astra 深度解析:Agent 时代的前沿旗舰,能力、成本、落地痛点与选型判断
人工智能·openai·agent·astra·vibecoding·大模型测评·gpt6