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

相关推荐
愚公搬代码20 分钟前
【愚公系列】《微信小程序项目实战(AI编程+视频图解)》049-项目实战:使用 AI 编程工具辅助实现图书分类页面
人工智能·微信小程序·ai编程
遥感之家32 分钟前
Sat3D-Bench:550 对卫星影像—三维场景配对与 11 项指标,第一次系统评测单图三维城市生成
深度学习·遥感·基准测试·卫星影像·三维生成
yangmu320332 分钟前
AI 辅助生成运动控制测试用例:从底层逻辑到工程实战
人工智能·测试用例
一水鉴天34 分钟前
元宝聊天十一月以后语料的分套与汇编 20261204(豆包)
人工智能·架构
geneculture34 分钟前
道函数零点上的物意文对齐: 用融智学三观新论系统重梳古今中外真理观
人工智能·自然语言处理·融智时代(杂志)·序位逻辑·融智学报·三观新论·真理观
橙光成长35 分钟前
12 万 Star 的 browser-use:用 600 行 CDP 直连,把“让 AI 上网”从视觉猜测变成坐标点击
人工智能·开源·1024程序员节
得一录36 分钟前
DeepSeek Harness 解读 18 · 流式输出:从 StreamChunk 到 UI 增量
人工智能·架构
寻道模式42 分钟前
【开发心得】如何从零构建类 Codex 的 AI 智能体【3】
人工智能·codex·智能体
zc.z1 小时前
RAG (一):从底层原理、Naive RAG 到企业级项目开发与面试实战
人工智能·python·rag
夜雪轻寒1 小时前
AI 工具踩坑录:Prompt 我越写越长,模型反而越来越笨,删到第三版才明白它在装
java·开发语言·人工智能·语言模型·自然语言处理·prompt