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

相关推荐
程序员NEO1 分钟前
精控Spring AI日志
人工智能·后端
伪_装3 分钟前
上下文工程指南
人工智能·prompt·agent·n8n
Digitally30 分钟前
如何将iPhone备份到Mac/MacBook
macos·ios·iphone
普通程序员32 分钟前
Gemini CLI 新手安装与使用指南
前端·人工智能·后端
视觉语言导航34 分钟前
ICCV-2025 | 复杂场景的精准可控生成新突破!基于场景图的可控 3D 户外场景生成
人工智能·深度学习·具身智能
whaosoft-14340 分钟前
51c自动驾驶~合集6
人工智能
tonngw1 小时前
Manus AI与多语言手写识别
人工智能
love530love1 小时前
Docker 稳定运行与存储优化全攻略(含可视化指南)
运维·人工智能·windows·docker·容器
HeartException2 小时前
量子计算+AI芯片:光子计算如何重构神经网络硬件生态
人工智能
摸鱼仙人~2 小时前
Minstrel:多智能体协作生成结构化 LangGPT 提示词
人工智能·提示词