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

相关推荐
Lyon198505282 分钟前
ChatGPT的最终总结分析-《文字定律》随笔
人工智能·ai·chatgpt
L、2184 分钟前
CANN神经网络算子库`ops-nn`:昇腾NPU上Matmul与激活函数的底层逻辑
人工智能·深度学习·神经网络
程序员码歌6 分钟前
OpenSpec 到 Superpowers:AI 编码从说清到做对
android·前端·人工智能
海兰7 分钟前
【第21篇-续】graph-Stream-Node改造为适配openAI模型示例
java·人工智能·spring boot·spring·spring ai
MobotStone11 分钟前
生成代码一分钟,填坑一小时?问题不在 AI,而在用法
人工智能
ccice0112 分钟前
硬核技术解析:运用Gemini多步推理链,攻克办公场景中的复杂决策与风险矩阵构建(国内免费镜像实操)
人工智能·线性代数·矩阵
2601_9594779114 分钟前
Vatee:数字化能力升级的全面观察
大数据·人工智能
@蔓蔓喜欢你14 分钟前
Web Components:构建可复用组件的未来
人工智能·ai
JGHAI15 分钟前
GEO优化:AI搜索时代的底层逻辑重构与中小企业实践路径
人工智能
庚昀◟16 分钟前
ClaudeCode安装教程,基础使用、进阶推荐
人工智能·python·ai