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

相关推荐
人工智能AI技术1 分钟前
AI编程规范
人工智能
yinghuoAI20263 分钟前
视觉生产力的觉醒:萤火AI如何让电商人从“工具”变回“人”
人工智能·新媒体运营·产品运营·个人开发·流量运营·用户运营·内容运营
龙文浩_4 分钟前
AI中NLP的自然语言处理中的文本预处理与特征工程
人工智能·pytorch·深度学习·神经网络·自然语言处理
好运的阿财4 分钟前
OpenClaw四种角色详解
人工智能·python·程序人生·microsoft·开源·ai编程
Pelb4 分钟前
求导 z = x + y
人工智能·深度学习·数学建模
斯坦SteinY5 分钟前
Git Worktree + Claude Code同时开发多个功能
人工智能·chatgpt·prompt·aigc·claude·并行开发
Ashley_Amanda7 分钟前
UiPath完全指南:从入门到精通
大数据·人工智能
Legend NO247 分钟前
精准定位企业竞争战略:经典理论与智能升维下的战略落地方法论
人工智能
小荟荟8 分钟前
全国数据资产新闻和报纸摘要联播 2026年3月22日 第25期
大数据·人工智能·数据挖掘
灵机一物9 分钟前
灵机一物AI原生电商小程序(已上线)-AI全链路自动化!内容推广系统架构解析(附落地细节)
人工智能·系统架构·自动化·内容推广