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

相关推荐
用户233986179573几秒前
TypeScript源码解析:系统提示词组装管线
人工智能
数据世界12 分钟前
医院、零售、电商三端销售数据如何放进同一体系?分层抽样放大模型的分立与统一
大数据·数据库·人工智能
user4465117917912 分钟前
拆解 AgentScope Agent 运行时:一次 reply 从输入到结束的完整链路
人工智能
模事在人5 分钟前
Agent 效果上不去:先别急着换模型,先量一遍 harness
人工智能
lihuang3197 分钟前
逆向工程新范式:用 REA + MCP 让 AI Agent 直接拆二进制(原理拆解 + 实战)
人工智能
陈如水10 分钟前
尚硅谷 Spring AI学习
人工智能·python·spring
用户369594537382911 分钟前
大模型推理优化系列二:注意力计算与执行分派
人工智能
wyd2004030315 分钟前
开源 AnyLink Agent:跨设备 Agent 协作协议与云端共享记忆实践
人工智能·分布式·postgresql·开源·智能体·openclaw·共享记忆
D_C_tyu24 分钟前
AI能力测试·PRD文档分享 | 3D高山滑雪小游戏HTML页面
人工智能·3d·html
是菜鸡小小陈啊27 分钟前
【CS329Z Assignment 1】从零构建 LLM Agent Harness(学习笔记)06
人工智能·笔记·python·学习·llm·agent