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

相关推荐
继续商行1 分钟前
探秘 Go 动态数组:pprof 排查大数据切片 GC 停顿
人工智能
OBiO20132 分钟前
如何利用AAV精准靶向血管平滑肌细胞(VSMCs)?
人工智能
lwyingdao2 分钟前
Codex接入国产大模型,三步配置,无需OpenAI账号
人工智能·ai编程·ai工具
团象科技4 分钟前
出海企业算力适配调研:深度学习模型云端搭建的落地观察
人工智能·深度学习
kft13146 分钟前
04 — AI 测试用例生成与评审实战
人工智能·测试用例
无心水6 分钟前
【Harness:落地实战】24、Harness CI/CD+GitOps深度实战:智能交付与渐进发布——企业级云原生DevOps全解析
人工智能·ci/cd·云原生·openclaw·harness·hermes·honcho
AI学长7 分钟前
数据集|二维码目标检测QRCodeDetection
人工智能·目标检测·计算机视觉·二维码目标检测
IT_陈寒8 分钟前
React开发实战:从入门到精通
前端·人工智能·后端
古道青阳10 分钟前
AI编码智能体横向评测Cursor、OpenAI Codex 与 Claude Code
人工智能
kft131411 分钟前
测试深度洞察 | 2026年6月:测试工具迭代背后的行业信号
人工智能·测试用例