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

相关推荐
youcans_2 小时前
【HALCON机器视觉实战】专栏介绍
图像处理·人工智能·计算机视觉·halcon
火山引擎开发者社区2 小时前
火山引擎 veRoCE 获权威认证:IANA 官方为 veRoCE 分配专属 UDP 端口号 4794
人工智能
飘落的数码折腾日记2 小时前
你的AI Agent可能正在“叛变“ | 5类真实威胁与四层防御
人工智能
放羊郎2 小时前
基于ORB-SLAM2算法的优化工作
人工智能·算法·计算机视觉
AI袋鼠帝3 小时前
字节的技术决心,都藏在这个动作里
人工智能
AI袋鼠帝3 小时前
企微又偷偷进化AI,并开始不对劲了..
人工智能
工业机器人销售服务3 小时前
2026 年,探索专业伯朗特机器人的奇妙世界
人工智能·机器人
摆烂大大王3 小时前
AI 日报|2026年5月9日:四部门力推AI与能源双向赋能,AI终端国标出台,中国大模型融资潮涌
人工智能
萑澈3 小时前
编程能力强和多模态模型的模型后训练
人工智能·深度学习·机器学习
LaughingZhu4 小时前
Product Hunt 每日热榜 | 2026-05-08
人工智能·经验分享·深度学习·神经网络·产品运营