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

相关推荐
迪康Defender2 分钟前
终端安全事后追溯能力解析:本地审计模块设计思路与落地实践
运维·开发语言·人工智能·安全·php·安全威胁分析·运维开发
郝学胜_神的一滴2 分钟前
Numpy数据处理详解 01:NumPy 从环境搭建到入门上手
人工智能·python
俊哥V7 分钟前
每日 AI 研究简报 · 2026-10-06
人工智能·ai
凡达Ai派9 分钟前
AI画布明暗关系总在变?用光源声明表和亮度分区做视觉验收
人工智能
你就是答案 -14811 分钟前
2026企业AI办公工具选型指南:搭建适配业务的智能协作体系
人工智能
Asa1213811 分钟前
Nature Microbiology|不依赖系统发育的机器学习框架从基因组预测菌株水平噬菌体—宿主互作
人工智能·机器学习
高升说14 分钟前
BEV环视硬件搭建全解析:机位、视场、链路与同步的工程方法
人工智能·数码相机
xsd2024111814 分钟前
秸秆禁烧AI算法服务全解析:烟火识别、视频接入、周期训练、点位标定与巡检纠错
人工智能
常州晟凯电子科技17 分钟前
sigmaStar SSC305DE/SSC308开发笔记之开发环境搭建和SDK编译
人工智能·笔记·嵌入式硬件·物联网·性能优化·视频编解码
回眸&啤酒鸭23 分钟前
【回眸】MiMo-V2.6-Flash 多模态实时交互应用指南
人工智能