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

相关推荐
天天进步20157 分钟前
[架构篇] 解构项目蓝图:Toonflow 的模块化设计与 AI 管道流转
人工智能·架构
龙文浩_8 分钟前
AI中NLP的深入浅出注意力机制 Seq2Seq 模型
人工智能·pytorch·深度学习·神经网络·自然语言处理
小饕8 分钟前
RAG 学习之-向量数据库与 FAISS 索引完全指南:从原理到选型实战
人工智能·rag·大模型应用
北京耐用通信8 分钟前
CC-Link IE转Modbus TCP集成实战:耐达讯自动化网关在五星级酒店节能改造中的应用
人工智能·物联网·网络协议·自动化·信息与通信
小超同学你好8 分钟前
面向 LLM 的程序设计 9:系统提示中的「能力边界」——减少越权与幻觉调用
人工智能·深度学习·语言模型
黑金IT9 分钟前
从“抽卡”到“工业化”:多模态 Harness 如何重塑 AI 内容生产的反馈闭环
人工智能·prompt·harness工程
笨笨饿11 分钟前
# 52_浅谈为什么工程基本进入复数域?
linux·服务器·c语言·数据结构·人工智能·算法·学习方法
踏着七彩祥云的小丑12 分钟前
Mac——已安装工具查找
macos
dtsola15 分钟前
小遥搜索生态新成员:一键导出钉钉文档,实现本地AI搜索
人工智能·ai编程·知识库·ai创业·独立开发者·个人开发者·一人公司
星爷AG I16 分钟前
18-9 预测心智(AGI基础理论)
人工智能·agi