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

相关推荐
Terrence Shen16 分钟前
Agent面试八股文(系列之二)
人工智能·大模型·agent·rag
爱睡懒觉的焦糖玛奇朵4 小时前
【从视频到数据集:焦糖玛奇朵的魔法工具使用说明】
人工智能·python·深度学习·学习·算法·yolo·音视频
oy_mail4 小时前
2026教程:用Gemini解决PCB设计与EMC/EMI问题,工程师效率跃升指南(国内直访)
人工智能
Runawayliquor4 小时前
opbase:CANN 所有算子的公共地基
大数据·数据库·人工智能·算法
英辰朗迪AI获客4 小时前
AI动态简报之算力基建篇(2026.05.22)
人工智能
徐安安ye4 小时前
FlashAttention 为什么对序列长度这么“敏感”?
人工智能·算法
天行健,君子而铎5 小时前
2026国内政务数据安全平台排名评析:基于AI降噪、全链路、动态性
人工智能·政务
智塑未来5 小时前
app应用怎么接入广告?标准流程与落地实操方案全解析
大数据·网络·人工智能
甲维斯5 小时前
Claude Code的六种种授权模式!安全和效率控制
人工智能·ai编程