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

相关推荐
Hcoco_me13 分钟前
大模型面试题75:讲解一下GRPO的数据回放
人工智能·深度学习·算法·机器学习·vllm
赫尔·普莱蒂科萨·帕塔18 分钟前
“共享”机器人
人工智能·机器人·agi
duyinbi751723 分钟前
改进YOLO13模型:C3k2与PPA优化在油田工人安全装备检测与行为识别中的应用
人工智能·安全·目标跟踪
Duang007_36 分钟前
【LeetCodeHot100 超详细Agent启发版本】两数之和 (Two Sum)
java·人工智能·python
Ydwlcloud44 分钟前
AWS 2026折扣活动深度解析:寻找最大优惠的智慧路径
大数据·服务器·人工智能·云计算·aws
NingboWill1 小时前
AI日报 - 2026年01月14日
人工智能
QYR_111 小时前
聚偏二氟乙烯(PVDF)行业市场深度调研与投资前景预测报告2026版
大数据·人工智能
2401_832298101 小时前
芯片级机密计算,天翼云CSV3筑牢数据“可用不可见”防线
大数据·网络·人工智能
Java后端的Ai之路1 小时前
【AI大模型开发】-Embedding 与向量数据库:从基础概念到实战应用
数据库·人工智能·embedding·向量数据库·ai应用开发工程师
我想发发发1 小时前
已经安装了ROS环境却还是报错`ModuleNotFoundError: No module named ‘rclpy‘`
前端·人工智能·chrome·机器人