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

相关推荐
F_U_N_5 分钟前
拒绝手动配环境!MonkeyCode:手机就能写项目,AI全程扛事
人工智能·ai编程
helloworddm8 分钟前
Vulkan GPU图像处理之对数变换:Kompute框架实战与性能分析
图像处理·人工智能·计算机视觉
旺仔Sec12 分钟前
一万字带您看懂:从“赛项”到“赛道”解读世界职业院校技能大赛改革与备赛策略
人工智能·世界职业院校技能大赛·大赛
海兰13 分钟前
【第2篇-续】从零开始helloworld使用openAI通用模型的完整实现示例附源代码
java·人工智能·spring boot·alibaba·spring ai
科研实践课堂(小绿书)15 分钟前
基于AI智能算法的装备结构可靠性分析与优化设计技术
人工智能·机器学习
蕤葳-22 分钟前
理性分析:如何利用考证作为抓手,构建系统化知识体系与职业规划?
人工智能·网络协议·https
秋923 分钟前
学霸圈公认的 10 种高效学习习惯:从低效到顶尖的底层逻辑
人工智能·学习·算法
大强同学33 分钟前
我用AI管知识库后,再也回不去了
人工智能
2501_9449347335 分钟前
2026销售岗怎样提升客户管理效率?
人工智能
AI精钢38 分钟前
Claude Opus 4.7 是一次失败的升级吗?一次基于用户反馈的技术复盘
网络·人工智能·ai·大模型·llm·claude·技术评论