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

相关推荐
sld16814 小时前
农资行业B2B多租户商城系统推荐,适配农业经销商层级管理
大数据·人工智能
yunhuibin14 小时前
LeNet
人工智能·python
Mixtral16 小时前
2026年春招复盘记录工具测评:告别手动整理,AI自动生成求职总结
人工智能·面试·职场和发展·语音转文字·ai语音转文字
Xd聊架构17 小时前
苹果电脑mac抖音直播伴侣直播
macos·抖音直播·obs·pd虚拟机·mac直播
程序猿_极客17 小时前
【2025 年最新版】Java JDK 安装与环境配置教程(附图文超详细,Windows+macOS 通用)
java·开发语言·windows·macos·jdk
年糕~milo17 小时前
mac 安装虚拟机保姆级教程(vmware fusion)
macos
是店小二呀17 小时前
Mac 用户久等了!节点小宝 4.0 macOS版,正式登陆!
macos
猫头虎17 小时前
macOS 双开/多开微信WeChat完整教程(支持 4.X 及以上版本)
java·vscode·macos·微信·编辑器·mac·脚本
ghostwritten17 小时前
在 macOS 上安装 Claude Code 的完整指南
macos
哥布林学者20 小时前
吴恩达深度学习课程五:自然语言处理 第二周:词嵌入(五)GloVe 算法
深度学习·ai