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

相关推荐
七牛开发者4 小时前
从 GLM 到 GPT,HarnessPro 如何用 RSI 降低 Agent 成本
人工智能·gpt·agent·harness·rsi
跨境卫士-小汪5 小时前
TikTokShop欧洲商品接口架构调整跨境技术团队需要做好哪些准备
大数据·人工智能·新媒体运营·跨境电商·跨境·营销策略
康小汪6 小时前
AI 写 Vue 总写成同一个味道:给它装 Skills,装的不是知识是边界
前端·vue.js·人工智能·ai编程·最佳实践
收放扳机6 小时前
多机连线(In-Line)场景下,收放板机“缓存工位”的容量与架构选型参考
人工智能·科技·自动化·制造·pcb工艺
武天旭6 小时前
AI安全--AI大模型的后门攻击检测与防御
人工智能·深度学习·安全·机器学习
智能运维指南6 小时前
研制过程“两张皮“怎么破:研制一体化支撑平台的定位、能力边界与落地前提
java·前端·人工智能·嘉为蓝鲸
人工智能AI技术6 小时前
DeepInfer开源炸场!别再妄想个人电脑跑满血DeepSeek
人工智能
深蓝电商API6 小时前
用AI生成拟人行为:让鼠标轨迹更“有人味”
人工智能·爬虫
znnnk7 小时前
数据库被AI“重写”:2026,从CPU中心走向GPU中心
数据库·人工智能·oracle
深蓝AI7 小时前
网站正在对 AI Agent 集体关门:亚马逊封锁 Muse、银行拒绝登录,开发者怎么活下去
人工智能