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

相关推荐
T.D.C14 分钟前
【OpenCV】使用opencv找哈士奇的脸
人工智能·opencv·计算机视觉
大霸王龙31 分钟前
软件工程的软件生命周期通常分为以下主要阶段
大数据·人工智能·旅游
yvestine1 小时前
自然语言处理——文本表示
人工智能·python·算法·自然语言处理·文本表示
zzc9211 小时前
MATLAB仿真生成无线通信网络拓扑推理数据集
开发语言·网络·数据库·人工智能·python·深度学习·matlab
点赋科技1 小时前
沙市区举办资本市场赋能培训会 点赋科技分享智能消费新实践
大数据·人工智能
HeteroCat1 小时前
一周年工作总结:做了一年的AI工作我都干了什么?
人工智能
编程有点难1 小时前
Python训练打卡Day43
开发语言·python·深度学习
2301_805054561 小时前
Python训练营打卡Day48(2025.6.8)
pytorch·python·深度学习
YSGZJJ1 小时前
股指期货技术分析与短线操作方法介绍
大数据·人工智能