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

相关推荐
yunhuibin12 分钟前
NIN网络学习
人工智能·python·深度学习·神经网络·学习
王解25 分钟前
第八篇:内外兼修 —— 配置系统与日志监控
人工智能·ai agent·nanobot
zhangshuang-peta28 分钟前
人工智能代理的上下文管理突破与长期任务执行
人工智能·ai agent·mcp·peta
隔壁大炮35 分钟前
03.深度学习——特点
人工智能·深度学习
两万五千个小时1 小时前
构建mini Claude Code:02 - 把 Bash 拆成专用工具(read_file, write_file 等)
人工智能·python
~央千澈~1 小时前
06实战处理AI音乐技术详解第一阶段:频谱破坏·卓伊凡
人工智能
Hcoco_me1 小时前
车载摄像头核心知识点结构化总结
人工智能·深度学习·数码相机·算法·机器学习·自动驾驶
逻辑君2 小时前
根与星辰【第2章】
人工智能·程序人生
施法老农2 小时前
openclaw和opencode组合使用
人工智能
2501_926978332 小时前
提高认知的位置---存在、认知、程序的逻辑位置
人工智能·经验分享