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

相关推荐
weixin_4462608510 小时前
AutoDesign:面向长时序智能体设计的元调度优化框架
人工智能
Rocktech_ruixun10 小时前
机器人端侧大模型部署对主板有哪些要求?瑞迅主控板分级方案对比
人工智能·嵌入式硬件·机器人
ZGi.ai10 小时前
多模型回答不稳定:路由规则与评测方法
网络·人工智能·大模型评测·多模型·模型路由·zgi·模型网关
dogstarhuang10 小时前
大模型 API 停服怎么办:用 API 网关实现多模型统一接入与可切换架构
人工智能·后端·架构·大模型·api·数字化转型·ai应用
紫禁玄科11 小时前
MCP协议安全深度剖析:AI Agent时代的隐形攻击面
人工智能
明航咨询_贾老师11 小时前
CISP-AISE知识体系大纲深度解读:6大模块,国内首个AI安全应用官方认证
人工智能·安全
weixin_3975740911 小时前
当AI的思考过程第一次被看见
人工智能
北风toto11 小时前
从提示词到工程化:大模型时代的AI工程实战指南
人工智能
CV-杨帆11 小时前
DeepSeek Harness入门教程实操 从零开始安装与使用 DeepSeek-V4-Pro基座5毛完成任务
人工智能