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

相关推荐
青瓷程序设计10 分钟前
【交通标志识别系统】python+深度学习+算法模型+Resnet算法+人工智能+2026计算机毕设项目
人工智能·python·深度学习
Mr.huang11 分钟前
RNN系列模型演进及其解决的问题
人工智能·rnn·lstm
香芋Yu15 分钟前
【深度学习教程——01_深度基石(Foundation)】05_数据太多怎么吃?Mini-batch训练的设计模式
深度学习·设计模式·batch
智驱力人工智能16 分钟前
货车走快车道检测 高速公路安全治理的工程实践与价值闭环 高速公路货车占用小客车道抓拍系统 城市快速路货车违规占道AI识别
人工智能·opencv·算法·安全·yolo·目标检测·边缘计算
老百姓懂点AI20 分钟前
[RAG架构] 拒绝向量检索幻觉:智能体来了(西南总部)AI agent指挥官的GraphRAG实战与AI调度官的混合索引策略
人工智能·架构
ws20190721 分钟前
技术迭代与湾区赋能:AUTO TECH China 2026广州汽车零部件展的四大核心价值
人工智能·科技·汽车
源于花海27 分钟前
迁移学习简明手册——迁移学习相关资源汇总
人工智能·机器学习·迁移学习
aihuangwu30 分钟前
deepseek图表怎么导出
人工智能·ai·deepseek·ds随心转
Gofarlic_oms141 分钟前
通过Kisssoft API接口实现许可证管理自动化集成
大数据·运维·人工智能·分布式·架构·自动化
电商API&Tina42 分钟前
电商数据采集 API 接口 全维度解析(技术 + 商业 + 合规)
java·大数据·开发语言·数据库·人工智能·json