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

相关推荐
Codebee6 分钟前
OoderAgent Apex OS:基于Skills化架构的热插拔启动机制
人工智能
苏打水前端客9 分钟前
【OpenClaw 保姆级教程】第二篇:多渠道接入 + 核心技能上手(附实操案例)
人工智能
何政@10 分钟前
Agent Skills 完全指南:从概念到自定义实践
人工智能·python·大模型·claw·404 not found 罗
码农三叔15 分钟前
(1-2)控制系统基础与人形机器人特点:人形机器人控制的特殊挑战
人工智能·机器学习·机器人·人形机器人
ai产品老杨16 分钟前
源码交付与全协议兼容:企业级 AI 视频中台的二次开发实战
人工智能·音视频
Rick199323 分钟前
Prompt 提示词
人工智能·深度学习·prompt
beiju24 分钟前
AI Agent 不是你以为的那样
人工智能·claude
Fleshy数模29 分钟前
基于OpenCV实现人脸与微笑检测:从入门到实战
人工智能·opencv·计算机视觉
沪漂阿龙29 分钟前
深入浅出 Pandas apply():从入门到向量化思维
人工智能·python·pandas