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

相关推荐
中微极客几秒前
2026 AI视频生成模型选型:Veo 3.1、Kling 3.0、Seedance 2.0实测对比
人工智能·音视频
2601_962860158 分钟前
隐私计算工程选型:MPC、联邦学习与可检索的测评基准
人工智能
启途AI9 分钟前
重构AI时代品牌坐标:搜极星与InsGEO双核驱动下的GEO全域监测新范式及生态工具全景解析
人工智能·重构
心念枕惊12 分钟前
【Agent Harness】Gliding Horse 整体架构拼图:当 AI Agent 有了自己的操作系统
人工智能·架构
JackHCC24 分钟前
Meta-SlimPer:固定知识库重构个性化排序
人工智能·机器学习·重构
Sirius Wu39 分钟前
OpenClaw Model Provider(模型提供商)完整详解
服务器·网络·人工智能·安全·aigc
1234Wu1 小时前
企业网站建设与SEO之后,如何补上GEO让AI搜索推荐你的品牌?
人工智能
产品推荐官1 小时前
2026年AI应用开发服务商的选择逻辑:适配度比功能清单更重要
大数据·人工智能·ai·技术分享·开发经验
虹科网络安全1 小时前
“顶会”看安全(十六):深入分析函数内联及其对基于机器学习的二进制分析的安全影响
人工智能·安全·机器学习
麻雀飞吧1 小时前
最新量化实现难点,规则和流程要先有形状
人工智能·python