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

相关推荐
小和尚同志1 小时前
小黑插图 Skill:从 11.7k star 的 Codex 专属,到 Claude Code 能用的平替
人工智能·aigc
高洁011 小时前
孪生不止在工厂:能源、医疗与农业
人工智能·深度学习·transformer·知识图谱·tornado
外域速览1 小时前
智谱50亿美元押注AI自训练
大数据·人工智能
人工智能培训1 小时前
孪生不止在工厂:能源、医疗与农业
大数据·人工智能
米小虾2 小时前
让模型说"我不知道",比让它答对更难:放弃文本生成能换来什么
人工智能
新新学长搞科研2 小时前
【SPIE出版】2026年人工智能、新材料与新能源国际学术会议(AINMNE 2026)
人工智能·新能源·新材料
野生技术架构师2 小时前
2026 Java 面试全套总结,八股 + 场景 + AI 相关面试考点
java·人工智能·面试
米小虾2 小时前
不写出来的思考:把 Transformer 的层循环起来,是第三条 scaling 轴还是省错了地方?
人工智能
A.说学逗唱的Coke3 小时前
【大模型专题】别再用 HTTP 直连 Agent 了:用 Kafka 承载 A2A 协议,从 PoC 走到生产
人工智能·kafka·a2a
资讯综合3 小时前
2026企业AI平台选型指南:多维视角下的主流方案解析
人工智能