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 分钟前
BMAD之核心架构:为什么“方案化”至关重要 (Phase 3 Solutioning)——必学!BMAD 方法论架构从入门到精通
人工智能·ai·系统架构·ai编程·敏捷开发·ai辅助编程·bmad
2501_926978335 分钟前
分形时空理论框架:从破缺悖论到意识宇宙的物理学新范式引言(理论概念版)--AGI理论系统基础1.1
java·服务器·前端·人工智能·经验分享·agi
heimeiyingwang15 分钟前
AI 赋能企业业务:从降本增效到业务创新
人工智能
阿林来了24 分钟前
Flutter三方库适配OpenHarmony【flutter_speech】— 语音识别监听器实现
人工智能·flutter·语音识别·harmonyos
教男朋友学大模型28 分钟前
LoRA 为什么必须把一个矩阵初始化为0
人工智能·算法·面试·求职招聘
小鸡吃米…28 分钟前
TensorFlow—— 卷积神经网络(CNN)与循环神经网络(RNN)的区别
人工智能·tensorflow
智能交通技术32 分钟前
iTSTech:从AGI到AMI——自动驾驶的新方向 2026
人工智能·机器学习·自动驾驶·agi
小lo想吃棒棒糖32 分钟前
思路启发:基于预测编码的Transformer无反向传播训练:局部收敛性与全局最优性分析:
人工智能·深度学习·transformer
来两个炸鸡腿33 分钟前
【Datawhale组队学习202602】Hello-Agents task04智能体经典范式构建
人工智能·学习·大模型·智能体
2501_9269783337 分钟前
重整化群理论:从基础到前沿应用的综述(公式版)---AGI理论系统基础2.2
人工智能·经验分享·深度学习·机器学习·agi