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

相关推荐
曾响铃2 小时前
千台量产前夜,具身智能竞争已沉到底层基建
人工智能
血色橄榄枝2 小时前
基于用户注册信息的关键词检测挑战赛「Datawhale AI 夏令营」
人工智能·算法·机器学习
A hao2 小时前
高对比度在XR虚拟背景中的作用
大数据·图像处理·人工智能·xr·广告
小二·2 小时前
2026年AI Agent框架横评:OpenClaw vs LangGraph vs CrewAI vs Superpowers,选型指南
人工智能
tyqtyq222 小时前
旅行打包清单 App — HarmonyOS AI 应用开发技术博客
人工智能·学习·华为·生活·harmonyos
guo_xiao_xiao_2 小时前
YOLOv11道路桥梁裂缝与坑洼目标检测数据集
人工智能·yolo·目标检测
邵宇然3 小时前
Rust Unsafe 代码规范:不安全块要小到能被审查
人工智能
Haoxuekeji3 小时前
山东 AI 智能批改校园电子阅卷企业
大数据·人工智能·深度学习·安全·ai
视觉AI4 小时前
VS Code Remote-SSH 连接Jetson踩坑完整解决记录(网段不通+主机密钥变更双重故障)
运维·网络·人工智能·windows·ssh·边缘计算