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

相关推荐
Mr数据杨2 分钟前
商店商品销量预测助力库存优化
人工智能·数据分析·kaggle竞赛
东方佑6 分钟前
202 个参数干掉 59 万个参数:ConvLinear 的设计、融合与实战
人工智能
唯创知音7 分钟前
电动车仪表语音芯片方案 速度、电量、故障三语播报用WT588F02-8S-C
人工智能·语音识别·电动车仪表语音芯片方案
前沿在线8 分钟前
Vbot ATOM发布,人形机器人进入产品化时刻
人工智能·ai·大模型
武子康8 分钟前
Claude 已经给文本加水印了吗?真正缺的不是声明,而是逐模型状态
人工智能·llm·agent
人工智能培训11 分钟前
通用人工智能AGI发展的潜在风险与管控思路
人工智能·agi
liukuang11013 分钟前
商汤2026上半年盈利6.2亿元,生成式AI业务占比近80%
大数据·人工智能
poiu123465714 分钟前
AI FDE技术学习平台对比测评 2026零基础技术学习参考
人工智能·学习
百胜软件@百胜软件14 分钟前
AI是“放大器”也是“风险源”:零售企业如何驾驭这把双刃剑?
大数据·人工智能·零售