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

相关推荐
技术小黑3 分钟前
RNN算法实战系列04 | LSTM火灾温度预测
rnn·深度学习·lstm·tensorflow2
GuWenyue6 小时前
放弃云端API!一套React+WebGPU本地LLM方案,零数据上传、离线可用
前端·人工智能·前端框架
love530love7 小时前
OpenClaw Windows Companion 桌面客户端 连接 LM Studio 完整配置指南
人工智能·windows·python·openclaw
墨舟的AI笔记8 小时前
从文本提示到可交互道具:AIGC 生成游戏资产的语义对齐与合规校验
人工智能
rain_sxr8 小时前
逼近上限就裁剪:大模型 Token 计数与前端上下文预算管理
人工智能
资深数据库专家9 小时前
月之暗面Kimi:K3之后,开源怎么走?
人工智能
小林ixn9 小时前
告别“屎山”与“幻觉”:3个核心心法,让你的Vibe Coding体验起飞
人工智能·agent
汤姆小白10 小时前
06-CLI命令参考
人工智能
颜酱10 小时前
04 | 召回前置准备:搭好召回所需的四个数据库
前端·人工智能·后端