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

相关推荐
放下华子我只抽RuiKe517 小时前
机器学习核心算法全景指南
人工智能·python·深度学习·算法·机器学习·机器人·交互
FluxMelodySun17 小时前
机器学习(二十四) 降维 : MDS降维方法与线性降维方法
人工智能·算法·机器学习
GEO研究生17 小时前
2026年游戏主板推荐:AI技术与个性化设计引领市场新风向
人工智能·游戏
CV矿工17 小时前
智驾端到端模型Flow Matching与Diffusion选型及机器人场景差异解析
人工智能·深度学习·机器人
DisonTangor17 小时前
mistralai 开源 Mistral-Small-4-119B-2603
人工智能·开源·aigc
传说故事17 小时前
【论文阅读】OpenClaw-RL: Train Any Agent Simply by Talking
论文阅读·人工智能
w_t_y_y17 小时前
Claude Code(四)command
人工智能
V搜xhliang024617 小时前
工业协作机器人
人工智能·深度学习·计算机视觉·自然语言处理·机器人·知识图谱
北京耐用通信17 小时前
耐达讯自动化实现CC-Link IE转EtherNet/IP网关跨协议协同技术方案
人工智能·科技·物联网·网络协议·自动化·信息与通信
羸弱的穷酸书生17 小时前
跟AI学一手之运维Agent
运维·人工智能·agent