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

相关推荐
bst@微胖子2 分钟前
Spring AI (5) : MCP 深度实战:从工具抽取到鉴权,SSE 与 STDIO
人工智能·spring·dubbo
richard_yuu3 分钟前
OpenCV 实战第 8 篇:几何测量算子族,从 boundingRect 到亚像素定位
人工智能·opencv·计算机视觉
2601_956743684 分钟前
上海GEO营销公司技术评估方法|以盾码无界公开产品路线为例,拆解企业知识库语义检索、资料版本核验、内容人工审核与大模型监测复测的验证要点及适用边界
人工智能·geo·上海·企业服务
中伟视界5 分钟前
AI视频监控矿山落地实践:从算法部署到误报调优全流程
人工智能
打工仔折腾 AI7 分钟前
FaceFusion本地换脸实战:Windows整合包、模型选择与遮罩调参记录
人工智能·windows·后端·python·深度学习·性能优化·ai agent 实战
DeviceHub15 分钟前
AI服务器电源设计进阶:TLVR电感的应用解析与选型验证指南
运维·服务器·人工智能
阿明副业观察20 分钟前
AI视频生成工具功能与作用全面解析:赋能高效内容创作
大数据·人工智能·aigc·音视频·ai写作
数智工坊24 分钟前
视觉SLAM第5讲|相机成像模型:针孔投影、畸变修正与深度感知全拆解
人工智能·深度学习·数码相机·机器人
坐吃山猪24 分钟前
Meta为Personal Agent推出一个新协议PAP
人工智能
要加油哦~24 分钟前
论文 | vision2web 基于代理验证的可视化网站开发分层基准测试
人工智能·论文