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

相关推荐
圆圆讲门店3 小时前
挑选同城获客服务机构时需要考量的核心因素都有哪些?
大数据·网络·人工智能·python
揽秀亭长3 小时前
论文降AI率有哪些方法?论文修改流程详解
人工智能·深度学习
爱上纯净的蓝天3 小时前
只输出选项和概率的模型:判别层的接口契约与阈值工程
人工智能·大模型·llm·模型评估·架构设计
@呱呱爱学习3 小时前
2026年09月28日 | 呱呱AI日报】GitHub 发布 Copilot WSL 教程,介绍在 Ubuntu 中运行编程 Agent
人工智能·github·copilot
lie..4 小时前
30天从零开始学AI应用开发(Day 12):像产品一样稳:流式输出、报错重试、花钱控制
开发语言·人工智能·php
镜象科技4 小时前
AI临床心理大模型:离临床最近的AI长什么样?
人工智能
zhanghaha13144 小时前
AI Agent_4 Agent工作原理详解:从“会聊天“到“会办事“
人工智能
DeepAgent4 小时前
AI Agent 工程实践(49):一次真实优化——从 Agent v1 到 v2
开发语言·人工智能·agent
民乐团扒谱机4 小时前
【微科普】节拍检测从入门到迁移:西方SOTA模型怎么识别Beat,中国戏曲民乐又该怎么训练?
深度学习·大模型
小蒋观天下4 小时前
两轮车检测AI摄像头——2026-2030年未来市场规模、增长逻辑与行业天花板
大数据·人工智能·安全·计算机视觉·ai大模型