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

相关推荐
zubylon几秒前
前端 RAG:把文档检索接到聊天页
前端·人工智能·算法
iNeuOS工业互联网1 分钟前
iNeuOS工业互联网操作系统集成大模型智库(iNeuOS_AiMind·心智灵慧)
大数据·人工智能·智能制造·视频·工业互联网·ineuos
人工智能AI技术1 分钟前
终身学习基础:AI 持续进化不遗忘旧知识
人工智能
前端不太难7 分钟前
给AI装上“安全缰绳”:OpenClaw与Co-Sight的信任协作
人工智能·安全·状态模式
甲维斯8 分钟前
逆天好消息!所有Claude用户配额翻倍
人工智能
名不经传的养虾人9 分钟前
从0到1:企业级AI项目迭代日记 Vol.18|功能被悄悄改没了,然后我们写了个看门狗
大数据·人工智能·ai编程·企业ai·多agent协作
Aray123415 分钟前
CPU vs GPU vs TPU vs NPU vs LPU vs DPU:驱动现代 AI 的六大处理器解析
人工智能
动物园猫16 分钟前
公共安全打架行为识别数据集分享(适用于YOLO系列深度学习检测任务)
人工智能·深度学习·yolo
byte轻骑兵16 分钟前
【HID】规范精讲[10]: 蓝牙HID设备的连接基石——GAP协议如何掌控发现、连接与安全
人工智能·人机交互·蓝牙·键盘·鼠标·hid