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

相关推荐
dajun181123456几秒前
音乐制作从创作到发行完整流程图表怎么画
大数据·运维·人工智能·信息可视化·架构·流程图·能源
Zhijun.li@Studio1 分钟前
【2026 最新】Mac 上手 OpenCode 完整安装指南(火山豆包 + 自定义模型)
macos·大模型·opencode
云边云科技_云网融合2 分钟前
云原生全球广域网架构深度科普:从单点集中到全域互联
大数据·人工智能·科技·云计算
輕華3 分钟前
OpenCV 实战封神榜(下):轮廓检测 + 模板匹配,从特征提取到精准匹配
人工智能·opencv·计算机视觉
听风吹等浪起4 分钟前
基于深度学习的医学图像分割系统:架构设计、实现与优化分析
人工智能·深度学习
人工智能AI技术4 分钟前
火山引擎ArkClaw深度体验:云端SaaS版OpenClaw在企微自动办公的完整实践
人工智能
进击ing小白6 分钟前
OpenCv之图像二值化
人工智能·opencv·计算机视觉
永霖光电_UVLED6 分钟前
将硅基 N 极性 GaN HEMT 扩展至 8 英寸晶圆
人工智能
Daydream.V7 分钟前
Opencv——图像形态学和边缘检测
人工智能·opencv·计算机视觉
智哪儿7 分钟前
小米 “养龙虾”:手机 Agent 落地,智能家居十年困局被撬开
人工智能·ai·智能体