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

相关推荐
小程故事多_805 小时前
OpenClaw工具引擎架构全解析,AI Agent的“双手”如何落地实操
人工智能·架构·aigc·ai编程·openclaw
qq_452396235 小时前
【AI 架构师】第十篇:Agent 工业化部署 —— 从 FastAPI 到云端全链路监控
网络·人工智能·ai·fastapi
前端摸鱼匠5 小时前
【AI大模型春招面试题11】什么是模型的“涌现能力”(Emergent Ability)?出现条件是什么?
人工智能·算法·ai·自然语言处理·面试·职场和发展
新缸中之脑5 小时前
如何合法地逆向SynthID
人工智能
剑穗挂着新流苏3126 小时前
115_PyTorch 实战:从零搭建 CIFAR-10 完整训练与测试流水线
人工智能·pytorch·深度学习·神经网络
Veggie266 小时前
【Java深度学习】PyTorch On Java 系列课程 第八章 17 :模型评估【AI Infra 3.0】[PyTorch Java 硕士研一课程]
java·人工智能·深度学习
链上杯子7 小时前
《2026 LangChain零基础入门:用AI应用框架快速搭建智能助手》第8课(完结篇):小项目实战 + 部署 —— 构建网页版个人知识库 AI 助手
人工智能·langchain
东方不败之鸭梨的测试笔记7 小时前
AI生成测试用例方案
人工智能·测试用例
笨手笨脚の8 小时前
AI 基础概念
人工智能·大模型·prompt·agent·tool
飞睿科技8 小时前
解析 ESP-AirPuff 泡芙一号的 ESP32-P4 大模型 AI 智能体方案
人工智能