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

相关推荐
听你说3214 小时前
中节能晶和科技亮相道路照明论坛:以EMC模式破局行业热潮 做智慧照明高质量发展引领者
大数据·人工智能·科技
ai大模型中转api测评14 小时前
Claude Opus 4.7 深度拆解:自验证架构与 1M 上下文,全方位对标 GPT-5.4
人工智能·gpt·自动化·api
脑极体14 小时前
智能体落地零售,带来了哪些新可能?
大数据·人工智能·零售
摸鱼仙人~14 小时前
企业级 AI Coding 设计规范
人工智能·设计规范
徐礼昭|商派软件市场负责人14 小时前
效率提升75%!AI赋能ECShopX系统开发特辑:使用Cursor、Codex、Figma等AI辅助工具高效完成商城创新功能开发
人工智能·figma
广州创科水利14 小时前
揭阳龙颈下水库除险加固:智慧监测护航,筑牢安全防线
人工智能
码云数智-大飞14 小时前
AI写单元测试的现状与挑战:覆盖率不等于有效性
人工智能
人工智能AI技术14 小时前
虚拟机基础:JVM、V8 运行机制极简科普
人工智能
和诺泰IC(-雷S-0114 小时前
现货库存TVP5158IPNPRQ1是德TI推出的一款高性能、多通道视频解码器芯片,专为安防监控、汽车电子及工业视频系统等对稳定性与图像质量要求较高的场景设计
人工智能·集成电路·电子元器件
阿里巴啦14 小时前
一个 Python 视频处理工具链实战:下载、转录、摘要、字幕、诊断全打通 (已开源)
人工智能·python·whisper·视频下载·视频处理工具