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

相关推荐
styshoo14 分钟前
[snapshot]1-snapshot内部逻辑
人工智能
yi01118 分钟前
DAY28: LeetCode 111. 二叉树的最小深度
人工智能·笔记·python·算法·leetcode·二叉树·递归
方方洛20 分钟前
ai-agent教程-05-上下文工程
人工智能·llm·agent
阿里云大数据AI技术22 分钟前
从原始Ego视频到训练就绪:用 EMR Serverless Spark 上的 Ray 提效具身数据生产管线
人工智能·spark
智圣新创0126 分钟前
全国高校第二课堂数字化建设供需适配指南:从政策要求到落地运营的全链路效能提升路径
人工智能
土星云SaturnCloud29 分钟前
土星云边缘计算+AI视觉+视频存管:连锁汽修数字化升级实践
服务器·人工智能·ai·边缘计算
糖糖单片机设计35 分钟前
基于 STM32 的配网变压器涌流抑制器设计与实现
人工智能·stm32·嵌入式硬件·51单片机·语音识别
倔强的小石头_37 分钟前
从Go+SQLite编译到浏览器开局:landlord部署、AI对局与固定地址实战
人工智能·golang·sqlite
Rany-39 分钟前
基于机器学习的长距离原水管线泄漏检测和定位
人工智能
Dawson Zhu42 分钟前
《Agentic Design Patterns》第 17 章导读:推理技术
人工智能·语言模型·架构·aigc·agi