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

相关推荐
Nablai11 小时前
AI 玩具机芯合作模式拆解:OEM 与 ODM 的工程边界
人工智能
4SAPI11 小时前
Gemini 4 Pro 泄露参数解析:2M 上下文时代,企业如何规划 Gemini API 中转与多模型架构?
人工智能·gemini
码云之上11 小时前
Skill 里的脚本终于能跑了,星悟接 CubeSandbox 的纪实
前端·人工智能·前端框架
IT_陈寒11 小时前
Vue computed属性这个坑,我居然踩了三次才爬出来
前端·人工智能·后端
paopaokaka_luck11 小时前
小学非遗科普平台(AI 非遗科普问答,ECharts学情数据、非遗资源分类与审核,资源收藏下载与学习记录,学习任务发布和作品评分,活动报名签到与统计)
java·人工智能·spring·信息可视化·数据分析·echarts
threerocks11 小时前
【AI 媒体必备】角色说明书制作
人工智能
子非鱼eva12 小时前
昇腾开源仓Issue分析解答-CANN精选(一)
人工智能·ai
边界智能12 小时前
边界智能通过人工智能管理体系认证,AI 研发及管理能力获权威认可
人工智能·ai·智能体
TomEval12 小时前
【测AI】第02篇:Python 环境搭建与基础语法速通
人工智能·python·功能测试·aigc
孙启超12 小时前
【AI开发之Rust】第 7 课:错误处理 —— panic、Result 与 `?`
人工智能·分布式·后端·爬虫·spring cloud·架构·rust