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

相关推荐
wanzehongsheng8 小时前
双轴跟踪系统核心优势解析:助力光伏电站提质增效的关键技术
人工智能·光伏·智能光伏·光伏支架·光伏追踪支架·光伏跟踪支架
Swift社区8 小时前
Guardrails 实战:如何为 OpenClaw 构建 AI 行为护栏系统
人工智能·安全·openclaw
SmartBrain8 小时前
AI智能体:MCP模型上下文管理设计及实现
人工智能·spring cloud·架构
sysinside8 小时前
macOS Tahoe 26.4.1 (25E253) 正式版 ISO、IPSW、PKG 下载
macos·tahoe
憨波个8 小时前
【说话人日志】从 LSTM attractor 到 Transformer attractor:EEND-TA
人工智能·深度学习·lstm·transformer·音频·语音识别
guslegend8 小时前
第6节:OCR文本错漏频发?结合LLM纠错,让图像文本也能精确使用
人工智能·大模型·ocr·rag
遥不可及zzz8 小时前
[特殊字符] Android AAB 一键安装工具配置指南
android·macos
PD我是你的真爱粉8 小时前
大模型可控性实践:护栏技术、结构化输出、GPT Structured Outputs 与 GPTCache
人工智能·gpt
这张生成的图像能检测吗8 小时前
(论文速读)基于知识图谱构建的大型工业设备故障诊断模型
人工智能·深度学习·知识图谱·故障诊断
#卢松松#8 小时前
腾讯云宣布涨价
人工智能·创业创新