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

相关推荐
阿里云大数据AI技术2 分钟前
DataWorks Data Agent的演进与工程化实践
人工智能·agent
HERR_QQ9 分钟前
强化学习的数学原理 学习笔记
人工智能·笔记·学习·自动驾驶
IvorySQL12 分钟前
PG 技术日报|2026-07-04
数据库·人工智能·postgresql·开源
程序员cxuan16 分钟前
Claude Code 为了封禁中国用户,竟然在代码里下毒
人工智能·后端·程序员
shushangyun_18 分钟前
2026年AI知识库系统选型指南
人工智能
喵叔哟44 分钟前
从聊天记录到真正的记忆:为 AI Agent 设计一套分层记忆系统
人工智能·langchain
道友可好1 小时前
Claude Code 泄露源码里的 89 个秘密
前端·人工智能·后端
大鱼>1 小时前
推荐系统原理与实现:协同过滤/内容推荐/深度学习
人工智能·深度学习
MartinYeung51 小时前
[论文学习]DP-Fusion:面向大语言模型的令牌级差分隐私推理-深度解析
人工智能·学习·语言模型
库拉大叔1 小时前
GPT提示词写法大全:不同场景的提问模板
人工智能·gpt