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

相关推荐
2401_8638014612 小时前
怎么把多个glb/gltf格式模型,导出保存一个个物体,只保留自己想要的部分
人工智能
一切皆有可能!!12 小时前
昇腾atlas 300I duo部署Qwen3-8B完整实战:从选型到成功运行
人工智能·大模型·昇腾·大模型部署
问道财经12 小时前
和飞书合作,安克没能走出舒适区
人工智能
Fleshy数模12 小时前
从一条直线开始:线性回归的底层逻辑与实战
人工智能·机器学习·概率论
哥布林学者13 小时前
吴恩达深度学习课程五:自然语言处理 第三周:序列模型与注意力机制 课后习题与代码实践
深度学习·ai
ssxueyi13 小时前
ModelEngine + MCP:解锁 AI 应用的无限可能
人工智能·大模型·ai应用·ai开发·modelengine
AAD5558889913 小时前
压接工具检测识别----RPN-R50-Caffe-C4模型训练与优化
人工智能·深度学习
OLOLOadsd12313 小时前
基于NAS-FCOS的拥挤路段车辆检测系统:R50-Caffe-FPN-NASHead-GN-Head模型训练与优化_1
人工智能·深度学习
AIArchivist13 小时前
破解肝胆慢病管理痛点,AI让长期守护更精准高效
人工智能
laplace012313 小时前
Claude Code 逆向工程报告 笔记(学习记录)
数据库·人工智能·笔记·学习·agent·rag