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

相关推荐
源于花海4 分钟前
模型独立的学习方式——协同训练
深度学习·机器学习·协同训练
geneculture7 分钟前
亚符号:人机互助中被忽视的根基——一种认知哲学分析
人工智能·融智学的重要应用·人机间性·符号与规则·亚符号与权重·融智时代杂志
aisifang008 分钟前
PDF转Word神器:Gemini3.1Pro一键搞定文档处理
人工智能·pdf·word
东坡肘子9 分钟前
让 AI 从称手到称心 -- 肘子的 Swift 周报 #134
人工智能·swiftui·swift
潘祖记11 分钟前
# 一行命令让 AI 接管全屋智能:FeyaGate Skill 保姆级接入教程,小米/涂鸦/美的/易微联全搞定
人工智能·后端·asp.net
joshchen21516 分钟前
强化学习基础(赵世钰)第二章 贝尔曼方程
人工智能·python·机器学习·强化学习
魔术师Grace17 分钟前
普通人学 AI,不要一上来就学提示词
前端·人工智能·程序员
数字化转型202519 分钟前
10年之后的未来:AI + 机器人成为主要价值创造者
人工智能
ZhengEnCi20 分钟前
01d-前馈神经网络代码实现 💻
人工智能·深度学习·神经网络
冬奇Lab22 分钟前
一天一个开源项目(第93篇):Symphony - OpenAI 官方定义的 AI 代理编排规范
人工智能·openai·agent