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

相关推荐
Am-Chestnuts1 小时前
DeepSeek内容转Word有哪几种方法?用DS随心转对比6条主流路径
开发语言·人工智能
童园管理札记1 小时前
从政策驱动到课堂落地:2026年“人工智能+教育”全景解读与技术实践指南
人工智能·python·深度学习·职场和发展·学习方法
程序员清风1 小时前
系统架构设计:模型服务、业务服务与知识库如何拆分
人工智能·ai·架构·aigc
jianpeng的工程笔记1 小时前
Qwen-Image-2.1 图像编辑拆解:从透明改字到多图合成
人工智能·qwen·图像生成·comfyui
武子康1 小时前
GPU Pod 已经 Running,为什么扩容还没变成推理容量?
人工智能·llm·agent
sdzhyt1 小时前
济南第六届高层次人才招引大会举行|智慧云通开放AI全栈、售前、销售、产品经理等岗位
人工智能·求职招聘·招聘
shionhana1 小时前
AI PPT 生成的两个关键环节:结构生成和视觉生成,以 PPTMaker 为例
人工智能·chatgpt·agent·ppt
Am-Chestnuts1 小时前
DeepSeek表格复制到Word变竖线错列?用DS随心转对比几种整理方法
人工智能·word·ds随心转
55873 生态系统1 小时前
013+【架构实战】55873 智慧生活:如何让生命更有价值、更有意义?—— 四大生命价值维度设计全解
人工智能·55873全域文明生态体系·55873操作系统·全域文明生态系统·55873智慧生活