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

相关推荐
财迅通Ai4 小时前
商业航天概念领涨A股,航天ETF华安(159267.SZ)收盘上涨1.2%
大数据·人工智能·区块链·中国卫星·航天电子
齐齐大魔王4 小时前
智能语音技术(八)
人工智能·语音识别
许彰午5 小时前
零成本搭建RAG智能客服:Ollama + Milvus + DeepSeek全程实战
人工智能·语音识别·llama·milvus
ZPC82105 小时前
自定义action server 接收arm_controller 指令
人工智能·机器人
迷茫的启明星5 小时前
各职业在当前发展阶段,使用AI的舒适区与盲区
大数据·人工智能·职场和发展
Liqiuyue6 小时前
Transformer:现代AI革命背后的核心模型
人工智能·算法·机器学习
桂花饼6 小时前
AI 视频生成:sora-2 模型快速对接指南
人工智能·音视频·sora2·nano banana 2·claude-opus-4-6·gemini 3.1
GreenTea7 小时前
AI Agent 评测的下半场:从方法论到落地实践
前端·人工智能·后端
冬奇Lab8 小时前
一天一个开源项目(第73篇):Multica - 把 AI 编程智能体变成真正的团队成员
人工智能·开源·资讯