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

相关推荐
YongCheng_Liang4 分钟前
零基础学 AI:AI 工程化部署与项目实战(从优化到落地全指南)
人工智能
励ℳ24 分钟前
【CNN网络入门】基于PyTorch的MNIST手写数字识别:从数据准备到模型部署全流程详解
人工智能·pytorch·深度学习
香芋Yu31 分钟前
【深度学习教程——05_生成模型(Generative)】25_扩散模型为什么能生成高质量图像?Diffusion数学推导
人工智能·深度学习
乐鑫科技 Espressif1 小时前
基于 ESP32-P4 的工业级智能机械臂设计与实现
人工智能·乐鑫科技
yubo05091 小时前
完整的 YOLO26 自定义模块注册 & 训练步骤
人工智能·深度学习
Sylvia33.1 小时前
火星数据:棒球数据API
java·前端·人工智能
nihao5611 小时前
OpenClaw 保姆级安装部署教程
人工智能
X54先生(人文科技)2 小时前
碳硅协同开发篇-ELR诞生记章
人工智能·ai编程·ai写作·程序员创富
小王毕业啦2 小时前
2010-2024年 上市公司-突破性创新和渐进性创新(数据+代码+文献)
大数据·人工智能·数据挖掘·数据分析·数据统计·社科数据·经管数据
美酒没故事°2 小时前
手摸手在扣子平台搭建周报智能体[特殊字符]
人工智能·ai