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

相关推荐
新缸中之脑3 分钟前
Tripo AI:构建游戏就绪的3D资产
人工智能·游戏·3d
Coder_Boy_3 分钟前
Java高级_资深_架构岗 核心知识点——高并发模块(底层+实践+最佳实践)
java·开发语言·人工智能·spring boot·分布式·微服务·架构
AC赳赳老秦9 分钟前
2026 AI原生开发工具链趋势:DeepSeek与主流IDE深度联动实践指南
运维·ide·人工智能·架构·prometheus·ai-native·deepseek
Dr.AE16 分钟前
深小i 产品分析报告
大数据·人工智能·政务
吾在学习路17 分钟前
AoP-SAM: Automation of Prompts for Efficient Segmentation
人工智能·深度学习·算法·计算机视觉
新缸中之脑23 分钟前
顶级视频生成模型 (2026)
人工智能
技术宅学长28 分钟前
Router门控网络简单介绍
人工智能·深度学习
健康平安的活着30 分钟前
AI之Toolcalling的使用案例(langchain4j+springboot)
人工智能·spring boot·后端
2501_9269783333 分钟前
大模型“脱敏--加密”--“本地轻头尾运算--模型重运算”
人工智能·经验分享·架构
冰西瓜60040 分钟前
深度学习的数学原理(十二)—— CNN的反向传播
人工智能·深度学习·cnn