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

相关推荐
小程故事多_808 分钟前
Claude Code与Codex六大组件拆解,Coding Agent怎么把任务做稳
人工智能
Keepreal49613 分钟前
《从零构建大模型》——从头实现GPT模型进行文本生成
gpt·深度学习·llm
董员外13 分钟前
RAG 系统进化论(六):GraphRAG(基于知识图谱的 RAG),从相似文本走向实体关系
人工智能·后端·设计模式
Summer-Bright42 分钟前
AI 软件简报 07.29-08.02:OpenAI 降价 80%、DeepSeek 全开源、欧盟动刀
人工智能·ai·开源·ai软件
武子康1 小时前
模型发布可以按天看,生产默认模型不能按天切:一套可回退的 30 天验收流程
人工智能·llm·agent
神经蛙19961 小时前
我用 TRAE Work 做周报:从 4 小时到 45 分钟的完整实操,建议收藏
人工智能
测不准1 小时前
终端日志还在手抄 ANSI 颜色码么?这个 VS Code 插件让你像选主题一样配颜色
人工智能
kuinnebula1 小时前
知识图谱skill
人工智能·知识图谱
DS随心转小程序1 小时前
实测评测 AI 导出鸭转化效能,全方位优化 DeepSeek 输出 word 文档落地使用效率
人工智能·aigc·word·豆包·deepseek·ai导出鸭
哈尔ai1 小时前
别让模型接口成为参数黑洞:Spring MVC 请求绑定、校验与错误契约实战
人工智能