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

相关推荐
mwq30123几秒前
Claude 完整代码教程(转载)
人工智能
DisonTangor2 分钟前
【阿里拥抱开源】阿里inclusionAI开源多模态Ming-flash-omni 2.0
人工智能·开源·aigc
MaoziShan5 分钟前
CMU Subword Modeling | 01 Things Smaller than Words
人工智能·机器学习·自然语言处理
文艺倾年7 分钟前
【免训练&测试时扩展】Code Agent可控进化
人工智能·软件工程·强化学习·vibecoding
宇擎智脑科技8 分钟前
SurrealDB:面向AI原生应用的新一代多模型数据库深度解析
数据库·人工智能·ai-native
一品威客爱开发9 分钟前
网游 APP 开发:聚焦交互体验与多端协同
人工智能
前沿AI9 分钟前
中关村科金 × 中国电信 以「文旅大模型 + 智能客服」点亮自贡灯会智慧服务新标杆
人工智能
木斯佳9 分钟前
HarmonyOS实战(解决方案篇)—企业AI资产利旧:如何将已有智能体快速接入鸿蒙生态
人工智能·华为·harmonyos
LuH112411 分钟前
【ILSVRC2012】ImageNet-1k数据集下载与处理脚本
python·深度学习·机器学习
A小码哥14 分钟前
开发利器 openCode + Oh My OpenCode 四大核心智能体:Sisyphus、Prometheus、Atlas 与 Hephaestus
人工智能